Method, device and equipment for synchronous playback of multi-channel recording, and storage medium

By using single-file interleaved storage and frame-level synchronous playback state machine, the problems of multi-channel playback misalignment and power failure reconstruction of multi-cameras were solved, and synchronous rendering and screen-free playback of multiple video encoding channels were achieved.

CN123185306APending Publication Date: 2026-11-27SHENZHEN XINRUISHI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611504095.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-24
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies in multi-view cameras suffer from problems such as misalignment of multiple playback channels, missing reference frames leading to screen distortion or mosaic effects, and difficulty in rebuilding after power failure, making it difficult to achieve unified storage, retrieval, and frame-level synchronous playback of multi-channel recordings.

Method used

By using a single-file interleaved storage, a unified tail index, and a frame-level synchronous playback state machine architecture, the system achieves frame header encapsulation, unified indexing, and frame-level alignment for multi-channel video encoded frames, and uses the "decode only, render not" flag in the frame attribute field for synchronous rendering output.

Benefits of technology

It solves the problems of file bloat, retrieval difficulties, playback misalignment, and power failure reconstruction caused by multiple files, multiple indexes, and multiple timelines in multi-camera systems, and achieves synchronous rendering of multiple video encoding channels and screen-free playback.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123185306A_ABST
    Figure CN123185306A_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a multi-channel video recording synchronous playback method, device, equipment and storage medium. The method comprises: frame header encapsulation on multiple encoding frames in the same device, interleaved writing of the multiple encoding frames into a data area of a same video recording file according to arrival time sequence, writing of reference frame information carrying channel identification into a file tail to generate a unified index area, positioning of target reference frames of each channel based on a playback jump time and index area information, and frame-level alignment using a decode-only-no-render identification in a frame attribute field, so as to realize synchronous rendering output of multiple video encoding channels. The present application solves the problems of multi-view camera playback misalignment and power failure reconstruction difficulty through single file interleaved storage, tail unified indexing and frame-level synchronous playback state machine architecture, and realizes unified search and synchronous non-flashing playback.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of video surveillance and digital video recording and storage technology, specifically to a method, apparatus, device, and storage medium for synchronous playback of multi-channel video recordings. Background Technology

[0002] With the development of artificial intelligence and multi-sensor fusion technology, binocular and multi-view cameras are becoming increasingly popular in scenarios such as security monitoring, perimeter defense, and traffic checkpoints. These cameras simultaneously output N (N≥2) video encoded streams within the same device, requiring recording on local storage media such as TF cards and SD cards, and supporting retrieval and playback by time, channel, and event.

[0003] Existing solutions follow the single-channel recording approach, with each channel having its own independent file, index, and event recording. In binocular / multi-camera scenarios, this leads to playback misalignment issues, where file boundaries are not aligned, resulting in misaligned images, missing reference frames causing screen tearing or pixelation. Furthermore, power-off reconstruction is difficult; after a power outage, it's hard to rebuild the indexes of each channel uniformly. File-by-file reconstruction is required, still making it difficult to guarantee consistency between the timelines and playback. Therefore, achieving unified storage, retrieval, and frame-level synchronized playback of multi-channel recordings on embedded multi-camera systems with lower overhead is a pressing technical problem in this field. Summary of the Invention

[0004] This application provides a method, apparatus, device, and storage medium for synchronous playback of multi-channel video recordings. By employing single-file interleaved storage, a unified end-of-line index, and a frame-level synchronous playback state machine architecture, it solves problems such as file bloat, retrieval difficulties, playback misalignment, and power-off reconstruction difficulties caused by multiple files, indexes, and timelines in multi-camera systems. This achieves unified retrieval and synchronous, screen-free playback. Specifically, to address playback misalignment, a unified end-of-line index enables unified positioning of multiple reference frames, and a frame-level synchronous playback state machine performs frame-level alignment of multiple encoded frames to control the synchronous rendering and output of video images from multiple video encoding channels. This avoids screen distortion or pixelation caused by image misalignment or missing reference frames during multi-channel playback.

[0005] To address the aforementioned technical problems, embodiments of this application provide a method for synchronous playback of multi-channel video recordings, comprising: Frame header encapsulation is performed on the multi-channel encoded frames output from multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field, which are used to characterize the frame's ownership, into the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header. The arrival time sequence of the multi-channel coded frames is determined based on the frame header carried by the multi-channel coded frames, and the multi-channel coded frames are interleaved and written into the data area of ​​the same video file based on the arrival time sequence. A unified file-splitting process is performed on the multiple video encoding channels. During the file-splitting process, reference frame information carrying channel identifiers for each video encoding channel in the current recording file is obtained. The reference frame information is written to the end of the current recording file to generate a unified index area built into the recording file. The unified index area records at least the channel identifier, file offset, and timestamp of the corresponding reference frame. Based on the playback jump time and the reference frame information in the unified index area, the current video file is played back to obtain the target reference frame position corresponding to the multi-channel video encoding channel; Based on the target reference frame position, the multi-channel encoded frames are aligned at the frame level using the "decode only, render not" flag in the frame attribute field, so as to control the synchronous rendering and output of video images by the multi-channel video encoding channels.

[0006] Optionally, the step of performing frame header encapsulation processing on the multi-channel encoded frames output from multiple video encoding channels within the same device, wherein the frame header processing involves writing a channel identifier field and a frame attribute field to the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header, includes: The first reserved field in the frame header is reused as the channel identifier field, and the channel number to which the frame belongs is written into the first reserved field; The second reserved field in the frame header is reused as the frame attribute field, and when the frame is a virtual reference frame, the virtual reference frame flag in the frame attribute field is set; when the frame needs to be decoded without rendering, the decode-only flag in the frame attribute field is set. Write the absolute timestamp into the timestamp field in the frame header to obtain a unified timeline shared by multiple encoded frames.

[0007] Optionally, the step of determining the arrival time sequence of the corresponding multi-coded frames based on the frame headers carried by the multi-coded frames, and interleaving the multi-coded frames into the data area of ​​the same video file based on the arrival time sequence, includes: The encoded frames of the multiple video encoding channels are pushed into the shared circular buffer via callbacks; Based on a single write thread and the order of arrival, encoded frames are sequentially retrieved from the shared circular buffer. The encoded frames extracted sequentially are written serially into the data area of ​​the same video file, forming a frame sequence that is naturally interwoven in chronological order.

[0008] Optionally, the step of performing unified file-splitting processing on the multiple video encoding channels includes: If any one of the multiple video encoding channels meets any preset file-switching trigger condition, a file-switching command is triggered. The file-switching command is sent to the multiple video encoding channels, and the multiple video encoding channels simultaneously close the current recording file and jointly open a new recording file. The preset file-switching trigger conditions include at least one of the following: the timed duration has been reached and the current frame is the reference frame, a natural day has passed, the recording service type has changed, and all event recording tasks of all channels have been completed.

[0009] Optionally, the step of performing unified file-splitting processing on the multiple video encoding channels further includes: Each of the multiple video encoding channels maintains a reference frame holding flag. When a reference frame is written out for a certain channel, the reference frame is cached and the reference frame holding flag for that channel is set. When cutting files, if the reference frame holding flag of a certain channel is valid, the cached reference frame of that channel is written as the first reference frame of the new recording file. If the reference frame holding flag of a certain channel is invalid, then the nearest non-reference frame of that channel is taken, the virtual reference frame flag bit in its frame attribute field is set, and then it is written as a virtual reference frame into the new recording file, so as to serve as the first decodable reference frame of the new recording file.

