AI video image compression method and system

By using AI-based video image compression methods for pixel-level semantic region recognition and importance classification, combined with quantization parameter mapping of the H.265 encoder, the problem of encoding imbalance between high-value targets and background areas in surveillance videos is solved, achieving efficient compression and bitrate optimization of surveillance videos.

CN122120465APending Publication Date: 2026-05-29SHENZHEN FANGYUANBAO INFORMATION TECH SERVICE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHENZHEN FANGYUANBAO INFORMATION TECH SERVICE CO LTD
Filing Date
2026-02-06
Publication Date
2026-05-29

Smart Images

  • Figure CN122120465A_ABST
    Figure CN122120465A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of video image compression, and discloses an AI video image compression method and system, which comprises the following steps: decoding a monitoring video stream to obtain video metadata and a luminance frame sequence; performing pixel classification based on the luminance frame sequence to construct an importance weight graph; calculating a static background mask according to the luminance frame sequence, adjusting the pixel weight value of pixels belonging to a third-level low-value area and the static background mask at the same time, and generating a background modeling fusion weight graph; creating a quantization parameter graph based on the background modeling fusion weight graph, inputting the H.265 encoder, keeping the video metadata unchanged, obtaining a compressed video code stream, and further realizing pixel-level semantic region recognition; and establishing an importance classification system through morphological optimization, establishing a cross-scale mapping relationship between pixel-level semantic understanding and the quantization parameter of the coding unit of the H.265 encoder, and solving the technical problem that semantic segmentation and video coding are independent of each other and cannot be cooperatively optimized in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of video image compression technology, and in particular to an AI video image compression method and system. Background Technology

[0002] With the widespread adoption of high-definition surveillance systems and increasingly stringent regulations on storage time limits, the cost of video data storage has risen dramatically. Existing H.264 and H.265 encoding standards use uniform quantization parameters to encode the entire video frame when compressing surveillance video, failing to distinguish between high-value target areas (such as faces and license plates) and background areas with no business value (such as sky and vegetation). This results in the loss of detail in critical targets or wasted bitrate in background areas.

[0003] Traditional encoders make encoding decisions based on macroblocks or coding units, with the smallest coding unit being a 16×16 or 64×64 pixel block. This lacks pixel-level fine-grained content recognition capabilities, making it impossible to achieve optimal encoding for small areas of the screen, such as faces and license plates. Furthermore, surveillance videos possess spatiotemporal characteristics, such as long-term static background areas and fixed high-value monitoring target areas. Existing encoding technologies do not incorporate spatiotemporal joint encoding strategies tailored to the characteristics of surveillance operations, resulting in significant bitrate waste due to repeated encoding of static background frames. Summary of the Invention

[0004] This invention provides an AI video image compression method and system, which achieves pixel-level semantic region recognition and establishes an importance classification system through morphological optimization. It establishes a cross-scale mapping relationship between pixel-level semantic understanding and the coding unit quantization parameters of the H.265 encoder, solving the technical problem that semantic segmentation and video coding are independent and cannot be optimized in coordination in the prior art.

[0005] The first aspect of this invention provides an AI video image compression method, the AI ​​video image compression method comprising: Decode the surveillance video stream to obtain video metadata and luminance frame sequences; Pixel classification is performed based on the brightness frame sequence to obtain a semantic label map, and an importance weight map is constructed based on the semantic label map; Calculate the static background mask based on the brightness frame sequence, adjust the pixel weight values ​​that belong to both the third-level low-value region and the static background mask, and generate a background modeling fusion weight map. A quantization parameter map is created based on the background modeling and fusion weight map. The quantization parameter map is then input into the H.265 encoder while keeping the video metadata unchanged to obtain the compressed video bitstream.

[0006] In conjunction with the first aspect, in a first implementation of the first aspect of the present invention, the step of decoding the surveillance video stream to obtain video metadata and a luminance frame sequence includes: Receive the monitoring video stream, call the video decoding function to decode frame by frame to obtain a video frame sequence in YUV color space format, and extract video metadata synchronously. Extract the Y luminance component of each frame in the video frame sequence, and divide each pixel value of the Y luminance component by the maximum pixel value to obtain the luminance frame sequence.

[0007] In conjunction with the first aspect, in a second implementation of the first aspect of the present invention, the step of performing pixel classification based on the luminance frame sequence to obtain a semantic label map, and constructing an importance weight map based on the semantic label map, includes: The luminance frame sequence is semantically segmented to output a semantic feature map, and the semantic feature map is then fused with contextual features to output a context-enhanced feature map. Each pixel in the context-enhanced feature map is classified into one of the following categories: sky region, road surface region, road marking region, vehicle body region, license plate region, human body region, human face region, and background vegetation region, and a semantic label map is output. Based on the semantic label graph, values ​​are assigned to different regions to generate an importance weight graph.

[0008] In conjunction with the first aspect, in a third implementation of the first aspect of the present invention, the step of assigning values ​​to different regions based on the semantic tag graph to generate an importance weight graph includes: Traverse the semantic category of each pixel in the semantic label image, and mark the pixels of the face region and license plate region as the first-level high-value region mask, the pixels of the vehicle body region, human body region and road marking region as the second-level medium-value region mask, and the pixels of the sky region and background vegetation region as the third-level low-value region mask. Perform a morphological closing operation on the first-level high-value region mask and a morphological opening operation on the third-level low-value region mask to obtain the target region mask; Each pixel in the target region mask is traversed, and a first weight value is assigned to pixels belonging to the first-level high-value region mask, a second weight value is assigned to pixels belonging to the second-level medium-value region mask, and a third weight value is assigned to pixels belonging to the third-level low-value region mask, thereby generating an importance weight map.

