A method and device for playing a video stream in reverse based on RTP-PS
By using an RTP-PS-based video stream reversal method, which utilizes keyframe indexing and timestamp settings, video reversal can be achieved without decoding and encoding, thus solving the problem of resource waste in existing technologies and realizing efficient video reversal processing.
Patent Information
- Application Number
- CN202410551976.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-07
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2044-05-07
AI Technical Summary
Existing video reversal technology consumes a lot of encoding and decoding resources, resulting in a waste of server resources.
A video stream reversal method based on RTP-PS is adopted. By reading the keyframe index, forming GOP data, encapsulating PS packets frame by frame and sending RTP packets, and setting the PTS and DTS timestamps in the PES header, video reversal can be achieved without decoding and encoding operations.
It greatly reduces the use of server resources and enables efficient processing of video reversal.
Smart Images

Figure CN118353885B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application discloses a method and device, relates to the technical field of video data management, and in particular relates to a video stream reverse playing method and device based on RTP-PS. BACKGROUND
[0002] With the continuous development of intelligent industry, video monitoring is widely applied to many occasions due to its intuition, accuracy, timeliness and rich information content, and becomes a powerful means of technical security protection. In the field of security monitoring, there is a demand for playing video recording backwards and tracing events afterwards, and most of the current video reverse playing technologies adopt the mode of playing locally after decoding video files in reverse order or sending to a remote end for playing after re-encoding, which needs to consume a large amount of coding and decoding resources. SUMMARY
[0003] The application provides a video stream reverse playing method and device based on RTP-PS, which does not need decoding and encoding operations, only has the overhead of encapsulation, and can greatly reduce the use of server resources.
[0004] The specific scheme provided by the application is as follows:
[0005] The application provides a video stream reverse playing method based on RTP-PS, which comprises the following steps:
[0006] Step 1: reading the key frame index of a video file, positioning to the current key frame according to a reverse playing start time, obtaining the current key frame and a previous key frame offset, reading the video data between the two key frames to form GOP data,
[0007] Step 2: dividing the GOP data into frames to form a frame array,
[0008] Step 3: encapsulating the frame array into PS packets frame by frame, wherein the related attributes in the PES Header are set in the encapsulation process, so that the PTS time stamp and the DTS time stamp exist in the PES Header at the same time,
[0009] Step 4: encapsulating the PS packets into RTP packets and sending to a playing end,
[0010] Step 5: taking the previous key frame offset as the end, continuously reading the GOP data, and repeating the operations of steps 2-4 until the playing ends.
[0011] Further, in the video stream reverse playing method based on RTP-PS, the frame array is formed in step 2, and the frame data in the frame array is in the form of I / P / P...P in sequence.
[0012] Further, the encapsulation process in step 3 of the video stream reverse playing method based on RTP-PS sets the PTS_DTS_flags attribute in the PES Header to 3, so that the PTS time stamp and the DTS time stamp exist in the PES Header at the same time.
[0013] Further, the DTS time stamp in step 3 of the video stream reverse playing method based on RTP-PS represents a decoding time stamp, and provides the decoding order of the video frames; and the PTS time stamp represents a playing time stamp, and provides the playing order of the video frames.
[0014] The application further provides a video stream reverse playing device based on RTP-PS, which comprises a frame data management module, an encapsulation module, a sending module and a playing management module.
[0015] The frame data management module reads the key frame index of a video file, positions to the current key frame according to the reverse playing start time, acquires the current key frame and the previous key frame offset, reads the video data between the two key frames, composes GOP data, frames the GOP data and forms a frame array.
[0016] The encapsulation module encapsulates the frame array into PS packets frame by frame, wherein the related attributes in the PES Header are set in the encapsulation process, so that the PTS time stamp and the DTS time stamp exist in the PES Header at the same time.
[0017] The sending module encapsulates the PS packets into RTP packets and sends them to a playing end.
[0018] The playing management module continues to read the GOP data forward with the previous key frame offset as the end, and performs the operations of encapsulation, packaging and sending in a loop until the playing ends.
[0019] Further, the frame data management module in the video stream reverse playing device based on RTP-PS forms a frame array, and the frame array is in the form of I / P / P...P frame data in sequence.
[0020] Further, the encapsulation module in the video stream reverse playing device based on RTP-PS sets the PTS_DTS_flags attribute in the PES Header to 3 in the encapsulation process, so that the PTS time stamp and the DTS time stamp exist in the PES Header at the same time.
[0021] Further, the encapsulation module in the video stream reverse playing device based on RTP-PS uses the DTS time stamp to represent a decoding time stamp and provide the decoding order of the video frames, and uses the PTS time stamp to represent a playing time stamp and provide the playing order of the video frames.
[0022] The application has the following advantages:
[0023] The application provides a video stream reverse playing method based on RTP-PS, which achieves the reverse playing purpose by setting PES header PTS and DTS data in the process of encapsulating PS packets, does not modify the original video data, does not need decoding and encoding operation, only has the encapsulation cost, and can greatly reduce the use of server resources. BRIEF DESCRIPTION OF DRAWINGS
[0024] Figure 1 is a method flowchart of the application. DETAILED DESCRIPTION
[0025] The application will be further described below in combination with the drawings and specific examples, so that those skilled in the art can better understand the application and implement it, but the examples are not used as the limitation of the application.
[0026] Example 1
[0027] The application provides a video stream reverse playing method based on RTP-PS, which includes the following steps.
[0028] Step 1: reading the key frame index of the video file, positioning to the current key frame according to the reverse playing start time, obtaining the current key frame and the previous key frame offset, reading the video data between the two key frames to form GOP data,
[0029] Step 2: dividing the GOP data into frames to form a frame array,
[0030] Step 3: encapsulating the frame array into PS packets frame by frame, wherein the related properties in the PES header are set in the encapsulation process, so that the PTS timestamp and the DTS timestamp exist in the PES header at the same time,
[0031] Step 4: encapsulating the PS packets into RTP packets and sending to the playing end,
[0032] Step 5: taking the previous key frame offset as the end, continuing to read the GOP data, and repeating the operations of steps 2-4 until the playing ends.
[0033] The method of the application modifies the GOP sending sequence of the video file and the decoding and display sequence of the video frames in a GOP to meet the video reverse playing function requirement, and meets the encapsulation and sending requirement of the RTP-PS mode.
[0034] Example 2
[0035] Based on the embodiment 1, the frame array is formed in step 2 of the method, and the frame data in the frame array is in the form of I / P / P...P in sequence. The video file is read in the form of GOP data packet, the P frame of the video is decoded in the forward direction depending on the I frame, the GOP data is read in reverse order, and the GOP is read in sequence.
[0036] In the encapsulation process of step 3, the PTS_DTS_flags attribute in the PES Header is set to 3, so that the PTS timestamp and the DTS timestamp exist in the PES Header at the same time.
[0037] Wherein, the DTS represents a decoding timestamp, and affects the decoding order of the video frame; the PTS represents a playing timestamp, and affects the playing order of the video frame; the DTS is sequentially increased in a group of GOP frames; and the PTS is sequentially decreased in a group of GOP frames. The DTS and the PTS of the last frame are the same, and the corresponding timestamps of other frames are generated according to the rules.
[0038] The application also provides a video stream reverse playing device based on RTP-PS, which comprises a frame data management module, an encapsulation module, a sending module and a playing management module.
[0039] The frame data management module reads the key frame index of the video file, positions to the current key frame according to the reverse playing start time, obtains the offset of the current key frame and the previous key frame, reads the video data between the two key frames, groups the GOP data, frames the GOP data, and forms a frame array.
[0040] The encapsulation module encapsulates the frame array into PS packets in sequence, wherein the related attributes in the PES Header are set in the encapsulation process, so that the PTS timestamp and the DTS timestamp exist in the PES Header at the same time.
[0041] The sending module encapsulates the PS packets into RTP packets and sends them to the playing end.
[0042] The playing management module continues to read the GOP data in sequence with the offset of the previous key frame as the end, and repeatedly encapsulates, packages and sends the GOP data until the playing ends.
[0043] The information interaction and execution process between the modules in the device are based on the same concept as the method embodiment, and the specific content can be referred to the description in the method embodiment.
[0044] Similarly, the device can achieve the reverse playing purpose by setting the PTS and DTS data in the PES header in the process of encapsulating the PS packet, without modifying the original video data, without invasive modification, without decoding and encoding operation, only with the encapsulation overhead, and can greatly reduce the use of server resources.
[0045] It should be noted that not all steps and modules in the above processes and device structures are necessary, and some steps or modules can be omitted according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in each of the above embodiments can be a physical structure or a logical structure, that is, some modules can be implemented by the same physical entity, or some modules can be implemented by multiple physical entities, or can be implemented by some components in multiple independent devices together.
[0046] The above-described embodiments are merely preferred embodiments of the present application and are not intended to limit the protection scope of the present application. Any equivalent replacement or transformation made by those skilled in the art based on the present application shall fall within the protection scope of the present application. The protection scope of the present application is defined by the claims.
Claims
1. A method for playing a video stream in reverse based on RTP-PS, characterized in that Comprise: Step 1: read the key frame index of the video file, locate to the current key frame according to the reverse play start time, get the current key frame and the previous key frame offset, read the video data between the two key frames, and form GOP data; Step 2: frame the GOP data to form a frame array, and the frame array is in the form of I / P / P...P frame data in turn; Step 3: encapsulate the frame array into PS packet frame by frame, and set the related attributes in PES Header during the encapsulation process, so that PTS timestamp and DTS timestamp exist in PES Header at the same time, wherein DTS represents decoding timestamp, which affects the decoding order of video frames, and DTS will increase sequentially in a group of GOP frames; PTS represents the play timestamp, which affects the play order of video frames, and PTS will decrease sequentially in a group of GOP frames; at the same time, the DTS and PTS of the last frame are the same, and the corresponding timestamps of other frames are generated according to the rules; Step 4: package the PS packet into RTP packet and send it to the playback end; Step 5: continue to read GOP data forward with the previous key frame offset as the end, and loop the operations of steps 2-4 until the playback is finished.
2. The method for playing a video stream in reverse based on RTP-PS according to claim 1, characterized in that In the encapsulation process of step 3, set PTS_DTS_flags attribute in PES Header to 3, so that PTS timestamp and DTS timestamp exist in PES Header at the same time.
3. A video stream reverse playing device based on RTP-PS, characterized in that Comprise frame data management module, encapsulation module, sending module and playback management module, The frame data management module reads the key frame index of the video file, locates to the current key frame according to the reverse play start time, gets the current key frame and the previous key frame offset, reads the video data between the two key frames, and forms GOP data, and frames the GOP data to form a frame array; the frame array is in the form of I / P / P...P frame data in turn; The encapsulation module encapsulates the frame array into PS packet frame by frame, and sets the related attributes in PES Header during the encapsulation process, so that PTS timestamp and DTS timestamp exist in PES Header at the same time, wherein DTS represents decoding timestamp, which affects the decoding order of video frames, and DTS will increase sequentially in a group of GOP frames; PTS represents the play timestamp, which affects the play order of video frames, and PTS will decrease sequentially in a group of GOP frames; at the same time, the DTS and PTS of the last frame are the same, and the corresponding timestamps of other frames are generated according to the rules; The sending module packages the PS packet into RTP packet and sends it to the playback end; The playback management module continues to read GOP data forward with the previous key frame offset as the end, and loops the operations of encapsulation, packaging and sending until the playback is finished.
4. The RTP-PS based video stream rewinding apparatus according to claim 3, wherein In the encapsulation process of the encapsulation module, set PTS_DTS_flags attribute in PES Header to 3, so that PTS timestamp and DTS timestamp exist in PES Header at the same time.
Citation Information
Patent Citations
Server, client and RTSP / RTP-based playing system
CN105828109A
Video playing method and device, and electronic equipment
CN107948735A