[0010] Optionally, the step of performing frame-level alignment of the multi-channel coded frame based on the target reference frame position using the "decode only, render only" flag in the frame attribute field includes: In the positioning state, based on the unified index area at the tail, the nearest reference frame no later than the target playback time is found for each of the multiple video encoding channels to obtain the offset within the target file for each channel. In the reference frame push state, the reference frame is read according to the offset in the target file corresponding to each path, and the channel that arrives at the reference frame last is determined as the alignment reference channel. In the virtual reference frame push state, the frame of the non-aligned reference channel is set to only decode and not render the flag, so that it is only sent to the decoder to rebuild the reference frame buffer and not rendered on the screen. In normal push mode, when the reference frame or virtual reference frame of the alignment base channel arrives, the "decode only, render not" flag is cleared, and the multi-channel video encoding channels enter synchronous rendering.

[0011] Optionally, the method further includes: A unified event database is established based on natural days. The unified event database contains an event table, and the event table has an event channel field. The event records of the multiple video encoding channels are all written into the same event table, and the event records of different channels are distinguished by the event channel field; Based on the event channel field and time range, a joint query is performed on the unified event database to locate the video file corresponding to the target event.

[0012] Optionally, the method further includes: After an abnormal power outage, open the recorded file and verify the file header start code; The data area of ​​the video file is scanned frame by frame and the frame start code is verified. If the verification fails, the current frame and subsequent data are truncated. Extract reference frames and virtual reference frames from the scanned frames, construct index entries and write them to the unified index area at the end; Based on the first and last frame times obtained from the scan, the event records of the video file are rewritten into the unified event database for the corresponding natural day.

[0013] This application also provides a synchronous playback device for multi-channel video recording, characterized in that it includes: The encapsulation unit is used to encapsulate the frame headers of the multi-channel encoded frames output from multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field, which are used to characterize the frame's ownership, into the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header. The writing unit is used to determine the arrival time sequence of the corresponding multi-channel coded frames according to the frame header carried by the multi-channel coded frames, and interleave the multi-channel coded frames into the data area of ​​the same video file based on the arrival time sequence. The file-splitting unit is used to perform unified file-splitting processing on the multiple video encoding channels. During the file-splitting process, it obtains reference frame information carrying channel identifiers for each video encoding channel in the current recording file and writes the reference frame information to the end of the current recording file to generate a unified index area built into the recording file. The unified index area records at least the channel identifier, file offset, and timestamp of the corresponding reference frame. The playback unit is used to play back the current video file based on the playback jump time and the reference frame information in the unified index area, and obtain the target reference frame position corresponding to the multi-channel video encoding channel; The frame alignment unit is used to perform frame-level alignment of the multi-channel encoded frames based on the target reference frame position and through the "decode only, render not" flag in the frame attribute field, so as to control the synchronous rendering and output of video images of the multi-channel video encoding channels.

[0014] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed on a computer, causes the computer to perform the synchronous playback method for multi-channel video recording as described above.

[0015] This application also provides a computer device, including a memory and a processor, wherein the processor executes the synchronous playback method of multi-channel video recording as described above by calling a computer program stored in the memory.

[0016] The multi-channel video recording synchronous playback method, apparatus, device, and storage medium provided in this application embodiment encapsulate multiple encoded frames within the same device with frame headers, interleave them into the data area of ​​the same video file according to their arrival time, and write reference frame information carrying channel identifiers to the end of the file to generate a unified index area when uniformly cutting the file. Then, based on the playback jump time and the index area information, the target reference frames of each channel are located, and frame-level alignment is performed using the "decode only, not render" flag in the frame attribute field, thereby achieving synchronous rendering output of multiple video encoded channels. This application solves the problems of file bloat, retrieval difficulties, playback misalignment, and power failure reconstruction difficulties caused by multiple files, multiple indexes, and multiple timelines in multi-camera systems through single-file interleaved storage, unified index at the end, and frame-level synchronous playback state machine architecture, achieving unified retrieval and synchronous playback without screen distortion. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a flowchart illustrating a method for synchronous playback of multi-channel video recordings provided in an embodiment of this application.

[0019] Figure 2 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in an embodiment of this application.

[0020] Figure 3 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in an embodiment of this application.

[0021] Figure 4 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in an embodiment of this application.

[0022] Figure 5 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in an embodiment of this application.

[0023] Figure 6 This is a schematic diagram of the structure of a multi-channel video synchronous playback device provided in an embodiment of this application.

[0024] Figure 7This is a schematic diagram of the computer device structure provided in an embodiment of this application. Detailed Implementation

[0025] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0026] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, components, features, and elements with the same names in different embodiments of this application may have the same meaning or different meanings, the specific meaning of which must be determined by its interpretation in that specific embodiment or further in conjunction with the context of that specific embodiment.

[0027] This application provides a method, apparatus, device, and storage medium for synchronous playback of multi-channel video recordings. Specifically, the synchronous playback method for multi-channel video recordings in this application can be executed by a computer device or a server, wherein the computer device can be a terminal. The terminal can be a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), smart home device, etc. The terminal may also include a client, which can be a media playback client or an instant messaging client, etc.

[0028] Please see Figure 1 The specific process of this multi-channel video synchronous playback method can be as follows: 101. Perform frame header encapsulation processing on the multi-channel encoded frames output from multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field to the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header.

[0029] In this embodiment, multiple video encoding channels are provided within the same device. The number of these multiple video encoding channels can be N, where N is an integer greater than or equal to 2. Each video encoding channel encodes the acquired video image and outputs multiple encoded frames. In one specific implementation, these multiple encoded frames can be H.264 encoded frames or H.265 encoded frames; this embodiment does not limit the specific encoding method used.

[0030] At the recording end, each encoded frame output from each video encoding channel undergoes frame header encapsulation. This encapsulation process involves writing a channel identifier field and a frame attribute field into the frame header corresponding to each encoded frame. The channel identifier field identifies the channel to which the encoded frame belongs, and the frame attribute field identifies the frame type attribute. After frame header encapsulation, a multi-channel encoded frame carrying a frame header is obtained.

[0031] Specifically, the first reserved field uReserved01 in the frame header is reused as the channel identifier field, and the channel number nCh to which the frame belongs is written into the first reserved field uReserved01. The value of the channel number nCh ranges from 0 to MAX_CH_NUM-1. By reusing the first reserved field uReserved01 to carry the channel number nCh, each encoded frame can still be identified as belonging to a specific channel after being written into the same video file. This provides a foundation for the interleaving and storage of multiple encoded frames in the same video file, as well as for retrieval and playback by channel. At the same time, no additional frame header length is required, and no additional storage or transmission overhead is incurred.

[0032] 102. Determine the arrival time of the corresponding multi-channel coded frames based on the frame headers carried by the multi-channel coded frames, and interleave the multi-channel coded frames into the data area of ​​the same video file based on the arrival time.

[0033] In this embodiment, after the encoded frames from multiple video encoding channels are output, each encoder pushes them into a shared circular buffer via callbacks. Since the encoding timings of each channel are different, the multiple encoded frames arrive at the shared circular buffer in the order of their respective encoding times, thus forming an arrival sequence. The arrival sequence of the corresponding multiple encoded frames can be determined based on the frame headers carried by each frame. In one specific implementation, the encoded frames from multiple video encoding channels are pushed into the shared circular buffer `g_p_ring_handle` via callbacks, and each frame includes information such as `nCh` and `u32RealTimeSec`. A single disk write thread retrieves the encoded frames from the shared circular buffer in the order of arrival and serially writes the sequentially retrieved encoded frames into the data area of ​​the same recording file, forming a frame sequence that is naturally interleaved in chronological order.

[0034] In one embodiment, the write thread pops frames from the shared circular buffer in the order of arrival, and sequentially executes `write(fd,&frame_head, sizeof(H264DATAPACKETHEADER))` and `write(fd, payload, frame_head.uOverloadLen)` to write the frame header and payload into the data area of ​​the same video file. Since the encoded frames from multiple video encoding channels arrive in their respective encoding timestamps, after being written to the video file, they form a stream naturally interleaved at 90kHz uShowTime, such as Ch0 I frames, Ch1 I frames, Ch0 P frames, Ch1 P frames, Ch0 P frames, Ch1 P frames, etc. Through this interleaved writing method, multiple encoded frames share the same file container and the same file-level timeline, eliminating the problem of multiple files and multiple timelines from the source.