[0009] In conjunction with the first aspect, in a fourth implementation of the first aspect of the present invention, the step of calculating a static background mask based on the luminance frame sequence, adjusting the pixel weight values ​​that simultaneously belong to the third-level low-value region and the static background mask, and generating a background modeling fusion weight map includes: Optical flow estimation is performed on the brightness frame sequence and the correlation of all pixel pairs between frames is calculated to obtain the motion vector field; Perform the sum of squares and square root operations on the x-direction motion component and y-direction motion component of each pixel in the motion vector field to generate a motion amplitude map; Set a motion threshold, compare the motion amplitude value of each pixel position in the motion amplitude map of multiple consecutive frames with the motion threshold, and count the number of times each pixel position is stationary when the motion amplitude is lower than the motion threshold in multiple consecutive frames. When the number of static occurrences exceeds a preset threshold, the corresponding pixel is marked as a long-term static pixel, and a static background mask is generated. The weight values ​​of pixels that simultaneously belong to the static background mask and the third-level low-value region mask are adjusted in the importance weight map to obtain the background modeling fusion weight map.

[0010] In conjunction with the first aspect, in the fifth implementation of the first aspect of the present invention, the step of creating a quantization parameter map based on the background modeling and fusion weight map, inputting the quantization parameter map into an H.265 encoder while keeping the video metadata unchanged, to obtain a compressed video bitstream, includes: The video frame is divided into several coding units according to the H.265 coding standard, and the average weight value is calculated based on the weight values ​​of all pixels in the background modeling fusion weight map within the coverage area of ​​each coding unit. When the average weight value is greater than or equal to the first threshold, the first level of quantization parameter is assigned; when the average weight value is between the first and second thresholds, the second level of quantization parameter is assigned; when the average weight value is less than the second threshold and the coding unit belongs to the static background mask, the third level of quantization parameter is assigned; when the average weight value is less than the second threshold and the coding unit does not belong to the static background mask, the fourth level of quantization parameter is assigned, and a quantization parameter map is generated. When encoding each encoding unit, the quantization parameter value at the corresponding position is read from the quantization parameter graph and assigned to the quantization parameter variable of the encoding unit, while keeping the video metadata unchanged, to obtain the compressed video bitstream.

[0011] In conjunction with the first aspect, in the sixth implementation of the first aspect of the present invention, after allocating the fourth-level quantization parameter, it further includes: After allocating the fourth-level quantization parameters, an initial parameter map is generated; For each coding unit position in the initial parameter map, the quantization parameter values ​​of the neighboring coding units are extracted, and median filtering is performed based on the quantization parameter values ​​of the neighboring coding units to obtain the filtered parameter map; Traverse each coding unit at the i-th row and j-th column position in the filter parameter graph, calculate the quantization parameter difference between the coding unit and its adjacent coding units at the (i+1)-th row and j-th column, and adjust the quantization parameters of the coding unit based on the quantization parameter difference to obtain the quantization parameter graph.

[0012] In conjunction with the first aspect, in the seventh implementation of the first aspect of the present invention, the step of reading the quantization parameter value at the corresponding position from the quantization parameter map and assigning it to the quantization parameter variable of the encoding unit while keeping the video metadata unchanged, to obtain the compressed video bitstream, includes: Create an initial encoder and configure the encoding parameters, then assign the video metadata to the initial encoder to obtain an encoder instance; When processing each encoding unit in the main encoding loop of the encoder instance, the quantization parameter value is read from the corresponding coordinate position of the quantization parameter map according to the row and column coordinates of the encoding unit in the video frame and directly assigned to the quantization parameter variable of the encoding unit; When the coding unit belongs to the first-level high-value region, the skip coding mode is disabled and the coding unit size is limited. When the coding unit belongs to the third-level low-value region, the early termination mechanism is enabled, resulting in an H.265 encoded bitstream. The H.265 encoded bitstream is encapsulated into a video container format, and the timestamp parameter, bitrate parameter, and audio stream parameter are written into the video metadata to generate a compressed video bitstream that retains the video metadata unchanged.

[0013] In conjunction with the first aspect, in the eighth implementation of the first aspect of the present invention, the step of disabling the skip coding mode and limiting the coding unit size when the coding unit belongs to the first-level high-value region, and enabling the early termination mechanism when the coding unit belongs to the third-level low-value region, to obtain the H.265 encoded bitstream, includes: When the coding unit belongs to the first-level high-value region, the skip coding mode is disabled in the coding configuration and the maximum size of the coding unit is limited while the intra-frame prediction mode is forced to be used. When the coding unit belongs to the third-level low-value region, the early termination mechanism is enabled and the coding mode is skipped directly when the rate-distortion cost is lower than the preset threshold. Encoding processing is performed sequentially on all coding units in the video frame sequence. Quantization operation with the corresponding quantization step size is performed according to the quantization parameter variable value of each coding unit to obtain the H.265 encoded bitstream.

[0014] A second aspect of the present invention provides an AI video image compression system, the AI ​​video image compression system comprising: The decoding module is used to decode the surveillance video stream to obtain video metadata and luminance frame sequences; A pixel classification module is used to classify pixels based on the brightness frame sequence, obtain a semantic label map, and construct an importance weight map based on the semantic label map. The background modeling module is used to calculate a static background mask based on the brightness frame sequence, adjust the pixel weight values ​​that belong to both the third-level low-value region and the static background mask, and generate a background modeling fusion weight map. The compression module is used to create a quantization parameter map based on the background modeling and fusion weight map, input the quantization parameter map into the H.265 encoder while keeping the video metadata unchanged, and obtain the compressed video bitstream.

