Method and system for implementing real-time video based on GStreamer streaming
Through GStreamer shunt technology, video data is written to shared memory and pushed to UDP port, solving the delay problem when multi-programs share camera data, and meeting the requirements of JT808 protocol to obtain real-time video.
Patent Information
- Application Number
- CN202411937746.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-08
AI Technical Summary
In the prior art, when multiple programs require camera data, they can usually only send data through the first program that opens the camera, resulting in data delays and cannot meet the requirements of JT808 protocol to obtain real-time video.
GStreamer is used to divert video data, write it to a shared memory supply program to obtain it, and push it to the UDP port through the RTP protocol for obtaining it for JT808 protocol program.
It realizes that multiple programs can share camera data without interference, solves the problem of video data delay, and meets the requirements of JT808 protocol to obtain real-time video.
Smart Images

Figure CN119788972A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of video data transmission, in particular to a method and system for implementing real-time video based on GStreamer shunting. Background Art
[0002] The JT808 protocol is a national industry standard issued by the Ministry of Transport of China. Its full name is "Communication Protocol for Vehicle Remote Monitoring Terminal Based on Satellite Positioning". It is mainly used to solve data communication problems in vehicle remote monitoring and management. It is widely used in fields such as public transportation, logistics transportation, and taxis. The JT808 protocol needs to support real-time video. However, in the prior art, the device side uses the camera to obtain image information for related algorithm-related function development, which is often exclusive to the camera, that is, after the camera is opened by application A, other applications cannot open and use the camera. The same problem also exists in vehicle-mounted devices. When the camera is opened by the algorithm program, a conflict will occur when the JT808 protocol obtains real-time video. The current solution is: the algorithm program calls opencv through python to obtain camera data for processing. Other applications / algorithm programs need to use the camera data. The camera data is often transmitted to other programs through the algorithm program that first opens the camera. This approach is more troublesome and may cause delays in the video data received by the subsequent programs. Summary of the invention
[0003] The purpose of the present invention is to provide a method and system for realizing real-time video based on GStreamer diversion, which is used to solve the problem in the prior art that multiple programs requiring camera data can only send data through the first program that opens the camera, resulting in data delay, and the requirement of JT808 protocol program to obtain real-time video is not met.
[0004] The present invention solves the above problems through the following technical solutions:
[0005] A method for implementing real-time video based on GStreamer streaming, comprising:
[0006] Get the video data from the camera;
[0007] Use GStreamer to stream the acquired video data: write the video data into shared memory for the application to obtain, and use the RTP protocol to push the video data to the UDP port for the JT808 protocol program to obtain.
[0008] The present invention adopts GStreamer to shunt video data, and other programs that need to obtain camera data can obtain camera data in real time by reading the shared memory without interfering with each other, so that multiple programs on the device side can use video data together; at the same time, the JT808 protocol program only needs to obtain RTP format data from the UDP port, and then add JT808 extended data to transmit to the cloud server, so as to realize real-time display of video, and also support JT808 to obtain video stream, meeting the requirements of real-time video.
[0009] Furthermore, after the JT808 protocol program receives the real-time video instruction from the cloud, it monitors the UDP port of the corresponding camera, obtains the data and packages it to send it to the cloud server.
[0010] Furthermore, the UDP port of the corresponding camera is monitored, data is obtained and packaged and sent to the cloud server. Specifically, the UDP port of the corresponding camera is monitored, data in H264 format is obtained, and then the corresponding protocol data is added according to the multimedia monitoring protocol JT1078, and then sent to the cloud server.
[0011] Furthermore, the writing of the video data into the shared memory specifically includes: writing the video data into the shared memory in a manner of cyclically writing the current video frame.
[0012] Furthermore, the pushing of the video data to the UDP port by using the RTP protocol specifically includes: pushing the video data to the UDP port by using the RTP protocol in a manner of cyclically pushing the current video frame.
[0013] A system for implementing real-time video based on GStreamer streaming, comprising:
[0014] At least one camera;
[0015] The preprocessing module is used to open the camera and obtain video data, and perform video streaming: GStreamer is used to write video data into shared memory for application programs to obtain, and the RTP protocol is used to push the video stream to the specified UDP port;
[0016] The JT808 protocol service module is used to obtain RTP format data from the UDP port after receiving real-time video instructions from the cloud, add the protocol data corresponding to the multimedia monitoring protocol JT1078, and then transmit it to the cloud server for display.
[0017] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0018] (1) The present invention uses GStreamer to shunt video data. Other programs that need to obtain camera data can obtain camera data in real time by reading the shared memory without interfering with each other, thereby supporting multiple programs on the device to use video data together. At the same time, the JT808 protocol program only needs to obtain RTP format data from the UDP port, add JT808 extended data and transmit it to the cloud server, so that real-time display of the video can be achieved, and JT808 is also supported to obtain video streams, meeting the requirements of real-time video.
[0019] (2) The present invention adopts GStreamer and shared memory to achieve multi-program sharing of video data, solve the problem of camera monopoly, realize the multi-program and multi-purpose use of video data, and solve the video delay problem that may occur when using multiple programs.
[0020] (3) The present invention uses GStreamer to divert RTP format data, simplifies the development of JT808 real-time video transmission format, and solves the problem of real-time video delay viewed by the cloud server caused by the camera being monopolized. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 It is a system principle block diagram of the present invention;
[0022] Figure 2 A schematic diagram of video data diversion in the present invention;
[0023] Figure 3 This is a schematic diagram of data interaction between the JT808 protocol program and the cloud server. DETAILED DESCRIPTION
[0024] The present invention is further described in detail below in conjunction with examples, but the embodiments of the present invention are not limited thereto.
[0025] Embodiment 1:
[0026] Combined with Figure 1 As shown, a method for implementing real-time video based on GStreamer streaming includes:
[0027] Get the video data from the camera;
[0028] Use GStreamer to split the acquired video data: write the video data into shared memory for application programs to obtain, and other programs that need to obtain camera data can obtain camera data in real time by reading the shared memory without interfering with each other. At the same time, the video data is pushed to the UDP port using the RTP protocol for the JT808 protocol program to obtain. The data written to the shared memory is in NV12 format, which is a color encoding format widely used in video encoding and decoding, and is a type of YUV 4:2:0 format. The data format written to the shared memory can also be other formats.
[0029] JT808 needs to obtain real-time video. According to the JT808 protocol, the transmission of real-time video stream refers to the RTP protocol. While writing video data into shared memory, the RTP protocol is used to transmit the specified UDP port through the User Datagram Protocol UDP. The JT808 protocol program only needs to obtain the RTP format data from the UDP port, and then add the corresponding protocol data according to JT1078 and transmit it to the cloud server.
[0030] Furthermore, after the JT808 protocol program receives the real-time video instruction from the cloud, it monitors the UDP port of the corresponding camera, obtains the data and packages it to send it to the cloud server, so that the real-time display of the video can be realized.
[0031] The data obtained from the UDP port is in RTP format (Real-time Transport Protocol is a network transmission protocol widely used in real-time transmission of multimedia data streams such as audio and video).
[0032] The whole method can be divided into three steps:
[0033] 1. Video streaming part: such as Figure 2 As shown, after the video data flows out from the camera, it is processed by video diversion to realize the video data being saved in a loop to the shared memory so that different local applications can share and use it, so as to achieve the purpose of multiple applications sharing camera data, and at the same time transmit it to the UDP port to achieve the purpose of JT808 real-time video. Figure 2 The medium video stream can be split into two and one more.
[0034] 2. After the local application captures the shared memory video data, it can perform corresponding processing, such as algorithm detection.
[0035] 3. After receiving the real-time video command from the cloud, the JT808 protocol program can obtain data in H264 format by monitoring the UDP port of the corresponding camera, and then add the corresponding protocol data according to JT1078 and send it to the cloud server. Figure 3 shown.
[0036] Embodiment 2:
[0037] A system for implementing real-time video based on GStreamer streaming, comprising:
[0038] At least one camera;
[0039] The preprocessing module is used to open the camera and obtain video data, and perform video streaming: GStreamer is used to write video data into shared memory for application programs to obtain, and the RTP protocol is used to push the video stream to the specified UDP port;
[0040] The JT808 protocol service module is used to obtain RTP format data from the UDP port after receiving real-time video instructions from the cloud, add the protocol data corresponding to the multimedia monitoring protocol JT1078, and then transmit it to the cloud server for display.
[0041] 1) The preprocessing module uses GStreamer and shared memory to achieve multi-program sharing of video data, solve the problem of camera exclusivity, realize the multi-program and multi-purpose use of video data, and solve the video delay problem that may occur when using multiple programs.
[0042] 2) The pre-processing module uses GStreamer to divert RTP format data, simplifying the development of the JT808 real-time video transmission format, and at the same time solving the problem of real-time video delay seen by the cloud server due to the camera being exclusively occupied.
[0043] Although the present invention is described herein with reference to the illustrative embodiments of the present invention, the above embodiments are only preferred embodiments of the present invention, and the embodiments of the present invention are not limited to the above embodiments. It should be understood that those skilled in the art can design many other modifications and embodiments, which will fall within the scope and spirit of the principles disclosed in this application.
Claims
1. A method for implementing real-time video based on GStreamer streaming, characterized in that: include: Get the video data from the camera; Use GStreamer to stream the acquired video data: write the video data into shared memory for the application to obtain, and use the RTP protocol to push the video data to the UDP port for the JT808 protocol program to obtain.
2. The method for implementing real-time video based on GStreamer shunting according to claim 1, characterized in that: It also includes that after the JT808 protocol program receives the real-time video command from the cloud, it monitors the UDP port of the corresponding camera, obtains the data and packages it to send it to the cloud server.
3. The method for implementing real-time video based on GStreamer shunting according to claim 2, characterized in that: Listen to the UDP port of the corresponding camera, obtain data and package it to send to the cloud server. Specifically: listen to the UDP port of the corresponding camera, obtain data that conforms to the H264 format, and then add the corresponding protocol data according to the multimedia monitoring protocol JT1078, and then send it to the cloud server.
4. The method for implementing real-time video based on GStreamer shunting according to claim 1, characterized in that: The step of writing the video data into the shared memory specifically includes: writing the video data into the shared memory in a manner of cyclically writing the current video frame.
5. The method for implementing real-time video based on GStreamer shunting according to claim 1, characterized in that: The method of pushing the video data to the UDP port by using the RTP protocol specifically includes: pushing the video data to the UDP port by using the RTP protocol by cyclically pushing the current video frame.
6. A system for implementing real-time video based on GStreamer streaming, characterized in that: include: At least one camera; The preprocessing module is used to open the camera and obtain video data, and perform video streaming: GStreamer is used to write video data into shared memory for application programs to obtain, and the RTP protocol is used to push the video stream to the specified UDP port; The JT808 protocol service module is used to obtain RTP format data from the UDP port after receiving real-time video instructions from the cloud, add the protocol data corresponding to the multimedia monitoring protocol JT1078, and then transmit it to the cloud server for display.