[0035] 103. Perform unified file cutting processing on multiple video encoding channels, and during the file cutting process, obtain the reference frame information carrying the channel identifier of each video encoding channel in the current recording file, and write the reference frame information to the end of the current recording file to generate a unified index area built into the recording file.

[0036] Specifically, performing unified file cutting processing on multiple video encoding channels means uniformly determining the file cutting for all multiple video encoding channels. When the preset file cutting trigger condition is met, the current recording file is terminated and a new recording file is created, thereby ensuring that all video encoding channels are aligned on the same file boundary.

[0037] Specifically, when any one of the multiple video encoding channels meets any preset file-switching trigger condition, a file-switching command is triggered and sent to all multiple video encoding channels. These channels simultaneously close their current recording files and begin recording new files. This ensures that all video encoding channels finish recording at the same time, preventing misalignment during subsequent playback caused by one channel having already switched files while another is still writing to the old file.

[0038] Furthermore, during the file cutting process, reference frame information carrying channel identifiers for each video encoding channel in the current recording file is obtained, and the reference frame information is written to the end of the current recording file to generate a unified index area built into the recording file.

[0039] In this embodiment, each index entry in the unified index area records at least the channel identifier nCh, the file offset CurrFramePos, and the timestamp CurIFrameTime of the corresponding reference frame. Since the index entry carries the channel identifier nCh, a single array covers multiple video encoding channels. Because the CurrFramePos of all reference frames is an absolute byte offset within the same recording file, multiple video encoding channels share the same address space, eliminating the need to create a separate index file for each channel. Since the CurIFrameTime of all reference frames is an absolute second, multiple video encoding channels share the same timeline, allowing for direct binary search by time. Because the RealIFrame field distinguishes between real and virtual reference frames, but both serve as anchor points for seeking, it ensures that multiple video encoding channels have a seekable reference frame at any given time point.

[0040] 104. Based on the playback jump time and the reference frame information in the unified index area, the current recording file is played back to obtain the target reference frame positions corresponding to multiple video encoding channels.

[0041] Specifically, during playback, the user inputs the playback jump time (seek_time). The unified index area at the end of the recording file is read, and the current recording file is searched and played back based on the playback jump time and the reference frame information in the unified index area to obtain the target reference frame positions corresponding to multiple video encoding channels.

[0042] In this embodiment, reading the unified index area at the end of the video file specifically involves: seeking to the position at the end of the video file minus sizeof(IFrameInfo) multiplied by MAX_AVI_FILE_IFRAME_NUM, and reading the entire arrIFrameInfo array. The arrIFrameInfo array is then filtered to find a subset where nCh equals the target channel. BinarySearchNearMaxV2 is called to find the nearest reference frame no later than the playback jump time seek_time, and its CurrFramePos is taken as the target reference frame position. Repeating the above steps for each of the multiple video encoding channels yields the target reference frame position for each video encoding channel.

[0043] 105. Based on the target reference frame position, perform frame-level alignment of multiple encoded frames using the "decode only, render not" flag in the frame attribute field to control the synchronous rendering and output of video images from multiple video encoding channels.

[0044] In this embodiment, after obtaining the target reference frame positions corresponding to multiple video encoding channels, the multi-encoded frames are aligned at the frame level based on the target reference frame positions using the decode-only-not-rendering flag IDR_NORENDER_BIT_VALUE in the frame attribute field, so as to control the synchronous rendering and output of video images by multiple video encoding channels.

[0045] Specifically, in the normal push state POP_PUSH_NORMAL_STATUS, when the reference frame or virtual reference frame of the alignment base channel arrives, the "decode only, render not" flag is cleared, and multiple video encoding channels enter synchronous rendering. Specifically, normal P-frames and B-frames are continuously sent for decoding; when uReserved01 of a frame equals wait_clear_render_ch and that frame is a reference frame or virtual reference frame, set_frame_ender is cleared to 0, and wait_clear_render_ch is cleared to 0, thus entering the synchronous rendering stage, where all video encoding channels are simultaneously displayed on screen.

[0046] Furthermore, through the above frame-level alignment processing, within the alignment window after seek or file cutting, the earliest arriving frame is only sent to the decoder to rebuild the reference frame buffer without being rendered and displayed on the screen. It waits until all video encoding channels reach the alignment benchmark before being displayed on the screen in a unified manner, thereby ensuring the synchronization of multiple screens and avoiding the misalignment phenomenon where one channel has a screen while another is still loading. It also avoids screen tearing or mosaic caused by missing reference frames.

[0047] As can be seen from the above, the synchronous playback method for multi-channel recording provided in this application encapsulates the frame headers of multiple encoded frames within the same device, interleaves them according to their arrival time, and writes them into the data area of ​​the same recording file. During unified file switching, reference frame information carrying channel identifiers is written to the end of the file to generate a unified index area. Then, based on the playback jump time and the index area information, each target reference frame is located, and frame-level alignment is performed using the "decode only, render not" identifier in the frame attribute field, thereby achieving synchronous rendering output of multiple video encoded channels. This application solves the problems of file bloat, retrieval difficulties, playback misalignment, and power-off reconstruction difficulties caused by multiple files, multiple indexes, and multiple timelines in multi-camera systems through single-file interleaved storage, unified end indexing, and a frame-level synchronous playback state machine architecture, achieving unified retrieval and synchronous, screen-free playback.

[0048] Please see Figure 2 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in this application embodiment. The specific flow of this method can be as follows: 201. The first reserved field in the frame header is reused as the channel identifier field, and the channel number to which the frame belongs is written into the first reserved field.

[0049] In this embodiment, the frame header can be an H264DATAPACKETHEADER. This H264DATAPACKETHEADER may contain, but is not limited to, the following fields: uDataPacketStartCode (frame start code), uFrameNo (frame sequence number), byFrameType (frame type), byLoadType (load type), uShowTime (display timestamp), u32RealTimeSec (absolute time in seconds), u32RealTimeUSec (absolute time in microseconds), uReserved01 (first reserved field), uReserved02 (second reserved field), and uOverloadLen (load length), etc.

[0050] Specifically, by reusing the first reserved field uReserved01 in the frame header as the channel identifier field, each encoded frame can still be identified as belonging to a specific channel after being written into the same video file. This provides a foundation for the interleaving and storage of multiple encoded frames in the same video file, as well as for channel-based retrieval and playback. Furthermore, since the reserved field in the frame header is reused, there is no need to increase the frame header length, thus avoiding increased storage and transmission overhead, which is particularly advantageous on embedded storage media with limited capacity.

[0051] 202. Reuse the second reserved field in the frame header as a frame attribute field, and set the virtual reference frame flag in the frame attribute field when the frame is a virtual reference frame; set the decode-only flag in the frame attribute field when the frame needs to be decoded without rendering.

[0052] In this embodiment, the second reserved field uReserved02 in the frame header is reused as a frame attribute field. This frame attribute field may include a virtual reference frame flag and a decode-only flag. The virtual reference frame flag can be REF_IDR_BIT_VALUE, with a value of 0x01, used to identify the current frame as a virtual reference frame. The decode-only flag can be IDR_NORENDER_BIT_VALUE, with a value of 0x02, used to indicate that the current frame is only sent to the decoder to reconstruct the reference frame buffer without being rendered and displayed on screen.

[0053] Furthermore, when the frame attribute field requires decoding without rendering, the "decode only, render only" flag IDR_NORENDER_BIT_VALUE is set. Decoding only, render only, means that the frame is only sent to the decoder to rebuild the reference frame buffer without rendering it for the screen. For example, in the alignment window after seek or file cutting, the "decode only, render only" flag IDR_NORENDER_BIT_VALUE is set for frames on non-aligned reference channels, so that they are only sent to the decoder to rebuild the reference frame buffer without rendering them for the screen, waiting for all video encoding channels to reach the alignment reference before being uniformly displayed for the screen.