[0015] Compared with existing technologies, this invention achieves pixel-level semantic region recognition and establishes an importance classification system through morphological optimization. It establishes a cross-scale mapping relationship between pixel-level semantic understanding and the quantization parameters of the coding units in the H.265 encoder, solving the technical problem that semantic segmentation and video coding are independent and cannot be co-optimized in existing technologies. This invention achieves pixel-level motion feature extraction through 4D correlation pyramid calculation of the RAFT optical flow estimation network, and identifies long-term static background regions by combining temporal cumulative analysis. It logically and computationally fuses spatial semantic hierarchies with temporal motion features, establishing a spatiotemporal joint background modeling mechanism. It performs deep quantization on regions that simultaneously meet the dual conditions of low value and static background, achieving full utilization of the spatiotemporal characteristics of the monitoring scene. This invention directly maps the quantization parameter map at the encoding unit level to the quantization parameter variables of the encoding unit by modifying the x265 encoder source code, bypassing the original bitrate control module. It implements a differentiated encoding strategy based on region categories (disabling skip mode and limiting encoding unit size in high-value regions, and enabling early termination mechanism in low-value regions). While keeping the video resolution, frame rate, encoding format, and metadata completely unchanged, it maintains visually lossless quality for high-value targets such as faces and license plates, while implementing high quantization step size deep compression for low-value background regions, thus realizing business-oriented intelligent compression encoding of surveillance videos. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art 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] The structures, proportions, sizes, etc., shown in the accompanying drawings of this specification are only for the purpose of assisting those skilled in the art in understanding and reading the content disclosed in the specification, and are not intended to limit the conditions under which the present invention can be implemented. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportions, or adjustments to the size, without affecting the effects and objectives that the present invention can produce, should still fall within the scope of the technical content disclosed in the present invention.

[0018] Figure 1 This is a flowchart illustrating the AI ​​video image compression method provided in an embodiment of the present invention; Figure 2 This is a schematic block diagram of the AI ​​video image compression system provided in an embodiment of the present invention. Detailed Implementation

[0019] 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, not all, of the embodiments of the present invention. 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.

[0020] The flowchart shown in the attached diagram is for illustrative purposes only and does not necessarily include all content and operations / steps, nor does it necessarily have to be performed in the order described. For example, some operations / steps can be broken down, combined, or partially merged, so the actual execution order may change depending on the actual situation.

[0021] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0022] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items, and all possible combinations, and includes such combinations. See also Figure 1 One embodiment of the AI ​​video image compression method in this invention includes: Step 100: Decode the monitoring video stream to obtain video metadata and luminance frame sequences; Step 200: Perform pixel classification based on the brightness frame sequence to obtain a semantic label map, and construct an importance weight map based on the semantic label map; Step 300: Calculate the static background mask based on the brightness frame sequence, adjust the pixel weight values ​​that belong to both the third-level low-value region and the static background mask, and generate a background modeling fusion weight map. Step 400: Create a quantization parameter map based on the background modeling and fusion weight map, input the quantization parameter map into the H.265 encoder while keeping the video metadata unchanged, and obtain the compressed video bitstream.

[0023] In one specific embodiment, the process of performing step 100 may specifically include the following steps: Receive the monitoring video stream, call the video decoding function to decode frame by frame to obtain a video frame sequence in YUV color space format, and extract video metadata synchronously. Extract the Y luminance component of each frame in the video frame sequence, and divide each pixel value of the Y luminance component by the maximum pixel value to obtain the luminance frame sequence.

[0024] Specifically, a video input receiving module is constructed. This module connects to the front-end network camera IPC or surveillance video platform and receives video streams compressed and encapsulated according to H.264 or H.265 encoding standards. By calling video decoding interfaces in the multimedia processing library, such as the avcodec_decode_video2 function in the FFmpeg framework, the compressed video stream is parsed frame by frame, and each frame is decoded and restored to its original frame format. The color space adopts the YUV420P structure, which separates luminance and chrominance information. The Y component represents the grayscale intensity of each pixel while maintaining full resolution, while the U and V chrominance components use 2×2 subsampling to reduce spatial resolution and achieve color information compression. During the decoding operation of each frame, video metadata information, including frame rate, resolution, bitrate, encoder type, audio and video channel identifiers, timestamp information, etc., is extracted simultaneously from the bitstream header and frame structure. All metadata is stored in a structured data structure. The Y component image is extracted from each frame of decoded YUV420P data. The Y component is a two-dimensional matrix structure with dimensions consistent with the video frame resolution. For example, for a 1920×1080 resolution, the Y component matrix is ​​1920 columns × 1080 rows, representing the brightness values ​​of all pixels in the entire image. During the extraction process, memory pointers are ensured to be correctly aligned to read the brightness bytes row by row. After obtaining the Y brightness matrix, a normalization operation is performed on each pixel value. The calculation formula is that the normalized brightness value equals the original pixel value divided by the maximum pixel value, where the maximum pixel value is fixed at 255, to map the brightness values ​​to a floating-point range of [0.0, 1.0], forming a brightness frame sequence composed of continuous floating-point matrices.

[0025] In one specific embodiment, the process of performing step 200 may specifically include the following steps: The luminance frame sequence is semantically segmented to output a semantic feature map, and the semantic feature map is then fused with contextual features to output a context-enhanced feature map. Each pixel in the context-enhanced feature map is classified into one of the following categories: sky region, road surface region, road marking region, vehicle body region, license plate region, human body region, human face region, and background vegetation region, and a semantic label map is output. Based on the semantic label graph, values ​​are assigned to different regions to generate an importance weight graph.

