A video data processing method
By processing luminance and chrominance plane data line by line and copying it into memory, YUV422 format video data is converted to YUV420P format, solving the problem of high CPU overhead and improving the real-time performance and efficiency of the DVR system.
Patent Information
- Application Number
- CN202611078639.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-20
- Publication Date
- 2026-11-17
AI Technical Summary
Existing video data merging methods suffer from high CPU overhead and insufficient real-time performance when converting YUV422 format to YUV420P format, affecting the real-time performance of the DVR system and the scheduling of other tasks.
The memory copying method uses whole-line data as units to copy four YUV422 format source video frame data blocks to the target YUV420P format video frame. By processing the luminance and chrominance plane data line by line and performing vertical downsampling during the copying process, the number of loops and memory access frequency are reduced.
It significantly reduced the resource utilization of the central processing unit, improved system throughput and real-time performance, and enhanced the efficiency of multi-channel video synthesis.
Smart Images

Figure CN123123519A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of video processing technology, and in particular to a video data processing method. Background Technology
[0002] In digital video recorder (DVR) systems, it is often necessary to merge YUV422 format video data captured by four independent cameras into a single four-grid YUV420P (I420, Y / U / V three-plane separation, U in front and V behind) format video frame. Compared to YUV422, YUV420P performs half-sampling on the chroma components, reducing the data volume by a quarter. It is also natively supported by most Android hardware encoders, allowing it to be directly used as encoding input, avoiding additional format conversion overhead. This significantly improves efficiency in scenarios involving simultaneous multi-screen display or encoded storage.
[0003] However, existing merging methods employ a pixel-by-pixel traversal approach, calculating the position index of each pixel in both the source and target images and assigning values accordingly. This method involves numerous multiplication and division operations and random memory accesses, with the number of loops proportional to the image area, resulting in low computational efficiency and excessive CPU utilization. This negatively impacts the real-time performance of the DVR system and the scheduling of other tasks. Summary of the Invention
[0004] The purpose of this invention is to disclose a video data processing method that solves the problems of high CPU overhead and insufficient real-time performance when merging four YUV422 videos pixel by pixel into a YUV420P four-grid image.
[0005] To achieve the above objectives, the present invention discloses a video data processing method, comprising: Obtain the YUV422 format data blocks of the four source video frames to be merged and the YUV420P format data block of the target video frame, and obtain the width w and height h of a single source video frame. Based on the width w and height h, determine the data volume of each luminance plane and chrominance plane in the source video frame and the target video frame, as well as their storage location information in the target video frame; In row order, the row data of each luminance plane in the four source video frames are copied to the four corresponding row areas of the luminance plane of the target video frame using a memory copy method. According to the row order, the row data of each chroma plane in the four source video frames are copied to the four corresponding row regions of the chroma plane of the target video frame by memory copying, and the vertical downsampling of the chroma data is completed synchronously during the copying process. Output the target video frame data block.
[0006] Specifically, determining the data volume of each plane and its storage location information in the target video frame based on the width w and height h includes: Calculate the luminance plane data size Y_size = w × h for a single source video frame; Calculate the amount of chroma plane data after vertical downsampling of a single source video frame: UV_src_down = w × h / 4; Calculate the luminance plane data size of the target video frame: Y_out_size = 4 × Y_size = 4 × w × h; Calculate the chroma plane data size of the target video frame: UV_out_size = Y_out_size / 4 = w × h; Calculate the starting offset of the U plane in the target video frame, U_out_offset = Y_out_size, and the starting offset of the V plane in the target video frame, V_out_offset = Y_out_size + UV_out_size.
[0007] Specifically, copying the row data of each luminance plane in the four source video frames to the four corresponding row regions of the luminance plane of the target video frame includes: For row index j, traverse from 0 to h-1, copy the j-th row of data in the luminance plane of the first source data block to the left region of the j-th row in the first row area of the target video frame luminance plane, copy the j-th row of data in the luminance plane of the second source data block to the right region of the j-th row in the first row area of the target video frame luminance plane, copy the j-th row of data in the luminance plane of the third source data block to the left region of the j-th row in the second row area of the target video frame luminance plane, and copy the j-th row of data in the luminance plane of the fourth source data block to the right region of the j-th row in the second row area of the target video frame luminance plane. The first row area corresponds to the upper half of the target video frame, and its row index is 0 to h-1; the second row area corresponds to the lower half of the target video frame, and its row index is h to 2h-1.
[0008] Specifically, the step of copying the row data of each chroma plane in the four source video frames to the four corresponding row regions of the chroma plane in the target video frame and simultaneously performing vertical downsampling during the copying process includes: For row index j, start from 0 and traverse in increments of 2. Only when j is even, perform a copy of the chroma data. At this time, calculate the chroma row index k = j / 2 (integer division) and the row starting offset uv_line_offset in the chroma plane = k × (w / 2). The data of length w / 2 at offset uv_line_offset in the U plane of the four source video frames are copied to the four corresponding row regions of the U plane of the target video frame by means of memory copying. The data of length w / 2 at offset uv_line_offset in the V plane of the four source video frames are copied to the four corresponding row regions of the V plane of the target video frame by means of memory copying.
[0009] Specifically, copying the U-plane data of the four source video frames to the four corresponding row regions of the U-plane of the target video frame includes: Copy the data of length w / 2 at offset uv_line_offset in the U plane of the first source data block to the left region of the kth row in the first row area of the U plane of the target video frame; Copy the data of length w / 2 at offset uv_line_offset in the U plane of the second source data block to the right region of the kth row in the first row area of the U plane of the target video frame; Copy the data of length w / 2 at offset uv_line_offset in the U plane of the third source data block to the left region of the kth row in the second row area of the target video frame U plane; Copy the data of length w / 2 at offset uv_line_offset in the U plane of the fourth source data block to the right region of the kth row in the second row area of the target video frame's U plane.
[0010] Specifically, copying the V-plane data of the four source video frames to the four corresponding row regions of the V-plane of the target video frame includes: Copy the data of length w / 2 at offset uv_line_offset in the V plane of the first source data block to the left region of the kth row in the first row area of the V plane of the target video frame; Copy the data of length w / 2 at offset uv_line_offset in the V plane of the second source data block to the right region of the kth row in the first row area of the target video frame V plane; Copy the data of length w / 2 at offset uv_line_offset in the V plane of the third source data block to the left region of the kth row in the second row area of the target video frame V plane; Copy the data of length w / 2 at offset uv_line_offset in the V plane of the fourth source data block to the right region of the kth row in the second row area of the target video frame's V plane.
[0011] Specifically, the row processing of the luminance plane data and the row processing of the chrominance plane data are executed synchronously in the same row loop: for each row index j, while performing luminance plane row copying, if j is even, then chrominance plane row copying is performed.
[0012] Specifically, the YUV422 format data blocks of the four source video frames have the same width w and height h, and the target video frame has a width of 2w and a height of 2h.
[0013] Specifically, the memory copy is implemented using the standard library function memcpy, with each call specifying the source address, destination address, and copy length; wherein, the length of each row of data copied in the luminance plane is w bytes, and the length of each row and each region copied in the chrominance plane is w / 2 bytes.
[0014] Specifically, the method is executed on an embedded processor or a digital signal processor, and both the source video frame data block and the target video frame data block are stored in contiguous physical memory.
[0015] The beneficial effects of this invention are as follows: This invention replaces the traditional pixel-by-pixel traversal assignment by copying data in whole rows to memory, reducing the number of loops from being proportional to the total number of pixels in the image to being proportional only to the number of rows in the image, thus significantly reducing the number of operations and instruction overhead of the central processing unit. At the same time, since each source video frame data block and the target video frame data block are stored in contiguous memory, the processor cache space can be fully utilized during row-by-row copying, effectively improving the data hit rate and reducing the frequency of access to external memory. While realizing the conversion of YUV422 to YUV420P format and the merging of four grids, it significantly reduces the resource occupancy of the central processing unit and improves the system throughput and overall real-time performance in embedded multi-channel video real-time synthesis scenarios. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating the video data processing method of the present invention; Figure 2 This is a schematic diagram of the target video region division of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] In this invention, the terms "upper," "lower," "left," "right," "front," "rear," "top," "bottom," "inner," "outer," "middle," "vertical," "horizontal," "lateral," and "longitudinal" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. These terms are primarily for the purpose of better describing the invention and its embodiments, and are not intended to limit the indicated devices, elements, or components to having a specific orientation, or to be constructed and operated in a specific orientation.
[0020] Furthermore, in addition to indicating direction or positional relationship, some of the aforementioned terms may also have other meanings. For example, the term "above" may also be used in certain situations to indicate a dependency or connection. Those skilled in the art can understand the specific meaning of these terms in this invention based on the specific circumstances.
[0021] Furthermore, the terms "installation," "setup," "equipped with," "connection," and "linked" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral structure; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium, or an internal connection between two devices, components, or parts. Those skilled in the art can understand the specific meaning of these terms in this invention based on the specific circumstances.
[0022] Furthermore, the terms "first," "second," etc., are primarily used to distinguish different devices, components, or parts (which may be the same or different in specific type and construction), and are not intended to indicate or imply the relative importance or quantity of the indicated devices, components, or parts. Unless otherwise stated, "a plurality of" means two or more.
[0023] The technical solution of the present invention will be further described below with reference to the embodiments and accompanying drawings.
[0024] like Figure 1 As shown, this embodiment provides a video data processing method, including: Step 1: Obtain the YUV422 format data blocks of the four source video frames to be merged, and denote them as the first source data block, the second source data block, the third source data block, and the fourth source data block, respectively; obtain the YUV420P format data block of the target video frame, wherein the YUV420P format data block is an I420 format data block with the Y / U / V three planes separated and the U plane in front and the V plane behind; obtain the width w and height h of a single source video frame, where the units of w and h are pixels.
[0025] Step 2: Calculate the data volume and offset of each plane of the source video frame and the target video frame based on the width w and height h, respectively. This includes the following sub-steps: Step 201: Calculate the luminance plane data size Y_size = w × h for a single source video frame; Step 202: Calculate the amount of chroma plane data after vertical downsampling of a single source video frame: UV_src_down = w × h / 4; Step 203: Calculate the luminance plane data size of the target video frame: Y_out_size = 4 × Y_size = 4 × w × h; Step 204: Calculate the chroma plane data size of the target video frame: UV_out_size = Y_out_size / 4 = w × h; Step 205: Calculate the starting offset of the U plane in the target video frame, U_out_offset = Y_out_size, and the starting offset of the V plane in the target video frame, V_out_offset = Y_out_size + UV_out_size.
[0026] Step 3: Process the brightness plane data row by row, specifically including: For row index j, traverse from 0 to h-1, and copy the j-th row of data in the luminance plane of the first source data block, the second source data block, the third source data block, and the fourth source data block to the corresponding position in the luminance plane of the target video frame; wherein, the j-th row of data in the luminance plane of the first source data block has a length of w bytes and is copied to the left region of the j-th row in the first row area of the luminance plane of the target video frame; the j-th row of data in the luminance plane of the second source data block is copied to the right region of the j-th row in the first row area of the luminance plane of the target video frame; the j-th row of data in the luminance plane of the third source data block is copied to the left region of the j-th row in the second row area of the luminance plane of the target video frame; and the j-th row of data in the luminance plane of the fourth source data block is copied to the right region of the j-th row in the second row area of the luminance plane of the target video frame.
[0027] The first row area corresponds to the upper half of the target video frame, and its row index is 0 to h-1; the second row area corresponds to the lower half of the target video frame, and its row index is h to 2h-1, as follows. Figure 2 As shown.
[0028] All of the above data were copied using a memory copy method.
[0029] Step 4: Process the chromaticity plane data row by row, simultaneously completing vertical downsampling and stitching, specifically including the following sub-steps: Step 401: For row index j, start from 0 and traverse in increments of 2 until all data is read. Only when j is even, copy the chroma data, i.e. when j%2==0, execute steps 402 to 404. Step 402: Calculate the chroma line index k = j / 2 (integer division), and the line starting offset uv_line_offset = k × (w / 2) in the chroma plane; Step 403: Copy the U-plane data, specifically including: a. Copy the data of length w / 2 at offset uv_line_offset in the U plane of the first source data block to the left region of the kth row in the first row area of the U plane of the target video frame; b. Copy the data of length w / 2 at offset uv_line_offset in the U plane of the second source data block to the right region of the kth row in the first row area of the U plane of the target video frame; c. Copy the data of length w / 2 at offset uv_line_offset in the U plane of the third source data block to the left region of the kth row in the second row area of the target video frame U plane; d. Copy the data of length w / 2 at offset uv_line_offset in the U-plane of the fourth source data block to the right region of the kth row in the second row area of the target video frame U-plane; Step 404: Copy the V-plane data, specifically including: a. Copy the data of length w / 2 at offset uv_line_offset in the V plane of the first source data block to the left region of the kth row in the first row area of the target video frame V plane; b. Copy the data of length w / 2 at offset uv_line_offset in the V plane of the second source data block to the right region of the kth row in the first row area of the target video frame V plane; c. Copy the data of length w / 2 at offset uv_line_offset in the V plane of the third source data block to the left region of the kth row in the second row area of the target video frame V plane; d. Copy the data of length w / 2 at offset uv_line_offset in the V plane of the fourth source data block to the right region of the kth row in the second row area of the target video frame V plane; All of the above data were copied using a memory copy method.
[0030] Step 5: Output the target video frame data block, which stores the merged complete YUV420P format video data. Its layout is a four-grid format, specifically: the upper left corner corresponds to the content of the first source data block, the upper right corner corresponds to the content of the second source data block, the lower left corner corresponds to the content of the third source data block, and the lower right corner corresponds to the content of the fourth source data block.
[0031] In one possible implementation, the row processing of the luminance plane data and the row processing of the chrominance plane data are executed synchronously in the same row loop: for each row index j, while executing step 301, if j is even, steps 402 to 404 are executed in parallel or sequentially to improve data processing efficiency and reduce loop overhead.
[0032] In one possible implementation, the memory copy is implemented using the standard library function `memcpy`, with each call specifying the source address, destination address, and copy length. Specifically, the length of a single-line copy in the luma plane is `w` bytes, and the length of a single-line, single-region copy in the chroma plane is `w / 2` bytes.
[0033] In one possible implementation, the method is executed on an embedded processor or digital signal processor, wherein both the source video frame data block and the target video frame data block are stored in contiguous physical memory to achieve optimal transmission efficiency for batch memory copying.
[0034] The technical means disclosed in this invention are not limited to those disclosed in the above embodiments, but also include technical solutions composed of any combination of the above technical features. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this invention, and these improvements and modifications are also considered within the scope of protection of this invention.
Claims
1. A video data processing method, characterized in that, include: Obtain the YUV422 format data blocks of the four source video frames to be merged and the YUV420P format data block of the target video frame, and obtain the width w and height h of a single source video frame. Based on the width w and height h, determine the data volume of each luminance plane and chrominance plane in the source video frame and the target video frame, as well as their storage location information in the target video frame; In row order, the row data of each luminance plane in the four source video frames are copied to the four corresponding row areas of the luminance plane of the target video frame using a memory copy method. According to the row order, the row data of each chroma plane in the four source video frames are copied to the four corresponding row regions of the chroma plane of the target video frame by memory copying, and the vertical downsampling of the chroma data is completed synchronously during the copying process. Output the target video frame data block.
2. The method according to claim 1, characterized in that, The process of determining the data volume of each plane and its storage location information in the target video frame based on the width w and height h specifically includes: Calculate the luminance plane data size Y_size = w × h for a single source video frame; Calculate the amount of chroma plane data after vertical downsampling of a single source video frame: UV_src_down = w × h / 4; Calculate the luminance plane data size of the target video frame: Y_out_size = 4 × Y_size = 4 × w × h; Calculate the chroma plane data size of the target video frame: UV_out_size = Y_out_size / 4 = w × h; Calculate the starting offset of the U plane in the target video frame, U_out_offset = Y_out_size, and the starting offset of the V plane in the target video frame, V_out_offset = Y_out_size + UV_out_size.
3. The method according to claim 2, characterized in that, The step of copying the row data of each luminance plane in the four source video frames to the four corresponding row regions of the luminance plane of the target video frame specifically includes: For row index j, traverse from 0 to h-1, copy the j-th row of data in the luminance plane of the first source data block to the left region of the j-th row in the first row area of the target video frame luminance plane, copy the j-th row of data in the luminance plane of the second source data block to the right region of the j-th row in the first row area of the target video frame luminance plane, copy the j-th row of data in the luminance plane of the third source data block to the left region of the j-th row in the second row area of the target video frame luminance plane, and copy the j-th row of data in the luminance plane of the fourth source data block to the right region of the j-th row in the second row area of the target video frame luminance plane. The first row area corresponds to the upper half of the target video frame, and its row index is 0 to h-1; the second row area corresponds to the lower half of the target video frame, and its row index is h to 2h-1.
4. The method according to claim 3, characterized in that, The step of copying the row data of each chroma plane in the four source video frames to the four corresponding row regions of the chroma plane in the target video frame, and simultaneously performing vertical downsampling during the copying process, specifically includes: For row index j, start from 0 and traverse in increments of 2. Only when j is even, perform a copy of the chroma data. At this time, calculate the chroma row index k = j / 2 (integer division) and the row starting offset uv_line_offset in the chroma plane = k × (w / 2). The data of length w / 2 at offset uv_line_offset in the U plane of the four source video frames are copied to the four corresponding row regions of the U plane of the target video frame by means of memory copying. The data of length w / 2 at offset uv_line_offset in the V plane of the four source video frames are copied to the four corresponding row regions of the V plane of the target video frame by means of memory copying.
5. The method according to claim 4, characterized in that, The step of copying the U-plane data of the four source video frames to the four corresponding row regions of the U-plane of the target video frame specifically includes: Copy the data of length w / 2 at offset uv_line_offset in the U plane of the first source data block to the left region of the kth row in the first row area of the U plane of the target video frame; Copy the data of length w / 2 at offset uv_line_offset in the U plane of the second source data block to the right region of the kth row in the first row area of the U plane of the target video frame; Copy the data of length w / 2 at offset uv_line_offset in the U plane of the third source data block to the left region of the kth row in the second row area of the target video frame U plane; Copy the data of length w / 2 at offset uv_line_offset in the U plane of the fourth source data block to the right region of the kth row in the second row area of the target video frame's U plane.
6. The method according to claim 4, characterized in that, The step of copying the V-plane data of the four source video frames to the four corresponding row regions of the V-plane of the target video frame specifically includes: Copy the data of length w / 2 at offset uv_line_offset in the V plane of the first source data block to the left region of the kth row in the first row area of the V plane of the target video frame; Copy the data of length w / 2 at offset uv_line_offset in the V plane of the second source data block to the right region of the kth row in the first row area of the target video frame V plane; Copy the data of length w / 2 at offset uv_line_offset in the V plane of the third source data block to the left region of the kth row in the second row area of the target video frame V plane; Copy the data of length w / 2 at offset uv_line_offset in the V plane of the fourth source data block to the right region of the kth row in the second row area of the target video frame's V plane.
7. The method according to claim 1, characterized in that, The row processing of the luminance plane data and the row processing of the chrominance plane data are executed synchronously in the same row loop: for each row index j, while performing luminance plane row copying, if j is even, chrominance plane row copying is performed.
8. The method according to any one of claims 1 to 7, characterized in that, The YUV422 format data blocks of the four source video frames have the same width w and height h, and the target video frame has a width of 2w and a height of 2h.
9. The method according to claim 8, characterized in that, The memory copy is implemented using the standard library function memcpy, with each call specifying the source address, destination address, and copy length. The length of each row of data copied in the luminance plane is w bytes, and the length of each row and each region copied in the chrominance plane is w / 2 bytes.
10. The method according to claim 9, characterized in that, The method is executed on an embedded processor or a digital signal processor, wherein both the source video frame data block and the target video frame data block are stored in contiguous physical memory.