[0054] 203. Write the absolute timestamp into the timestamp field in the frame header to obtain a unified timeline shared by multiple encoded frames.

[0055] In this embodiment, the timestamp field in the frame header may include u32RealTimeSec and u32RealTimeUSec. Writing the absolute timestamp into the timestamp field in the frame header means writing the absolute time in seconds into u32RealTimeSec and the absolute time in microseconds into u32RealTimeUSec. Since the encoded frames of multiple video encoding channels all have the same absolute timestamp written, the multiple encoded frames share the same timeline.

[0056] Specifically, by writing absolute timestamps into the timestamp field of the frame header, multiple encoded frames share a unified timeline. This provides a unified time reference for subsequent interleaving of multiple encoded frames, unified indexing, and frame-level synchronous playback. During retrieval, multiple frames can be retrieved at the same time, eliminating the need to locate them separately in multiple file lists. During playback, each video encoding channel can be searched using a binary search based on time, resulting in a simple retrieval logic and naturally aligned boundaries.

[0057] 204. Push the encoded frames of the multiple video encoding channels into the shared circular buffer via callbacks.

[0058] In this embodiment, after outputting encoded frames, the encoders of the multiple video encoding channels push the encoded frames into the shared circular buffer g_p_ring_handle via a callback. Each frame includes information such as nCh and u32RealTimeSec. The shared circular buffer g_p_ring_handle can be the circular buffer in MemRecord.c.

[0059] Specifically, by pushing the encoded frames from multiple video encoding channels into a shared circular buffer via callbacks, the multiple encoded frames can be managed uniformly according to their arrival order. This provides a basis for the subsequent single-disk write thread to retrieve the encoded frames sequentially according to their arrival order. At the same time, since multiple encoded frames are pushed into the same shared circular buffer, concurrent write contention is avoided, ensuring that the write order is consistent with the arrival order.

[0060] 205. Based on the single write thread and the order of arrival, retrieve the encoded frames sequentially from the shared circular buffer.

[0061] In this embodiment, a single disk write thread retrieves encoded frames sequentially from the shared circular buffer g_p_ring_handle in the order of arrival. The single disk write thread also pops frames from the shared circular buffer in the same order of arrival. Because only one disk write thread is used, multi-way concurrent write contention is avoided.

[0062] 206. The encoded frames extracted in sequence are serially written into the data area of ​​the same video file to form a frame sequence that is naturally interwoven in chronological order.

[0063] In this embodiment, a single write thread serially writes the sequentially retrieved encoded frames into the data area of ​​the same video file. The write thread pops frames from the shared circular buffer in the order of arrival, and executes `write(fd,&frame_head,sizeof(H264DATAPACKETHEADER))` and `write(fd, payload, frame_head.uOverloadLen)` sequentially, thereby writing the frame header and payload into the data area of ​​the same video file. Since the encoded frames from multiple video encoding channels arrive according to their respective encoding timing, after being written into the video file, they form a frame sequence naturally interleaved according to 90kHz uShowTime, such as Ch0 I frame, Ch1I frame, Ch0 P frame, Ch1 P frame, Ch0 P frame, Ch1 P frame, etc.

[0064] Specifically, by sequentially writing the extracted encoded frames into the data area of ​​the same video file, multiple encoded frames share the same file container and the same file-level timeline. This eliminates the problem of multiple files and multiple timelines at the source, significantly reduces the number of files and indexes, decreases directory entries and metadata overhead in the embedded file system, and reduces storage media wear. 207. When any one of the multiple video encoding channels meets any preset file-switching trigger condition, a file-switching command is triggered.

[0065] In this embodiment, a file-splitting command is triggered when any one of the multiple video encoding channels meets any preset file-splitting trigger condition, ensuring a unified file-splitting decision. This guarantees that the multiple video encoding channels are aligned on the same file boundary, preventing misalignment during subsequent playback caused by one channel having already been split while another is still being written to the old recording file. Simultaneously, the duration and size of individual files are limited, facilitating retrieval, transmission, and overwriting loops. Furthermore, the boundaries of event recordings, regular recordings, and cross-day recordings are aligned with file boundaries, and the `file_start` and `file_end` fields in the event library correspond one-to-one with the physical files. 208. Send the file-switching command to multiple video encoding channels. The multiple video encoding channels simultaneously close the current recording file and start the new recording file.

[0066] In this embodiment, the file-switching command is sent to multiple video encoding channels, which simultaneously close the current recording file and start a new recording file. In one specific implementation, when any video encoding channel meets any preset file-switching trigger condition, *need_update_file is set to 1, and the multiple video encoding channels jointly switch files at the next unified time.

[0067] By sending a file-splitting command to multiple video encoding channels, all channels simultaneously close their current recording files and begin recording new files, ensuring that all channels finish recording at the same time. This guarantees alignment of the multiple video encoding channels on the same file boundary, preventing misalignment during subsequent playback caused by one channel having already split its file while another is still writing to the old recording file.

[0068] 209. Based on the playback jump time and the reference frame information in the unified index area, the current recording file is played back to obtain the target reference frame positions corresponding to multiple video encoding channels; 210. Based on the target reference frame position, perform frame-level alignment of multiple encoded frames using the "decode only, render not" flag in the frame attribute field to control the synchronous rendering and output of video images from multiple video encoding channels.

[0069] As can be seen from the above, the synchronous playback method for multi-channel recording provided in this application encapsulates the frame headers of multiple encoded frames within the same device, interleaves them according to their arrival time, and writes them into the data area of ​​the same recording file. When uniformly cutting the file, the reference frame information carrying the channel identifier is written to the end of the file to generate a unified index area. Then, based on the playback jump time and the index area information, the target reference frames of each channel are located, and the frame-level alignment is performed using the "decode only, not render" flag in the frame attribute field, thereby realizing the synchronous rendering output of multiple video encoded channels. This application solves the problems of file expansion, retrieval difficulties, playback misalignment, and power failure reconstruction difficulties caused by multiple files, multiple indexes, and multiple time axes in multi-camera systems through single-file interleaved storage, unified index at the end, and frame-level synchronous playback state machine architecture, thereby achieving unified retrieval and synchronous playback without screen distortion.

[0070] Please see Figure 3 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in this application embodiment. The specific flow of this method can be as follows: 301. Perform frame header encapsulation on the multi-channel encoded frames output from the multi-channel video encoding channels. The frame header processing involves writing a channel identifier field and a frame attribute field to the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header.

[0071] 302. Determine the arrival time of the corresponding multi-channel coded frames based on the frame headers carried by the multi-channel coded frames, and interleave the multi-channel coded frames into the data area of ​​the same video file based on the arrival time.

[0072] 303. Maintain reference frame holding flags for multiple video encoding channels. When a reference frame is written out for a certain channel, buffer the reference frame and set the reference frame holding flag for that channel.

[0073] In this embodiment, an independent reference frame holding flag bNodeHoldFlag[nCh] is maintained for each video encoding channel. The reference frame holding flag bNodeHoldFlag[nCh] is used to indicate whether the corresponding video encoding channel currently holds a reference frame that can be used later. The reference frame can be an I-frame. Specifically, when a video encoding channel writes a reference frame, the reference frame is cached in HoldFrame[nCh], and the reference frame holding flag bNodeHoldFlag[nCh] of that channel is set to 1. Cache the reference frame, which means cache the frame header and payload of the reference frame together. For example, when the bullet camera channel Ch0 writes an I-frame, the I-frame is cached in HoldFrame[0], and the reference frame holding flag bNodeHoldFlag[0] of the bullet camera channel Ch0 is set to 1. As another example, when the PTZ camera channel Ch1 writes an I-frame, the I-frame is cached in HoldFrame[1], and the reference frame holding flag bNodeHoldFlag[1] of the PTZ camera channel Ch1 is set to 1.