[0026] Specifically, a deep neural network architecture adapted to surveillance video scenarios is constructed. This architecture uses normalized luminance frames as input and employs a network structure with strong high-resolution feature preservation capabilities, such as HRNet-OCR. After inputting the luminance frames, the network extracts spatial semantic information at different scales in the image through parallel multi-resolution sub-networks, ensuring that the input image does not experience spatial resolution compression during the entire forward propagation process, thus avoiding the loss of details in small target regions during high-level semantic feature extraction. Contextual relationship modeling is performed based on the OCR module. The OCR module constructs a three-stage semantic modeling path: pixel-region-pixel. This ensures that the semantic features of each pixel are not only determined by its own convolutional receptive field but also integrate the global contextual information of its region. Specifically, clustering or softmax mechanisms are first used to assign pixels to different semantic regions, then the context vector of each region is calculated, and finally, the region features are distributed back to each pixel position according to attention weights, achieving enhanced semantic consistency and boundary clarity, and outputting a context-enhanced feature map. Based on the context-enhanced feature map, a softmax classification layer is used to perform multi-class classification probability judgment on the feature vector output at each pixel location. The category corresponding to the highest probability is used as the final semantic classification label for that pixel, and it is mapped to an integer value to obtain a two-dimensional semantic label map with the same resolution as the input image. The value range of each pixel corresponds to eight predefined semantic categories: sky region, road surface region, road marking region, vehicle body region, license plate region, human body region, face region, and background vegetation region. Based on the semantic label map, a corresponding importance value is assigned to each semantic category to construct a floating-point type importance weight map. The assignment strategy is determined according to the monitoring business priority. For example, the face region and license plate region are assigned a value of 1.0 to retain their highest visual quality, the vehicle body, human body, and road marking are assigned a value of 0.5 to retain medium quality, and the sky and background vegetation regions are assigned a value of 0.1 to implement deep compression. For some misclassified regions or regions with blurred boundaries, morphological optimization or edge smoothing is performed to avoid visual jumps or model misidentification, forming a two-dimensional importance weight map.

[0027] In one specific embodiment, the process of assigning values ​​to different regions based on the semantic label graph and generating an importance weight graph can specifically include the following steps: Traverse the semantic category of each pixel in the semantic label image, and mark the pixels of the face region and license plate region as the first-level high-value region mask, the pixels of the vehicle body region, human body region and road marking region as the second-level medium-value region mask, and the pixels of the sky region and background vegetation region as the third-level low-value region mask. Perform a morphological closing operation on the first-level high-value region mask and a morphological opening operation on the third-level low-value region mask to obtain the target region mask; Each pixel in the target region mask is traversed, and a first weight value is assigned to pixels belonging to the first-level high-value region mask, a second weight value is assigned to pixels belonging to the second-level medium-value region mask, and a third weight value is assigned to pixels belonging to the third-level low-value region mask, thereby generating an importance weight map.

[0028] Specifically, a pixel-level mask image generation module is constructed. This module receives pixel-by-pixel classification information from the semantic label image and determines the semantic category code corresponding to each pixel by traversing the two-dimensional pixel matrix of the entire label image. When the label value is equal to the predefined face category number or license plate category number, the corresponding pixel position is assigned a value of 255 in the first-level high-value mask image; otherwise, it is assigned a value of 0. When the label value corresponds to the vehicle body, human torso, or road marking number, it is marked in the second-level medium-value mask image. Similarly, pixels corresponding to the sky and background vegetation category numbers are recorded in the third-level low-value mask image. Morphological closing operations are performed on the first-level mask image to fill in holes and discontinuities caused by lighting shadows and occlusion interference in the face or license plate regions, so that these key target regions form a connected and complete target boundary structure in the mask. At the same time, morphological opening operations are performed on the third-level mask image to remove isolated noise points caused by semantic segmentation errors, avoiding misclassification of local erroneous pixels as low-value regions. After optimizing the structure of the mask image, a floating-point type importance weight map with the same resolution as the original image is constructed. By iterating through the values ​​of each pixel position in the three mask images again, pixels in the first-level high-value mask are assigned a first weight value such as 1.0, pixels in the second-level mask are assigned a second weight value such as 0.5, and pixels in the third-level low-value region mask are assigned a third weight value such as 0.1, thus forming a floating-point weight map.

[0029] In one specific embodiment, the process of performing step 300 may specifically include the following steps: Optical flow estimation is performed on the brightness frame sequence and the correlation of all pixel pairs between frames is calculated to obtain the motion vector field; Perform the sum of squares and square root operations on the x-direction motion component and y-direction motion component of each pixel in the motion vector field to generate a motion amplitude map; Set a motion threshold, compare the motion amplitude value of each pixel position in the motion amplitude map of multiple consecutive frames with the motion threshold, and count the number of times each pixel position is stationary when the motion amplitude is lower than the motion threshold in multiple consecutive frames. When the number of static occurrences exceeds a preset threshold, the corresponding pixel is marked as a long-term static pixel, and a static background mask is generated. The weight values ​​of pixels that simultaneously belong to the static background mask and the third-level low-value region mask are adjusted in the importance weight map to obtain the background modeling fusion weight map.

[0030] Specifically, a frame pair sequence is constructed based on continuous luminance frames, and an optical flow estimation network such as RAFT is used to model the pixel-level motion state between adjacent frames. During processing, the luminance component map is extracted from each pair of adjacent frames and used as the optical flow input pair. The network establishes a full pair correlation structure at all pixel positions, constructs a four-dimensional correlation pyramid, and optimizes the matching relationship at multiple scales to output a dense optical flow field with the same resolution as the input image and two channels. Each pixel position stores the continuous displacement in the x and y directions, resulting in a motion vector field. The horizontal and vertical displacement components of each pixel are squared and then square-rooted to calculate the instantaneous motion amplitude of the corresponding pixel between frames, generating a floating-point motion amplitude map, where each position value represents the motion intensity of the pixel between the current two frames. A small motion threshold of about 2.0 pixels / frame is set to distinguish between stationary and slightly moving regions. The motion amplitude maps in multiple consecutive frames (e.g., 16 frames) are compared frame by frame. For each pixel position, the number of frames in which its motion amplitude is less than the set threshold is counted and recorded as the number of stationary periods. When a pixel remains stationary more than a preset stationary threshold (e.g., 14 times), it is considered a long-term stationary pixel because it has remained stationary in most frames. All pixels meeting the long-term stationary condition are uniformly marked as static background pixels, forming a binary static background mask. A pixel-by-pixel logical AND operation is performed between the static background mask and the third-level low-value region mask to filter out a set of pixels that are both long-term stationary and semantically belong to low-value regions such as background vegetation or sky. The weight values ​​of these pixels in the original importance weight map are then downgraded, for example, from 0.1 to 0.05 or lower, generating a background compression and enhancement remap that incorporates static modeling features.

[0031] In one specific embodiment, the process of performing step 400 may specifically include the following steps: The video frame is divided into several coding units according to the H.265 coding standard, and the average weight value is calculated based on the weight values ​​of all pixels in the background modeling fusion weight map within the coverage area of ​​each coding unit. When the average weight value is greater than or equal to the first threshold, the first level of quantization parameter is assigned; when the average weight value is between the first and second thresholds, the second level of quantization parameter is assigned; when the average weight value is less than the second threshold and the coding unit belongs to the static background mask, the third level of quantization parameter is assigned; when the average weight value is less than the second threshold and the coding unit does not belong to the static background mask, the fourth level of quantization parameter is assigned, and a quantization parameter map is generated. When encoding each encoding unit, the quantization parameter value at the corresponding position is read from the quantization parameter graph and assigned to the quantization parameter variable of the encoding unit, while keeping the video metadata unchanged, to obtain the compressed video bitstream.

[0032] Specifically, based on the H.265 coding standard, each frame of image is divided into a series of coding tree units (CTUs). Each CTU is 64×64 pixels in size and serves as the most basic spatial partitioning unit in the video coding process. After the image partitioning is completed, based on the pixel set of the corresponding region of each coding unit on the background modeling fusion weight map, all pixels in the region of the coding unit are traversed and their corresponding weight values ​​are extracted. Weighted accumulation and normalization processing are performed to calculate the average weight value of the coding unit. The system performs interval judgment based on the average weight value and two set weight thresholds. When the average weight value is greater than or equal to the first threshold, it indicates that the area covered by the coding unit mainly contains high-value target areas such as faces or license plates. In this case, a first-level quantization parameter, i.e., a lower QP value, is assigned to maintain high-fidelity image quality. If the average weight value is between the first and second thresholds, it indicates that the coding unit mainly involves medium-value areas such as vehicle bodies, human outlines, or road markings. A second-level quantization parameter is assigned, with its QP value in a medium range to achieve a balance between visual quality and compression rate. When the average weight value is lower than the second threshold, it is determined whether the coding unit is within the range of a static background mask. If it is within the static background mask area, the content of the coding unit is determined to be semantically low-value and temporally stable image content. A third-level quantization parameter is assigned, i.e., the highest QP value is used for deep compression. If the low-weight unit is not marked as a static area by the background modeling, such as dynamic low-value areas like swaying leaves or water reflections, a fourth-level quantization parameter is assigned, with its QP value lower than the third-level quantization parameter but higher than the second-level quantization parameter, to retain some dynamic details and avoid compression anomalies. Based on the allocation results of all coding units, a two-dimensional quantization parameter map of the entire frame is generated. The size of the quantization parameter map corresponds to the CTU partitioning layout. Entering the H.265 encoding process, a customized x265 encoder is invoked. In the main encoding loop of each frame, the CTU units are traversed one by one, and the corresponding QP value is found in the quantization parameter map according to their spatial coordinates. The QP value is assigned to the quantization parameter variable of the current coding unit, overriding the encoder's original bitrate control module. This enables the encoder to execute the externally guided layered QP control strategy, while keeping the metadata information of the input video frame, such as resolution, frame rate, duration, audio parameters, and encoding type, completely unchanged, generating a compressed video stream conforming to the H.265 standard.

[0033] In one specific embodiment, after allocating the fourth-level quantization parameter, the method further includes: After allocating the fourth-level quantization parameters, an initial parameter map is generated; For each coding unit position in the initial parameter map, the quantization parameter values ​​of the neighboring coding units are extracted, and median filtering is performed based on the quantization parameter values ​​of the neighboring coding units to obtain the filtered parameter map; Traverse each coding unit at the i-th row and j-th column position in the filter parameter graph, calculate the quantization parameter difference between the coding unit and its adjacent coding units at the (i+1)-th row and j-th column, and adjust the quantization parameters of the coding unit based on the quantization parameter difference to obtain the quantization parameter graph.