[0074] Furthermore, by maintaining reference frame holding flags for each of the multiple video encoding channels, and caching reference frames and setting the reference frame holding flag for a particular channel after writing a reference frame, each video encoding channel can independently hold the most recent reference frame. This provides a foundation for supplementing reference frames channel by channel during subsequent file splitting. When splitting files, if the reference frame holding flag for a certain channel is valid, the cached reference frame for that channel can be directly written as the first reference frame of the new recording file, thus ensuring that the first reference frame of the new recording file is a true reference frame and avoiding screen distortion during subsequent playback due to missing reference frames. 304. When cutting files, if the reference frame holding mark of a certain channel is valid, then the cached reference frame of that channel is written as the first reference frame of the new recording file.

[0075] In this embodiment, specifically, when cutting files, multiple video encoding channels are traversed. For a particular video encoding channel that has been traversed, it is determined whether the reference frame holding flag bNodeHoldFlag[nCh] of that channel is valid. A valid reference frame holding flag means that the reference frame holding flag bNodeHoldFlag[nCh] is equal to 1. If the reference frame holding flag of a certain channel is valid, that is, bNodeHoldFlag[nCh] is equal to 1, then the cached reference frame HoldFrame[nCh] of that channel is written as the first reference frame of the new recording file.

[0076] Specifically, the reference frame HoldFrame[nCh] in the cache is written to the new recording file as is, serving as the first reference frame. Writing it as is means writing the frame header and payload of the reference frame to the new recording file together. Since this reference frame is a real reference frame, the virtual reference frame flag REF_IDR_BIT_VALUE in the frame attribute field of this reference frame is not set.

[0077] 305. If the reference frame holding mark of a certain channel is invalid, then take the nearest non-reference frame of that channel, set the virtual reference frame flag in its frame attribute field, and write it as a virtual reference frame into the new recording file, so as to serve as the first decodable reference frame of the new recording file.

[0078] In this embodiment, specifically, when cutting files, multiple video encoding channels are traversed. For a particular video encoding channel that has been traversed, it is determined whether the reference frame holding flag bNodeHoldFlag[nCh] of that channel is valid. An invalid reference frame holding flag means that the reference frame holding flag bNodeHoldFlag[nCh] is equal to 0. If the reference frame holding flag of a certain channel is invalid, that is, bNodeHoldFlag[nCh] is equal to 0, then the nearest non-reference frame of that channel is taken, the virtual reference frame flag bit REF_IDR_BIT_VALUE in its frame attribute field is set, and it is written as a virtual reference frame into the new recording file, so as the first decodable reference frame of the new recording file.

[0079] Specifically, the most recent non-reference frame on this path can be the most recent P-frame on this path. Setting the virtual reference frame flag REF_IDR_BIT_VALUE in its frame attribute field means performing a bitwise OR operation between the second reserved field uReserved02 in the frame header of this frame and REF_IDR_BIT_VALUE, thus setting the virtual reference frame flag REF_IDR_BIT_VALUE. Non-reference frames after setting the virtual reference frame flag are used as virtual reference frames. Virtual reference frames are used by the decoder to reconstruct the reference frame buffer.

[0080] Furthermore, when a reference frame on a certain path is marked as invalid, the nearest non-reference frame on that path is taken, and its virtual reference frame flag is set in its frame attribute field. This virtual reference frame is then written into the new recording file, ensuring that even in the abnormal situation where a reference frame is marked as invalid, the new recording file still has a first decorable reference frame. This guarantees that a decorable reference frame or virtual reference frame exists before any seek start point. The decoder rebuilds the reference frame buffer from this point, ensuring that subsequent P-frames can be correctly decoded, thus avoiding screen distortion due to missing reference frames during multi-channel playback. Simultaneously, since the virtual reference frame is obtained by filling in the gaps with the nearest non-reference frame, there is no need to wait for the next real reference frame to arrive. Therefore, file switching can be completed promptly without delay due to waiting for a real reference frame.

[0081] 306. Based on the playback jump time and the reference frame information in the unified index area, the current recording file is played back to obtain the target reference frame positions corresponding to multiple video encoding channels.

[0082] 307. In the positioning state, based on the unified index area at the tail, find the nearest reference frame no later than the target playback time for each of the multiple video encoding channels, and obtain the corresponding offset in the target file for each channel.

[0083] In this embodiment, the frame-level synchronous playback state machine checks for seek requests in the POP_CHECK_STATUS state; if a seek request is found, it transitions to the positioning state POP_SEEK_STATUS. In the positioning state POP_SEEK_STATUS, based on the unified index area at the end, it searches for the nearest reference frame no later than the target playback time for each of the multiple video encoding channels, obtaining the corresponding offset within the target file for each channel.

[0084] Specifically, the target playback time seek_time can be a time point selected by the user through the playback interface, or a time point determined based on the event retrieval results; this embodiment of the application does not limit this. The target playback time seek_time can also be referred to as the playback jump time.

[0085] Furthermore, by searching for the nearest reference frame no later than the target playback time for each of the multiple video encoding channels based on the unified index area at the end, the offset within the target file for each channel is obtained, enabling multiple video encoding channels to be located within the same index area. Therefore, multiple video encoding channels can be served simultaneously by reading the unified index area only once, eliminating the need to traverse each channel's own index file, simplifying the retrieval logic and ensuring natural boundary alignment. Simultaneously, since each index entry in the unified index area records a channel identifier nCh, a subset of reference frames for the target channel can be quickly obtained by filtering nCh, resulting in high search efficiency.

[0086] 308. In the reference frame push state, start reading the reference frame according to the offset in the target file corresponding to each channel, and determine the channel that arrives at the reference frame last as the alignment reference channel.

[0087] In this embodiment, after obtaining the target file offset for each channel in the positioning state POP_SEEK_STATUS, the system transitions to the reference frame push state POP_PUSH_I_STATUS. In the reference frame push state POP_PUSH_I_STATUS, reference frames are read based on the target file offset for each channel, and the channel that arrives last to the reference frame is designated as the alignment reference channel wait_clear_render_ch.

[0088] Specifically, the channel that arrives at the reference frame latest refers to the video coding channel whose reference frame arrives latest among the multiple video coding channels. For example, if the reference frame of the bullet camera channel Ch0 arrives first, and the reference frame of the PTZ camera channel Ch1 arrives later, then the PTZ camera channel Ch1 is designated as the alignment reference channel wait_clear_render_ch. As another example, if the reference frame of the front camera channel arrives first, and the reference frame of the rear camera channel arrives later, then the rear camera channel is designated as the alignment reference channel wait_clear_render_ch.

[0089] By reading reference frames based on the offsets within the corresponding target files for each channel, and determining the channel that arrives latest as the alignment reference channel, frame-level alignment of multiple video encoding channels has a clear benchmark. Therefore, subsequent frames arriving earlier from other channels are decoded but not rendered, with the alignment reference channel serving as the standard. The markers are then cleared once the alignment reference channel arrives, ensuring synchronized display of multiple video streams and preventing misalignment where one stream displays an image while another is still loading.

[0090] 309. In the virtual reference frame push state, the frame of the non-aligned reference channel is set to decode only and not render, so that it is only sent to the decoder to rebuild the reference frame buffer and not rendered on the screen.

[0091] In this embodiment, after determining the channel that arrives latest at the reference frame as the alignment reference channel (wait_clear_render_ch) in the reference frame push state (POP_PUSH_I_STATUS), the system transitions to the virtual reference frame push state (POP_PUSH_VI_STATUS). In the virtual reference frame push state (POP_PUSH_VI_STATUS), frames from non-aligned reference channels are set to the "decode only, render not" flag (IDR_NORENDER_BIT_VALUE), causing them to be sent only to the decoder to reconstruct the reference frame buffer without being rendered for display.