[0034] Specifically, after executing the quantization layering strategy based on background modeling, weight map fusion, and static mask, the entire video frame is divided into CTU structures according to the H.265 coding standard, and each CTU unit is assigned a corresponding quantization parameter QP value, forming a two-dimensional quantization parameter map. Each element in the map represents the quantization intensity level of the corresponding coding unit, with levels one to four reflecting the coding intent from high fidelity to deep compression, respectively. Due to significant semantic differences in different regions, the initial quantization parameter map may show excessively large differences in QP values ​​between adjacent coding units, which can easily lead to compression block effects or sudden changes in image quality at the boundaries. Therefore, a spatial smoothing mechanism is introduced to perform a two-dimensional spatial median filtering operation on the quantization parameter map. For each coding unit position in the initial parameter map, a 3×3 or 5×5 coding unit neighborhood window is constructed with that point as the center, and the QP value set of all effective neighboring CTUs within the window is extracted. The median value in the set is calculated, and the median value is used to replace the original coding unit's QP value, generating a filter parameter map with a continuous structure and natural transition. For each coding unit at the i-th row and j-th column position in the filter parameter map, bidirectional difference detection is performed. That is, the QP difference between the coding unit and the coding unit below it (i+1-th row and j-th column) and the coding unit to its right (i-th row and j+1-th column) is calculated respectively, and it is determined whether the difference exceeds a preset smoothing threshold. If the difference in one direction is greater than the preset smoothing threshold, the coding unit with the larger QP value is corrected downward so that the difference between its QP value and that of its adjacent unit does not exceed the preset smoothing threshold. For example, the correction strategy is to set a maximum allowable jump of 8 levels. That is, if the difference between adjacent coding units is 12, the high QP value unit is reduced to only 8 levels greater than the low QP value to avoid visual banding. By performing difference constraint traversal correction on the entire filter parameter map, a quantization parameter map with hierarchical continuity, structural smoothness and visual uniformity is obtained.

[0035] In one specific embodiment, the process of reading the quantization parameter value at the corresponding position from the quantization parameter map and assigning it to the quantization parameter variable of the encoding unit while keeping the video metadata unchanged to obtain the compressed video bitstream can specifically include the following steps: Create an initial encoder and configure the encoding parameters, then assign the video metadata to the initial encoder to obtain an encoder instance; When processing each encoding unit in the main encoding loop of the encoder instance, the quantization parameter value is read from the corresponding coordinate position of the quantization parameter map according to the row and column coordinates of the encoding unit in the video frame and directly assigned to the quantization parameter variable of the encoding unit; When the coding unit belongs to the first-level high-value region, the skip coding mode is disabled and the coding unit size is limited. When the coding unit belongs to the third-level low-value region, the early termination mechanism is enabled, resulting in an H.265 encoded bitstream. The H.265 encoded bitstream is encapsulated into a video container format, and the timestamp parameter, bitrate parameter, and audio stream parameter are written into the video metadata to generate a compressed video bitstream that retains the video metadata unchanged.

[0036] Specifically, an initial encoder structure instance based on the x265 kernel is created, and the structure is configured with encoding parameters consistent with the original video, including video frame resolution, height and width parameters, frame rate parameters, sampling format, color space information, bitrate control strategy, etc. Simultaneously, fields such as the timestamp sequence, audio stream information, original average bitrate, and encoding format identifier from the metadata structure extracted during the video decoding stage are written into the encoder configuration fields to ensure that the compressed video is consistent with the original video in terms of encapsulation structure and playback compatibility. After initialization, the main encoding loop is started. In the main encoding loop, each frame is processed frame by frame, and the encoding units in each frame are traversed row by row and column by column. When processing a specific encoding unit, the position coordinates of the encoding unit within the frame are obtained, such as (i, j). The QP value under the position coordinates is extracted from the pre-generated quantization parameter map and forcibly written into the corresponding quantization parameter variable in the encoder's CU structure. This bypasses the x265 default CQP or CRF control flow, ensuring that each encoding unit executes a custom QP control strategy driven by both semantic and motion characteristics. After the assignment is completed, the encoding decision stage begins. If the current encoding unit belongs to a block identified and recorded as a first-level high-value region by the semantic label map, the skip encoding mode and inter-frame prediction mode are forcibly disabled, and its partition size is limited to no more than 16×16 pixels. This preserves more details and structural information during the encoding process, enhancing the edge quality and texture features of key regions such as faces and license plates. Conversely, if the current encoding unit belongs to a third-level low-value region in the semantic layer and is also judged as a static background in motion analysis, the early termination mechanism in the encoder is enabled. When its rate-distortion cost is lower than a preset threshold, the maximum CU size of 64×64 is directly adopted and the skip encoding mode is enabled to skip the complex prediction and transformation process, thereby effectively reducing the encoding computation burden and significantly improving the compression ratio. After all encoding units complete their encoding, a continuous H.265 compressed bitstream is formed. In the final stage, the H.265 compressed bitstream is encapsulated into a standard video container format such as MP4 or TS. During the encapsulation process, the multimedia multiplexing module is called to write the timestamp information from the original video metadata into the container header of each frame to maintain the playback sequence. The audio stream data is encapsulated synchronously in the form of the original bitstream, and the original bitrate parameters are used to update the bitrate field of the container. This allows the compressed video to be compressed as a whole without changing the encapsulation format, modifying the timeline, or destroying the audio and video synchronization characteristics, and outputs the compressed video bitstream.

[0037] In one specific embodiment, the process of disabling skip coding mode and limiting coding unit size when the coding unit belongs to the first-level high-value region, and enabling early termination mechanism when the coding unit belongs to the third-level low-value region, to obtain the H.265 encoded bitstream, can specifically include the following steps: When the coding unit belongs to the first-level high-value region, the skip coding mode is disabled in the coding configuration and the maximum size of the coding unit is limited while the intra-frame prediction mode is forced to be used. When the coding unit belongs to the third-level low-value region, the early termination mechanism is enabled and the coding mode is skipped directly when the rate-distortion cost is lower than the preset threshold. Encoding processing is performed sequentially on all coding units in the video frame sequence. Quantization operation with the corresponding quantization step size is performed according to the quantization parameter variable value of each coding unit to obtain the H.265 encoded bitstream.

[0038] Specifically, a dynamically controllable encoding strategy entry is retained during the encoder initialization phase, enabling adaptive decision-making based on the semantic label map and fusion weight map during the encoding process. When processing a specific encoding unit, if the encoding unit is determined to be within a first-level high-value region such as a face or license plate, the skip encoding mode is immediately disabled in the encoding configuration. That is, the skip flag of the encoding unit is cleared to zero in the encoder's internal settings, and the inter-frame prediction path is blocked to prevent it from directly referencing historical images and ignoring current detail changes. At the same time, the maximum size of the encoding unit is set to not exceed 16×16 in the partitioning control module. The pixel size requires intra-frame prediction to be performed in a smaller CU structure, thereby improving its ability to preserve high-frequency details such as edge contours and texture features. When the coding unit belongs to the third-level low-value area, such as static background or distant buildings, an early termination mechanism is enabled in the encoder rate control structure. The rate distortion cost is calculated during the intra-frame prediction or inter-frame prediction search stage and compared with a preset threshold. When the rate distortion cost is lower than the threshold, skip coding is triggered directly, skipping the residual calculation and transform quantization process, quickly outputting the inter-frame reference frame index and generating the simplest codeword, effectively compressing the code rate occupation of redundant areas. All coding units in each frame of video are processed sequentially in row and column order. When entering the transform and quantization stage, the quantization step size Qstep value is determined according to the corresponding quantization parameter QP value. The DCT coefficients or DST coefficients in the prediction residual block are uniformly quantized according to the quantization step size, that is, each frequency domain coefficient is divided by the quantization step size and rounded to an integer. The quantization coefficients, prediction modes, intra-frame and inter-frame identifiers, motion vectors and transform indexes of all coding blocks are packaged into compressed coding syntax elements and summarized to form the H.265 encoded bitstream.

[0039] The AI ​​video image compression method in the embodiments of the present invention has been described above. The AI ​​video image compression system in the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 2 One embodiment of the AI ​​video image compression system in this invention includes: Decoding module 11 is used to decode the monitoring video stream to obtain video metadata and luminance frame sequences; The pixel classification module 12 is used to classify pixels based on the brightness frame sequence, obtain a semantic label map, and construct an importance weight map based on the semantic label map. Background modeling module 13 is used to calculate a static background mask based on the brightness frame sequence, adjust the pixel weight values ​​that belong to both the third-level low-value region and the static background mask, and generate a background modeling fusion weight map. Compression module 14 is used to create a quantization parameter map based on the background modeling and fusion weight map, input the quantization parameter map into the H.265 encoder and keep the video metadata unchanged to obtain the compressed video bitstream.

[0040] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0041] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0042] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. An AI video image compression method, characterized in that, include: Decode the surveillance video stream to obtain video metadata and luminance frame sequences; Pixel classification is performed based on the brightness frame sequence to obtain a semantic label map, and an importance weight map is constructed based on the semantic label map; Calculate the static background mask based on the brightness frame sequence, adjust the pixel weight values ​​that belong to both the third-level low-value region and the static background mask, and generate a background modeling fusion weight map. A quantization parameter map is created based on the background modeling and fusion weight map. The quantization parameter map is then input into the H.265 encoder while keeping the video metadata unchanged to obtain the compressed video bitstream.

2. The AI ​​video image compression method according to claim 1, characterized in that, The decoding of the surveillance video stream to obtain video metadata and luminance frame sequences includes: Receive the monitoring video stream, call the video decoding function to decode frame by frame to obtain a video frame sequence in YUV color space format, and extract video metadata synchronously. Extract the Y luminance component of each frame in the video frame sequence, and divide each pixel value of the Y luminance component by the maximum pixel value to obtain the luminance frame sequence.

3. The AI ​​video image compression method according to claim 1, characterized in that, The step of performing pixel classification based on the luminance frame sequence to obtain a semantic label map, and constructing an importance weight map based on the semantic label map, includes: The luminance frame sequence is semantically segmented to output a semantic feature map, and the semantic feature map is then fused with contextual features to output a context-enhanced feature map. Each pixel in the context-enhanced feature map is classified into one of the following categories: sky region, road surface region, road marking region, vehicle body region, license plate region, human body region, human face region, and background vegetation region, and a semantic label map is output. Based on the semantic label graph, values ​​are assigned to different regions to generate an importance weight graph.

4. The AI ​​video image compression method according to claim 3, characterized in that, The step of assigning values ​​to different regions based on the semantic label graph and generating an importance weight graph includes: Traverse the semantic category of each pixel in the semantic label image, and mark the pixels of the face region and license plate region as the first-level high-value region mask, the pixels of the vehicle body region, human body region and road marking region as the second-level medium-value region mask, and the pixels of the sky region and background vegetation region as the third-level low-value region mask. Perform a morphological closing operation on the first-level high-value region mask and a morphological opening operation on the third-level low-value region mask to obtain the target region mask; Each pixel in the target region mask is traversed, and a first weight value is assigned to pixels belonging to the first-level high-value region mask, a second weight value is assigned to pixels belonging to the second-level medium-value region mask, and a third weight value is assigned to pixels belonging to the third-level low-value region mask, thereby generating an importance weight map.