[0092] Specifically, virtual reference frames are sent to the decoder to reconstruct the reference frame buffer using a decode-only, non-rendering method. A virtual reference frame is a frame whose byFrameType is equal to P_FRAME and whose AND operation between uReserved02 and REF_IDR_BIT_VALUE is not zero. All frames in the non-aligned reference channel are continuously set to IDR_NORENDER_BIT_VALUE in uReserved02.

[0093] 310. In normal push mode, when the reference frame or virtual reference frame of the alignment base channel arrives, the "decode only, render not" flag is cleared, and multiple video encoding channels enter synchronous rendering.

[0094] In this embodiment, after setting the "decode only, don't render" flag IDR_NORENDER_BIT_VALUE for frames in the virtual reference frame push state POP_PUSH_VI_STATUS, the system transitions to the normal push state POP_PUSH_NORMAL_STATUS. In the normal push state POP_PUSH_NORMAL_STATUS, when a reference frame or virtual reference frame for the aligned reference channel arrives, the "decode only, don't render" flag IDR_NORENDER_BIT_VALUE is cleared, and multiple video encoding channels enter synchronous rendering.

[0095] Specifically, the arrival of a reference frame or virtual reference frame aligned with the reference channel means that the frame read satisfies the condition that frame_head.uReserved01 equals wait_clear_render_ch and that the frame is a real reference frame with byFrameType equal to I_FRAME, or that the frame is a virtual reference frame with byFrameType equal to P_FRAME and the result of the AND operation between uReserved02 and REF_IDR_BIT_VALUE is not zero.

[0096] By clearing the "decode only, render not" flag when the reference frame or virtual reference frame for the alignment baseline channel arrives during normal push operation, multiple video encoding channels enter synchronous rendering, thus ending the alignment window. As a result, the reference frame buffers for all video encoding channels are ready, and subsequent frames can be synchronously displayed, achieving multi-channel frame-level synchronous playback without screen tearing. Clearing the "decode only, render not" flag is the signal for the end of the alignment window, ensuring that multiple video streams begin synchronous rendering at the same time.

[0097] Please see Figure 4 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in this application embodiment. The specific flow of this method can be as follows: 011. Establish a unified event database based on calendar days.

[0098] In this embodiment, a unified event database is established based on calendar days. The unified event database is a database built according to calendar days, and its name can be V2_YYYYMMDD.db, where YYYYMMDD represents the year, month, and day of the calendar day. For example, the unified event database name corresponding to September 21, 2026 could be V2_20260921.db. All events from multiple video encoding channels on the same day share this unified event database.

[0099] By establishing a unified event database based on calendar days, the capacity of a single database is limited to the number of events in a single day, preventing the database from growing indefinitely and slowing down queries. Therefore, cross-day searches can be performed by enumerating the daily database, balancing uniformity and partitioning. Furthermore, splitting database names by calendar day allows event records to be categorized by date, facilitating cross-day cleanup and deletion of expired records.

[0100] 012. Write the event records of multiple video encoding channels into the same event table, and distinguish the event records of different channels by the event channel field.

[0101] In this embodiment, event records for multiple video encoding channels are all written to the same event table `event_tab`, and the event records for different channels are distinguished by the `event_ch` field. The event records for multiple video encoding channels share the same event table `event_tab`, and are distinguished only by the `event_ch` field.

[0102] Specifically, the event_ch field serves several purposes: channel identifier, distinguishing which video encoding channel a particular event record belongs to in the unified event table, forming the basis for multiple video encoding channels sharing a single table; query filter key, used as an SQL WHERE condition during joint retrieval, supporting precise filtering by specifying a channel and time range; and foundation for multi-channel unions, enabling cross-channel GROUP BY and JOIN operations at the SQL layer without merging multiple indexes at the application layer.

[0103] 013. Based on the event channel field and time range, perform a joint query on the unified event database to locate the video file corresponding to the target event.

[0104] In this embodiment, the reasons for the improved efficiency of joint queries include: avoiding multi-channel, multi-file hash scanning. If each of the N channels of video recordings has its own index, playback or retrieval would require traversing and merging all the index files of the N channels separately, which degenerates into a single SQL query under a unified database; using SQLite's B-Tree index with an automatic primary key, building the tree with the event_id auto-incrementing primary key, and parameterizing the event_ch and event_start, reducing the complexity from O(N multiplied by the number of files) to O(logn plus the number of rows hit); controlling the scale of databases by daily switching, with the maximum capacity of a single database being the amount of events in one day, avoiding the infinite expansion of a single database that would slow down queries, and enumerating the daily databases for cross-day retrievals.

[0105] Furthermore, by performing joint queries on the unified event database based on event channel fields and time ranges, event records from multiple video encoding channels can be queried across channels at the SQL layer. This supports joint searches by channel and by time range, improving search efficiency, simplifying search logic, and facilitating the location of the recording file corresponding to the target event.

[0106] Please see Figure 5 This is another flowchart illustrating the synchronous playback method for multi-channel video recording provided in this application embodiment. The specific flow of this method can be as follows: 021. After an abnormal power outage, open the video file and verify the file header start code.

[0107] In this embodiment, after an abnormal power outage and upon power restoration, the video file being written is opened and the file header start code is verified. In one specific implementation, the abnormal video file is opened, and the MPEG4 FILEHEADER is read to verify the start code 0xB6010000.

[0108] Specifically, the header of a video file includes a header start code. If the header start code verification passes, it means the header of the video file is complete, and subsequent frame-by-frame scanning can continue. If the header start code verification fails, it means the header of the video file is corrupted and cannot be repaired; the video file can be discarded.

[0109] 022. Scan the data area of ​​the video file frame by frame and verify the frame start code. If the verification fails, truncate the current frame and subsequent data.

[0110] In this embodiment, the data area of ​​the video file is scanned frame by frame and the frame start code is verified. In one specific implementation, the data area is scanned frame by frame as follows: lseek to the current frame header position, read H264DATAPACKETHEADER; verify that the frame start code uDataPacketStartCode is equal to FRAME_START_CODE, if the verification fails, ftruncate(fd, nSeekCur) truncates the current frame and subsequent data; skip the frame load using FrameHead.uOverloadLen and continue scanning the next frame.

[0111] Specifically, during frame-by-frame scanning, the first frame time uFirstFrameTime is recorded as equal to FrameHead.u32RealTimeSec, and the last frame time uLastFrameTime is recorded. By recording the first and last frame times, time information is provided for subsequent rewriting of event records to the unified event library.

[0112] 023. Extract reference frames and virtual reference frames from the scanned frames, construct index entries, and write them to the unified index area at the end.

[0113] In this embodiment, the index item IFrameInfo includes, but is not limited to: nCh (channel number), RealIFrame (real or virtual reference frame flag), CurrFramePos (file offset), CurIFrameTime (reference frame time), ShowTime (display time), and IFrameNum (frame number). Among them, the RealIFrame field is used to distinguish between real and virtual reference frames.

[0114] Specifically, after truncating the fragmented frames, a quality check is performed: if nIFrameNum is less than REPAIRED_VIDEO_MIN_IFRAME_NUM, the repair fails and the file is discarded. This quality check prevents the repaired video file from failing to play back properly due to an insufficient number of index entries.

[0115] Specifically, the unified write-back of the tail index involves executing `write(fd,&arrIFrameInfo, sizeof(IFrameInfo) multiplied by MAX_AVI_FILE_IFRAME_NUM)` to write all reference frames and virtual reference frames from multiple video encoding channels to the end of the file. By uniformly writing back the tail index with channel identifiers, the tail index with channel identifiers can be reconstructed uniformly after an abnormal power outage.

[0116] 024. Based on the first frame time and the last frame time obtained from the scan, rewrite the event records of the video file into the unified event library for the corresponding natural day.