5. The AI ​​video image compression method according to claim 4, characterized in that, The step of calculating a static background mask based on the brightness frame sequence, adjusting the pixel weight values ​​that simultaneously belong to the third-level low-value region and the static background mask, and generating a background modeling fusion weight map includes: Optical flow estimation is performed on the brightness frame sequence and the correlation of all pixel pairs between frames is calculated to obtain the motion vector field; Perform the sum of squares and square root operations on the x-direction motion component and y-direction motion component of each pixel in the motion vector field to generate a motion amplitude map; Set a motion threshold, compare the motion amplitude value of each pixel position in the motion amplitude map of multiple consecutive frames with the motion threshold, and count the number of times each pixel position is stationary when the motion amplitude is lower than the motion threshold in multiple consecutive frames. When the number of static occurrences exceeds a preset threshold, the corresponding pixel is marked as a long-term static pixel, and a static background mask is generated. The weight values ​​of pixels that simultaneously belong to the static background mask and the third-level low-value region mask are adjusted in the importance weight map to obtain the background modeling fusion weight map.

6. The AI ​​video image compression method according to claim 1, characterized in that, The process of creating a quantization parameter map based on the background modeling and weighting map, inputting the quantization parameter map into an H.265 encoder while keeping the video metadata unchanged, to obtain a compressed video bitstream includes: The video frame is divided into several coding units according to the H.265 coding standard, and the average weight value is calculated based on the weight values ​​of all pixels in the background modeling fusion weight map within the coverage area of ​​each coding unit. When the average weight value is greater than or equal to the first threshold, the first level of quantization parameter is assigned; when the average weight value is between the first and second thresholds, the second level of quantization parameter is assigned; when the average weight value is less than the second threshold and the coding unit belongs to the static background mask, the third level of quantization parameter is assigned; when the average weight value is less than the second threshold and the coding unit does not belong to the static background mask, the fourth level of quantization parameter is assigned, and a quantization parameter map is generated. When encoding each encoding unit, the quantization parameter value at the corresponding position is read from the quantization parameter graph and assigned to the quantization parameter variable of the encoding unit, while keeping the video metadata unchanged, to obtain the compressed video bitstream.

7. The AI ​​video image compression method according to claim 6, characterized in that, After assigning the fourth-level quantization parameters, the following is also included: After allocating the fourth-level quantization parameters, an initial parameter map is generated; For each coding unit position in the initial parameter map, the quantization parameter values ​​of the neighboring coding units are extracted, and median filtering is performed based on the quantization parameter values ​​of the neighboring coding units to obtain the filtered parameter map; Traverse each coding unit at the i-th row and j-th column position in the filter parameter graph, calculate the quantization parameter difference between the coding unit and its adjacent coding units at the (i+1)-th row and j-th column, and adjust the quantization parameters of the coding unit based on the quantization parameter difference to obtain the quantization parameter graph.

8. The AI ​​video image compression method according to claim 6, characterized in that, The step of reading the quantization parameter value at the corresponding position from the quantization parameter map and assigning it to the quantization parameter variable of the encoding unit while keeping the video metadata unchanged, to obtain the compressed video bitstream, includes: Create an initial encoder and configure the encoding parameters, then assign the video metadata to the initial encoder to obtain an encoder instance; When processing each encoding unit in the main encoding loop of the encoder instance, the quantization parameter value is read from the corresponding coordinate position of the quantization parameter map according to the row and column coordinates of the encoding unit in the video frame and directly assigned to the quantization parameter variable of the encoding unit; When the coding unit belongs to the first-level high-value region, the skip coding mode is disabled and the coding unit size is limited. When the coding unit belongs to the third-level low-value region, the early termination mechanism is enabled, resulting in an H.265 encoded bitstream. The H.265 encoded bitstream is encapsulated into a video container format, and the timestamp parameter, bitrate parameter, and audio stream parameter are written into the video metadata to generate a compressed video bitstream that retains the video metadata unchanged.

9. The AI ​​video image compression method according to claim 8, characterized in that, The method of disabling skip coding mode and limiting coding unit size when the coding unit belongs to the first-level high-value region, and enabling early termination mechanism when the coding unit belongs to the third-level low-value region, yields an H.265 encoded bitstream, including: When the coding unit belongs to the first-level high-value region, the skip coding mode is disabled in the coding configuration and the maximum size of the coding unit is limited while the intra-frame prediction mode is forced to be used. When the coding unit belongs to the third-level low-value region, the early termination mechanism is enabled and the coding mode is skipped directly when the rate-distortion cost is lower than the preset threshold. Encoding processing is performed sequentially on all coding units in the video frame sequence. Quantization operation with the corresponding quantization step size is performed according to the quantization parameter variable value of each coding unit to obtain the H.265 encoded bitstream.

10. An AI video image compression system, characterized in that, An AI video image compression method for performing any one of claims 1-9 includes: The decoding module is used to decode the surveillance video stream to obtain video metadata and luminance frame sequences; A pixel classification module is used to classify pixels based on the brightness frame sequence, obtain a semantic label map, and construct an importance weight map based on the semantic label map. The background modeling module is used to calculate a static background mask based on the brightness frame sequence, adjust the pixel weight values ​​that belong to both the third-level low-value region and the static background mask, and generate a background modeling fusion weight map. The compression module is used to create a quantization parameter map based on the background modeling and fusion weight map, input the quantization parameter map into the H.265 encoder while keeping the video metadata unchanged, and obtain the compressed video bitstream.