[0117] In this embodiment, the event records of the video file are rewritten to the unified event database for the corresponding natural day based on the first frame time uFirstFrameTime and the last frame time uLastFrameTime obtained from the scan. In one specific implementation, strBeginTime and strStopTime are generated using uFirstFrameTime and uLastFrameTime, and the event records of this file are re-INSERTed into the event_tab of V2_YYYYMMDD.db for the corresponding natural day. The event records contain event_ch.

[0118] Specifically, since multiple video encoding channels share the same recording file, the same end unified index area, and the same timeline, and u32RealTimeSec is in absolute seconds, the seek after reconstruction is still aligned with the latest channel reference frame, ensuring natural synchronization of multiple playbacks. By rewriting the event records of the recording file into the unified event library for the corresponding natural day, the event records in the unified event library after an abnormal power outage are kept consistent with the repaired recording file.

[0119] In summary, the multi-channel video recording storage and synchronous playback method provided in this application involves: opening the video file and verifying the file header start code after an abnormal power outage; scanning the data area of ​​the video file frame by frame and verifying the frame start code; truncating the current frame and subsequent data if verification fails; extracting reference frames and virtual reference frames from the scanned frames, constructing index entries, and writing them to the unified index area at the end; and rewriting the event records of the video file to the unified event database for the corresponding natural day based on the first and last frame times obtained from the scan. Therefore, after an abnormal power outage, the tail index with channel identifiers can be uniformly reconstructed, ensuring consistency between multiple timelines and playback, and improving the reliability of video recording storage and playback.

[0120] For example, such as Figure 6 The diagram shown is a structural schematic of a multi-channel video recording synchronous playback device provided in an embodiment of this application. This multi-channel video recording synchronous playback device may include: The encapsulation unit 601 is used to encapsulate the frame headers of the multi-channel encoded frames output from the multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field, which are used to characterize the frame's ownership, into the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header. The writing unit 602 is used to determine the arrival time sequence of the corresponding multi-channel coded frames according to the frame header carried by the multi-channel coded frames, and interleave the multi-channel coded frames into the data area of ​​the same video file based on the arrival time sequence. The file cutting unit 603 is used to perform unified file cutting processing on the multiple video encoding channels, and during the file cutting process, it obtains reference frame information carrying channel identifiers for each video encoding channel in the current recording file, and writes the reference frame information to the end of the current recording file to generate a unified index area built into the recording file. The unified index area records at least the channel identifier, file offset and timestamp of the corresponding reference frame. The playback unit 604 is used to play back the current video file based on the playback jump time and the reference frame information in the unified index area, and obtain the target reference frame position corresponding to the multi-channel video encoding channel. The frame alignment unit 605 is used to perform frame-level alignment of the multi-channel encoded frames based on the target reference frame position and through the decode-only-not-render flag in the frame attribute field, so as to control the synchronous rendering and output of video images of the multi-channel video encoding channels.

[0121] The synchronous playback device for multi-channel video recording proposed in this application encapsulates frame headers for multiple encoded frames within the same device, interleaves them according to their arrival time, and writes them into the data area of ​​the same recording file. During unified file switching, reference frame information carrying channel identifiers is written to the end of the file to generate a unified index area. Then, based on the playback jump time and the index area information, the target reference frames for each channel are located, and frame-level alignment is performed using the "decode only, no rendering" flag in the frame attribute field, thereby achieving synchronous rendering output of multiple video encoded channels. The solution provided in this application, through single-file interleaved storage, unified indexing at the end, and a frame-level synchronous playback state machine architecture, solves the problems of file bloat, retrieval difficulties, playback misalignment, and power-off reconstruction difficulties caused by multiple files, multiple indexes, and multiple timelines in multi-camera systems, achieving unified retrieval and synchronous, screen-free playback.

[0122] All of the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here.

[0123] This application also provides a computer device, including a memory and a processor, wherein the processor executes the process in the multi-channel video synchronous playback method provided in this embodiment by calling a computer program stored in the memory.

[0124] For example, the aforementioned computer equipment can be terminal devices with corresponding functions, such as mobile phones, tablets, personal computers, and cloud computers. Please refer to [link / reference]. Figure 7 , Figure 7 A schematic diagram of the structure of a computer device provided in an embodiment of this application.

[0125] The computer device 700 may include components such as a memory 701 and a processor 702. Those skilled in the art will understand that... Figure 7The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0126] Memory 701 can be used to store application programs and data. The application programs stored in memory 701 contain executable code. Application programs can be composed of various functional modules. Processor 702 executes various functional applications and data processing by running the application programs stored in memory 701.

[0127] The processor 702 is the control center of the computer device. It connects various parts of the computer device through various interfaces and lines. By running or executing applications stored in memory 701 and calling data stored in memory 701, it performs various functions of the computer device and processes data, thereby monitoring the computer device as a whole.

[0128] In this embodiment, the processor 702 in the computer device loads the executable code corresponding to the processes of one or more applications into the memory 701 according to the following instructions, and the processor 702 runs the applications stored in the memory 701 to execute: Frame header encapsulation is performed on the multi-channel encoded frames output from multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field, which are used to characterize the frame's ownership, into the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header. The arrival time sequence of the multi-channel coded frames is determined based on the frame header carried by the multi-channel coded frames, and the multi-channel coded frames are interleaved and written into the data area of ​​the same video file based on the arrival time sequence. A unified file-splitting process is performed on the multiple video encoding channels. During the file-splitting process, reference frame information carrying channel identifiers for each video encoding channel in the current recording file is obtained. The reference frame information is written to the end of the current recording file to generate a unified index area built into the recording file. The unified index area records at least the channel identifier, file offset, and timestamp of the corresponding reference frame. Based on the playback jump time and the reference frame information in the unified index area, the current video file is played back to obtain the target reference frame position corresponding to the multi-channel video encoding channel; Based on the target reference frame position, the multi-channel encoded frames are aligned at the frame level using the "decode only, render not" flag in the frame attribute field, so as to control the synchronous rendering and output of video images by the multi-channel video encoding channels.

[0129] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0130] Therefore, embodiments of this application provide a storage medium storing a plurality of instructions that can be loaded by a processor to execute steps in any of the data calculation methods provided in embodiments of this application. For example, the instructions can execute the following steps: Frame header encapsulation is performed on the multi-channel encoded frames output from multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field, which are used to characterize the frame's ownership, into the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header. The arrival time sequence of the multi-channel coded frames is determined based on the frame header carried by the multi-channel coded frames, and the multi-channel coded frames are interleaved and written into the data area of ​​the same video file based on the arrival time sequence. A unified file-splitting process is performed on the multiple video encoding channels. During the file-splitting process, reference frame information carrying channel identifiers for each video encoding channel in the current recording file is obtained. The reference frame information is written to the end of the current recording file to generate a unified index area built into the recording file. The unified index area records at least the channel identifier, file offset, and timestamp of the corresponding reference frame. Based on the playback jump time and the reference frame information in the unified index area, the current video file is played back to obtain the target reference frame position corresponding to the multi-channel video encoding channel; Based on the target reference frame position, the multi-channel encoded frames are aligned at the frame level using the "decode only, render not" flag in the frame attribute field, so as to control the synchronous rendering and output of video images by the multi-channel video encoding channels.

[0131] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0132] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0133] Since the instructions stored in the storage medium can execute the steps of any of the data calculation methods provided in the embodiments of this application, the beneficial effects that any of the data calculation methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.

[0134] The embodiments of the computer device and readable storage medium provided in this application include all the technical features of the embodiments of the above methods. The extended and explanatory content of the specification is the same as that of the embodiments of the above positioning method, and will not be repeated here.

[0135] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed description of the synchronous playback device for multi-channel video recording above, which will not be repeated here.

[0136] The synchronous playback method for multi-channel video recording provided in this application embodiment belongs to the same concept as the synchronous playback device for multi-channel video recording in the above embodiment. For details of its specific implementation process, please refer to the embodiment of the synchronous playback device for multi-channel video recording, which will not be repeated here.

[0137] It should be noted that, regarding the synchronous playback method for multi-channel video recording described in the embodiments of this application, those skilled in the art will understand that all or part of the process of implementing the synchronous playback method for multi-channel video recording described in the embodiments of this application can be accomplished by a computer program controlling related hardware. The computer program can be stored in a computer-readable storage medium, such as a memory, and executed by at least one processor. During execution, it can include the process of the embodiments of the synchronous playback method for multi-channel video recording. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory (RAM), etc.

[0138] The foregoing has provided a detailed description of a method, apparatus, device, and storage medium for synchronous playback of multi-channel video recordings provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

[0139] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, such as the combination of technical features between embodiments, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for synchronous playback of multi-channel video recordings, characterized in that, include: Frame header encapsulation is performed on the multi-channel encoded frames output from multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field, which are used to characterize the frame's affiliation, into the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header. The arrival time sequence of the multi-channel coded frames is determined based on the frame header carried by the multi-channel coded frames, and the multi-channel coded frames are interleaved and written into the data area of ​​the same video file based on the arrival time sequence. A unified file-splitting process is performed on the multiple video encoding channels. During the file-splitting process, reference frame information carrying channel identifiers for each video encoding channel in the current recording file is obtained. The reference frame information is written to the end of the current recording file to generate a unified index area built into the recording file. The unified index area records at least the channel identifier, file offset, and timestamp of the corresponding reference frame. Based on the playback jump time and the reference frame information in the unified index area, the current video file is played back to obtain the target reference frame position corresponding to the multi-channel video encoding channel; Based on the target reference frame position, the multi-channel encoded frames are aligned at the frame level using the "decode only, render not" flag in the frame attribute field, so as to control the synchronous rendering and output of video images by the multi-channel video encoding channels.

2. The synchronous playback method for multi-channel video recording as described in claim 1, characterized in that, The step of performing frame header encapsulation processing on multiple encoded frames output from multiple video encoding channels within the same device, wherein the frame header processing involves writing a channel identifier field and a frame attribute field to the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header, includes: The first reserved field in the frame header is reused as the channel identifier field, and the channel number to which the frame belongs is written into the first reserved field; The second reserved field in the frame header is reused as the frame attribute field, and when the frame is a virtual reference frame, the virtual reference frame flag in the frame attribute field is set; when the frame needs to be decoded without rendering, the decode-only flag in the frame attribute field is set. Write the absolute timestamp into the timestamp field in the frame header to obtain a unified timeline shared by multiple encoded frames.

3. The synchronous playback method for multi-channel video recording as described in claim 1, characterized in that, The step of determining the arrival time sequence of the corresponding multi-channel coded frames based on the frame headers carried by the multi-channel coded frames, and interleaving the multi-channel coded frames into the data area of ​​the same video file based on the arrival time sequence, includes: The encoded frames of the multiple video encoding channels are pushed into the shared circular buffer via callbacks; Based on a single write thread and the order of arrival, encoded frames are sequentially retrieved from the shared circular buffer. The encoded frames extracted sequentially are written serially into the data area of ​​the same video file, forming a frame sequence that is naturally interwoven in chronological order.

4. The synchronous playback method for multi-channel video recording as described in claim 1, characterized in that, The step of performing unified file splitting processing on the multiple video encoding channels includes: If any one of the multiple video encoding channels meets any preset file-switching trigger condition, a file-switching command is triggered. The file-switching command is sent to the multiple video encoding channels, and the multiple video encoding channels simultaneously close the current recording file and jointly open a new recording file. The preset file-switching trigger conditions include at least one of the following: the timed duration has been reached and the current frame is the reference frame, a natural day has passed, the recording service type has changed, and all event recording tasks of all channels have been completed.

5. The synchronous playback method for multi-channel video recording as described in claim 1, characterized in that, The step of performing unified file-splitting processing on the multiple video encoding channels further includes: Each of the multiple video encoding channels maintains a reference frame holding flag. When a reference frame is written out for a certain channel, the reference frame is cached and the reference frame holding flag for that channel is set. When cutting files, if the reference frame holding flag of a certain channel is valid, the cached reference frame of that channel is written as the first reference frame of the new recording file. If the reference frame holding flag of a certain channel is invalid, then the nearest non-reference frame of that channel is taken, the virtual reference frame flag bit in its frame attribute field is set, and then it is written as a virtual reference frame into the new recording file, so as to serve as the first decodable reference frame of the new recording file.

6. The synchronous playback method for multi-channel video recording as described in claim 1, characterized in that, The step of performing frame-level alignment of the multi-channel coded frame based on the target reference frame position using the "decode only, render only" flag in the frame attribute field includes: In the positioning state, based on the unified index area at the tail, the nearest reference frame no later than the target playback time is found for each of the multiple video encoding channels to obtain the offset within the target file for each channel. In the reference frame push state, the reference frame is read according to the offset in the target file corresponding to each path, and the channel that arrives at the reference frame last is determined as the alignment reference channel. In the virtual reference frame push state, the frame of the non-aligned reference channel is set to only decode and not render the flag, so that it is only sent to the decoder to rebuild the reference frame buffer and not rendered on the screen. In normal push mode, when the reference frame or virtual reference frame of the alignment base channel arrives, the "decode only, render not" flag is cleared, and the multi-channel video encoding channels enter synchronous rendering.

7. The synchronous playback method for multi-channel video recording as described in claim 6, characterized in that, The method further includes: A unified event database is established based on natural days. The unified event database contains an event table, and the event table has an event channel field. The event records of the multiple video encoding channels are all written into the same event table, and the event records of different channels are distinguished by the event channel field; Based on the event channel field and time range, a joint query is performed on the unified event database to locate the video file corresponding to the target event.

8. The synchronous playback method for multi-channel video recording as described in claim 7, characterized in that, The method further includes: After an abnormal power outage, open the recorded file and verify the file header start code; The data area of ​​the video file is scanned frame by frame and the frame start code is verified. If the verification fails, the current frame and subsequent data are truncated. Extract reference frames and virtual reference frames from the scanned frames, construct index entries and write them to the unified index area at the end; Based on the first and last frame times obtained from the scan, the event records of the video file are rewritten into the unified event database for the corresponding natural day.

9. A synchronous playback device for multi-channel video recording, characterized in that, include: The encapsulation unit is used to encapsulate the frame headers of the multi-channel encoded frames output from the multiple video encoding channels within the same device. The frame header processing involves writing a channel identifier field and a frame attribute field, which are used to characterize the frame's ownership, into the corresponding frame header of each encoded frame to obtain a multi-channel encoded frame carrying a frame header. The writing unit is used to determine the arrival time sequence of the corresponding multi-channel coded frames according to the frame header carried by the multi-channel coded frames, and interleave the multi-channel coded frames into the data area of ​​the same video file based on the arrival time sequence. The file-splitting unit is used to perform unified file-splitting processing on the multiple video encoding channels. During the file-splitting process, it obtains reference frame information carrying channel identifiers for each video encoding channel in the current recording file and writes the reference frame information to the end of the current recording file to generate a unified index area built into the recording file. The unified index area records at least the channel identifier, file offset, and timestamp of the corresponding reference frame. The playback unit is used to play back the current video file based on the playback jump time and the reference frame information in the unified index area, and obtain the target reference frame position corresponding to the multi-channel video encoding channel; The frame alignment unit is used to perform frame-level alignment of the multi-channel encoded frames based on the target reference frame position and through the decode-only-not-render flag in the frame attribute field, so as to control the synchronous rendering and output of video images of the multi-channel video encoding channels.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed on a computer, it causes the computer to perform the method as described in any one of claims 1 to 8.

11. A computer device, comprising a memory and a processor, characterized in that, The processor executes the method as described in any one of claims 1 to 8 by invoking a computer program stored in the memory.