Method and device for calculating video frame quantization parameter offset and video encoder
By identifying the region of interest in the video frame and building an attribute calculation model, and calculating the quantitative parameter offset, the problem of insufficient coding support for the region of interest in the hardware encoder is solved, and the quality of video frame encoding is improved.
Patent Information
- Application Number
- CN202510034028.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-08
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, the encoding of the region of interest is insufficient in the hardware encoder, and the computing model of the region of interest Qp-Delta is complex and difficult to implement in hardware, resulting in poor video frame encoding quality.
By identifying the region of interest in the video frame and dividing the mapping blocks and sub-blocks on it, a texture attribute and motion attribute calculation model is constructed, and the quantitative parameter offsets are calculated using the linear combination of these models to realize the quantitative parameter adjustment of the region of interest and non-interest areas.
It realizes efficient calculation of the quantized parameter offset of the region of interest in the video frame in the hardware encoder, improves the quality of video frame encoding, is suitable for parallel processing in hardware, and has simple calculation logic.
Smart Images

Figure CN119893103A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of video technology, and in particular to a method and device for calculating a video frame quantization parameter offset, and a video encoder. Background Art
[0002] Video frame region of interest coding is a research hotspot based on perceptual coding. Its research direction mainly focuses on two aspects: one is how to extract the region of interest in the video frame, and the other is how to calculate Qp-Delta for the extracted video frame region of interest. Qp-Delta is used to adjust the quantization parameter (Qp) of the coding block. As we all know, the change of Qp has a crucial impact on the quality of video coding, so the accuracy of Qp-Delta calculation directly affects the final quality of video coding.
[0003] Although region of interest coding is a research hotspot in the field of perceptual video coding, its implementation and application in hardware encoders still have many limitations. First, in hardware encoders, there are few hardware implementation modules for video frame region of interest detection and region of interest Qp-Delta, resulting in many manufacturers' encoders on the market not supporting region of interest coding; second, many hardware encoders so-called support for region of interest coding only provide users with interfaces of interest, requiring users to specify the region of interest and the Qp-Delta value of the region of interest by themselves. These input data are uncertain, resulting in the actual video frame encoding quality not meeting expectations.
[0004] At present, the support research of interest coding is mainly concentrated on the implementation level of software algorithms. For example, Tencent has made some improvements to the adaptive quantization (Aq) algorithm based on the HEVC open source library x265, and realized the coding support of interest regions at the Tencent application level; Bigo265 is a software encoder developed based on the HEVC official encoder (HM), and its internally supported interest coding is also at the software level.
[0005] The main problems in the theoretical research on support for region of interest coding are as follows: 1) The region of interest detection model is relatively complex and difficult to implement in hardware; 2) The calculation model of the region of interest Qp-Delta is complex to build. First, it is difficult to implement in the hardware encoder. Second, the constructed model does not comprehensively consider the characteristics of video frame coding, resulting in inaccurate calculation results and difficulty in achieving the expected improvement in video frame coding quality.
[0006] There are three main research aspects of region of interest coding: 1) support for region of interest coding in hardware encoders; 2) research and application of region of interest coding algorithms at the software level; 3) development of region of interest coding in academic research;
[0007] The existing calculation models for Qp-Delta in the region of interest have the following deficiencies in the above three research levels:
[0008] 1. Support in hardware encoder:
[0009] Many hardware encoders on the market do not support region of interest encoding. Hardware encoders that claim to support region of interest encoding only provide users with a region of interest encoding interface. The hardware encoders do not support region of interest detection and hardware calculation of region of interest Qp-Delta. They only allow users to input Qp-Delta values for regions of interest and specified areas. In this case, it is difficult to achieve the encoding quality expected by users.
[0010] 2. Research and application of algorithms at the software level:
[0011] The research and application of algorithms for region of interest coding at the software level are quite extensive, generally mainly in some video players, video clouds or open source encoding libraries. Tencent Cloud implements region of interest detection and Qp-Delta calculation based on the adaptive quantization (Aq) algorithm of the HEVC encoder open source library x265; Bigo265 supports software-level region of interest related coding based on the HEVC official encoder (HM); ffmpeg provides an interface for region of interest coding, and the internal encoding core is still the h264 encoder open source library (lib264) or the hevc encoder open source library (lib265);
[0012] 3. Development in academic research:
[0013] The academic research and development of region of interest coding is mainly focused on theory, and the models constructed are mainly concentrated on the human vision model (HVS), visual sensitivity model, interlaced perception model, etc. This model is not only complex to build and not suitable for hardware implementation, but also has poor accuracy and does not comprehensively consider the characteristics of video frame coding, making it difficult to achieve the expected improvement in video coding quality; Summary of the invention
[0014] One of the purposes of the present invention is to overcome the deficiencies in the prior art and, in view of the above-mentioned technical problems existing in the prior art, provide a method and device for calculating a video frame quantization parameter offset and a video encoder.
[0015] To achieve the above objectives, the present invention is implemented through the following technical solutions:
[0016] In a first aspect, the present invention provides a method for calculating a video frame quantization parameter offset, the calculation method comprising:
[0017] S100: Identify the region of interest of the current video frame;
[0018] S200: Calculate a first quantization parameter offset of the region of interest to obtain a first quantization parameter of the region of interest.
[0019] In a preferred embodiment of the present application, S200 specifically includes:
[0020] S210: Divide the region of interest into a plurality of mapping blocks, and divide each mapping block into a plurality of sub-blocks;
[0021] S220: constructing a texture attribute calculation model for each sub-block in each mapping block in sequence in the region of interest according to a raster scanning order, and obtaining an edge gradient value of each sub-block;
[0022] S230: constructing a motion attribute calculation model for each sub-block in each mapping block in the region of interest in sequence according to a raster scanning order, and obtaining a motion vector gradient value for each sub-block;
[0023] S240: constructing a quantization parameter offset calculation model for the entire mapping block based on a linear combination of the texture attribute model and the motion attribute model, calculating a first quantization parameter offset of the region of interest, and obtaining a first quantization parameter.
[0024] In a preferred embodiment of the present application, S220 specifically includes:
[0025] S221: Obtain pixel values of each pixel block in a single sub-block;
[0026] S222: for a single pixel block, calculating a horizontal gradient value and a vertical gradient value of the single pixel block based on pixel values of all neighboring pixel blocks around the single pixel block;
[0027] S223: adding the absolute values of the horizontal gradient value and the vertical gradient value of the single pixel block to obtain the texture gradient value of the single pixel block;
[0028] S224: Add the texture gradient values of each pixel block to obtain the edge gradient value of the single sub-block.
[0029] In a preferred embodiment of the present application, S230 specifically includes:
[0030] S231: Determine whether the current video frame is an initial frame; if not, execute S232; if so, execute S235;
[0031] S232: based on the position information of the single sub-block in the current video frame, searching for a co-located sub-block with the same position information as the single sub-block in the encoded frame located in the previous frame of the current video frame; if the co-located sub-block exists in the encoded frame, executing S233; if not, executing S235;
[0032] S233: Calculate the motion vector of the single sub-block, and the horizontal and vertical motion vectors of the single sub-block are the horizontal motion vector and vertical motion vector of the sub-block at the same position;
[0033] S234: adding the absolute values of the horizontal motion vector and the vertical motion vector of the single sub-block to obtain a motion vector gradient value of the single sub-block;
[0034] S235: Assign the motion vector gradient value of the single sub-block to 0.
[0035] In a preferred embodiment of the present application, S240 specifically includes:
[0036] S241: obtaining a feature gradient value corresponding to each sub-block based on an edge gradient value and a motion vector gradient value corresponding to each sub-block in the mapping block;
[0037] S242: obtaining an average gradient value of the mapping block based on the number of sub-blocks in the mapping block and the characteristic gradient values corresponding to each sub-block;
[0038] S243: obtaining a first quantization parameter offset of the region of interest based on a maximum characteristic gradient value, a minimum characteristic gradient value and an average gradient value in the mapping block;
[0039] S244: Obtain a first quantization parameter of the region of interest based on the first quantization parameter offset and a preset basic quantization parameter.
[0040] In a preferred embodiment of the present application, the calculation method further includes:
[0041] S300: Calculate the second quantization parameter offset of the non-interest region except the interest region in the current video frame to obtain the second quantization parameter of the non-interest region.
[0042] In a preferred embodiment of the present application, S300 specifically includes:
[0043] S310: Dividing the non-interested region according to the size of the mapping block divided by the interested region;
[0044] S320: Calculate the second quantization parameter offset of the non-interested region in units of mapping blocks to obtain a second quantization parameter.
[0045] In a preferred embodiment of the present application, S320 specifically includes:
[0046] S321: Obtain a left-quantization parameter offset corresponding to a left mapping block and an upper-quantization parameter offset corresponding to an upper mapping block located in an adjacent region of the mapping block;
[0047] S322: Calculate a second quantization parameter offset of the non-interested region based on the left quantization parameter offset and the upper quantization parameter offset;
[0048] S323: Obtain a second quantization parameter of the non-interest region based on the second quantization parameter offset and a preset basic quantization parameter.
[0049] In a second aspect, the present invention provides a device for calculating a video frame quantization parameter offset, comprising an identification module and a first calculation module;
[0050] The identification module is used to identify the region of interest of the video frame;
[0051] The first calculation module is used to calculate a first quantization parameter offset of the region of interest.
[0052] In a preferred embodiment of the present application, the computing device further includes a second computing module, which is used to calculate the second quantization parameter offset of a non-interest region other than the interest region in the video frame to obtain the second quantization parameter of the non-interest region.
[0053] In a third aspect, the present invention provides a video encoder, comprising a preprocessing module and an encoder module, wherein the preprocessing module is provided with a calculation device for the video frame quantization parameter offset as described in the second aspect, and the calculation device and the encoder module can be processed in parallel.
[0054] In a preferred embodiment of the present application, the computing device obtains basic quantization parameters through an external user input interface or a region of interest detection module provided in the pre-processing module.
[0055] In a fourth aspect, the present invention provides a computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, and when the computer-readable storage medium is run on a computer, the computer executes the method for calculating the video frame quantization parameter offset as described in the first aspect.
[0056] In a fifth aspect, the present invention provides a computer program product, which includes a computer program, and when the computer program is run on a computer, it enables the computer to execute the method for calculating the video frame quantization parameter offset as described in the first aspect.
[0057] In the calculation method, device and video encoder of the video frame quantization parameter offset disclosed by the present invention, the calculation method executed by the calculation device is implemented in the preprocessor module of the video encoder and has simple calculation logic. It is parallel to the normal encoding work of the video encoder and will not affect the normal encoding time. It is suitable for implementation in hardware and has high calculation accuracy, which can improve the subjective quality of the encoding of the video frame region of interest to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The present invention is described with the aid of the following drawings:
[0059] Figure 1 is a schematic diagram of a hardware module of a video encoder according to an embodiment of the present invention;
[0060] Figure 2 is a schematic diagram of a module of a device for calculating a video frame quantization parameter offset according to an embodiment of the present invention;
[0061] Figure 3 is a flow chart of a method for calculating a video frame quantization parameter offset according to an embodiment of the present invention;
[0062] Figure 4 is a specific flow chart of S200 in the method for calculating the video frame quantization parameter offset according to an embodiment of the present invention;
[0063] Figure 5 It is a schematic diagram of the relative positions of pixel values of a single pixel block and its adjacent pixel blocks when a sobel operator is used to calculate a texture gradient value of a single pixel block in a method for calculating a video frame quantization parameter offset in an embodiment of the present invention;
[0064] Figure 6 It is a schematic diagram of the position correspondence between a single sub-block in a current video frame and a sub-block at the same position in an encoded frame in a method for calculating a video frame quantization parameter offset according to an embodiment of the present invention;
[0065] Figure 7 is a schematic diagram of a module of a device for calculating a video frame quantization parameter offset according to another embodiment of the present invention;
[0066] Figure 8 The figure is a flow chart of a method for calculating a video frame quantization parameter offset according to another embodiment of the present invention.
[0067] Reference numerals:
[0068] 1- preprocessing module; 2- encoder module; 3- user input interface;
[0069] 10-computing device; 11-identification module; 12-first computing module; 13-second computing module; 20-region of interest detection module;
[0070] 30-sub-block; 31-pixel block. DETAILED DESCRIPTION
[0071] In order to better understand the technical solution of the present application, the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0072] It should be clear that the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0073] The invention discloses a video encoder, which makes an in-depth study on the calculation of the quantization parameter offset Qp-Delta of the region of interest of the video frame, selects a suitable metric standard according to the motion attribute of the video frame motion region and the static attribute of the complex texture region, and calculates the negative quantization parameter offset (-QP-delta) of the region of interest (ROI) of the video frame and the positive quantization parameter offset (+QP-delta) of the non-region of interest (Non-ROI) for adjusting the video frame; wherein, the gradient value of each pixel block of the sub-block (block) calculated by the sobel operator is used to measure the texture attribute of the current video frame (i.e., the frame to be encoded), and the absolute value sum of the motion vector (MV, motion vector) is used to measure the motion attribute of the video frame. wherein, the calculation model of the quantization parameter offset Qp-Delta is generated by the linear combination of the motion attribute and the texture attribute.
[0074] like Figure 1 As shown, an embodiment of the present invention provides a video encoder, including a preprocessing module and an encoder module, wherein the preprocessing module is provided with a video frame quantization parameter offset calculation device, and the calculation device and the encoder module can be processed in parallel. The calculation device can obtain the basic quantization parameter through an external user input interface or an area of interest detection module provided in the preprocessing module.
[0075] Specifically, the overall architecture of the video encoder for region of interest coding mainly includes two modules: one is the preprocessing module, and the other is the encoder module. Among them, the main function of the preprocessing module is to pre-calculate the coding parameters for the encoder module to assist the encoding work of the encoder module, while the function of the encoder module is to perform the normal encoding process of the frame to be encoded: input the current video frame and the encoded frame → inter-frame / intra-frame prediction → transformation → quantization → entropy coding → output the encoded bitstream.
[0076] The calculation module of this embodiment is a hardware module for calculating the quantization parameter offset Qp-Delta, which is implemented in the preprocessing module and can be implemented in parallel with the formal encoder module. Figure 1 As shown, the quantization parameter offset Qp-delta calculation model of the calculation module supports two types of input: one is the output of the region of interest detection module of the preprocessing module, and the data format of the region of interest detection module output is (x, y, width, height); the other is the region of interest interface data input by the user through the user input interface provided by the video encoder, and the data format is (x, y, width, height), mapblockSize. Among them, (x, y) is the pixel coordinate value of the upper left position of the rectangular region of interest, (width, height) is the width and height of the rectangular region of interest, and (x, y, width, height) determines the range of the region of interest. MapblockSize is the size of the map block (mablock), which needs to be entered as an encoding parameter in the encoding execution command line. Its possible values are 8x8, 16x16, 32x32, 64x64, 128x128, and the region of interest needs to be aligned to the map block size (mapblockSize) in the computing device. The mapping block is the smallest unit for calculating the quantization parameter offset Qp-delta. The value of the quantization parameter offset Qp-delta is the same in the same mapping block. The output of the calculation device is mainly used in three submodules of the encoder module: intra / inter prediction module, transform module and quantization module. Among them, in the intra / inter prediction module, it mainly affects the division of coding blocks, prediction blocks, the selection of intra prediction mode, the selection of inter motion vectors, etc.; in the transform module, it mainly affects the division of transform blocks; in the quantization module, it mainly affects the entire quantization process by changing the quantization parameter (Qp).
[0077] like Figure 2 As shown, in one embodiment of the present invention, a device for calculating a quantization parameter offset of a video frame includes an identification module and a first calculation module, wherein the identification module is used to identify a region of interest of a video frame; and the first calculation module is used to calculate a first quantization parameter offset of the region of interest. The quantization parameter offset calculation model of a mapping block of the region of interest is constructed by the first calculation module.
[0078] like Figure 3 As shown, in one embodiment of the present invention, the calculation method performed by the video frame quantization parameter offset calculation device includes:
[0079] S100: Identify the region of interest of the current video frame;
[0080] S200: Calculate a first quantization parameter offset of the region of interest to obtain a first quantization parameter of the region of interest.
[0081] like Figure 4 As shown, in the calculation method, S200 specifically includes:
[0082] S210: Divide the region of interest into a plurality of mapping blocks, and divide each mapping block into a plurality of sub-blocks;
[0083] S220: constructing a texture attribute calculation model for each sub-block in each mapping block in sequence in the region of interest according to the order of raster scanning to obtain an edge gradient value of each sub-block;
[0084] S230: constructing a motion attribute calculation model for each sub-block in each mapping block in sequence in the region of interest according to the order of raster scanning, and obtaining a motion vector gradient value for each sub-block;
[0085] S240: constructing a quantization parameter offset calculation model for the entire mapping block based on a linear combination of the texture attribute model and the motion attribute model, calculating a first quantization parameter offset of the region of interest, and obtaining a first quantization parameter.
[0086] Specifically, the minimum calculation unit of the quantization parameter offset Qp-delta calculation model of this embodiment is a mapping block. Through S210, the region of interest identified in the current video frame is divided into multiple mapping blocks according to the value of the parameter mapblockSize, and then the mapping block is divided into N×N sub-blocks. For ease of understanding and explanation, the present invention will take a 4×4 sub-block as an example.
[0087] Then, S220 is a calculation process of the texture attribute calculation model of the region of interest in the current video frame, which specifically includes:
[0088] S221: Obtain pixel values of each pixel block in a single sub-block;
[0089] S222: for a single pixel block, calculating a horizontal gradient value and a vertical gradient value of the single pixel block based on pixel values of all neighboring pixel blocks around the single pixel block;
[0090] S223: adding the absolute values of the horizontal gradient value and the vertical gradient value of the single pixel block to obtain the texture gradient value of the single pixel block;
[0091] S224: Add the texture gradient values of each pixel block to obtain the edge gradient value of the single sub-block.
[0092] The texture properties of a video frame generally represent the static properties of the video frame. During video playback, the area with complex texture can also attract great attention. The complexity of the texture of a video frame is generally measured based on the properties of the encoded image pixel values. In the texture property calculation model of S220, the texture gradient value of each sub-block in the mapping block is calculated based on the gradient value of the sobel edge detection algorithm. The mapping block with a known input is divided into 4×4 sub-blocks, and the sobel edge gradient value EA of each 4×4 sub-block is calculated. x,y .
[0093] Calculate the sobel edge gradient value EA for each 4×4 sub-block in the mapping block x,y The method is as follows:
[0094] Assuming that pixel(i,j) is the pixel value at position (i,j) in the 4×4 sub-block, the calculation formulas for the horizontal and vertical gradient values in Sobel edge detection are as follows:
[0095]
[0096] Among them, 0≤i,j<4, and Respectively represent the horizontal gradient value and vertical gradient value of pixel (i, j). Then, the texture gradient value of a single pixel block of the sub-block at the (x, y) position can be defined by the following formula:
[0097]
[0098] Then the edge gradient value EA of the 4×4 sub-block at the (x, y) position is x,y is the sum of the texture gradient values of each pixel block:
[0099]
[0100] Among them, the relative positions of each pixel block participating in the calculation of the Sobel gradient value in the sub-block are as follows: Figure 5 shown.
[0101] While executing S220 to calculate the texture attribute of the region of interest of the current video frame, a motion attribute calculation model of the region of interest is also constructed. S230 is the calculation process of the motion attribute calculation model of the region of interest of the current video frame, which specifically includes:
[0102] S231: Determine whether the current video frame is an initial frame; if not, execute S232; if so, execute S235;
[0103] S232: based on the position information of the single sub-block in the current video frame, searching for a co-located sub-block with the same position information as the single sub-block in the encoded frame located in the previous frame of the current video frame; if the co-located sub-block exists in the encoded frame, executing S233; if not, executing S235;
[0104] S233: Calculate the motion vector of the single sub-block, and the horizontal and vertical motion vectors of the single sub-block are the horizontal motion vector and vertical motion vector of the sub-block at the same position;
[0105] S234: adding the absolute values of the horizontal motion vector and the vertical motion vector of the single sub-block to obtain a motion vector gradient value of the single sub-block;
[0106] S235: Assign the motion vector gradient value of the single sub-block to 0.
[0107] The motion properties between frames to be encoded are the key factors for the maximum compression of video coding. Among them, the commonly used measurement indicator of video frame motion properties is the motion vector. In the motion vector gradient (MVA) algorithm proposed in this paper, it is based on the coded frame (f n-1 ) is measured by the sum of the absolute values of the co-located MVs of the co-located sub-blocks with the same position information as the single sub-block of the current video frame. The mapping block is divided into 4×4 sub-blocks, and the motion vector gradient value mv of each 4×4 sub-block is calculated. x,y :
[0108]
[0109] Among them, Figure 6 As shown, the col-located MV refers to the current video frame (f n ) in the coded frame (f n-1 ) corresponds to the motion vector (MV) of the 4×4 sub-block at the corresponding position in ).
[0110] Next, the edge gradient values EA of each sub-block of the mapping block of the region of interest of the current video frame are obtained. x,y and motion vector gradient value mv x,y Afterwards, the texture attribute calculation model and the motion attribute calculation model are linearly combined by the quantization parameter offset Qp-Delta calculation model constructed by the first calculation module. S240 is a calculation process of the quantization parameter offset Qp-Delta calculation model of the first quantization parameter offset of the region of interest of the current video frame, which specifically includes:
[0111] S241: obtaining a feature gradient value corresponding to each sub-block based on an edge gradient value and a motion vector gradient value corresponding to each sub-block in the mapping block;
[0112] S242: obtaining an average gradient value of the mapping block based on the number of sub-blocks in the mapping block and the characteristic gradient values corresponding to each sub-block;
[0113] S243: obtaining a first quantization parameter offset of the region of interest based on a maximum characteristic gradient value, a minimum characteristic gradient value and an average gradient value in the mapping block;
[0114] S244: Obtain a first quantization parameter of the region of interest based on the first quantization parameter offset and a preset basic quantization parameter.
[0115] Specifically, the calculation steps of the first quantization parameter offset of the region of interest are as follows:
[0116] 1. Calculate the gradient value A of the 4×4 sub-block at the (x, y) position in the mapping block x,y :
[0117] A x,y =(1-W t )xEA x,y +W t xmv x,y (6)
[0118] Among them, W t Represents the motion vector gradient value mv x,y The weight, W t = 3 / 8 can get accurate and reliable calculation results. The weight W t The value of will affect the calculation accuracy of the quantization parameter offset Qp-Delta, the test set of different scenarios and encoding requirements, the weight W t The value of can also be set differently and can be determined according to the ratio of motion attributes to texture attributes. The specific value depends on the specific application scenario.
[0119] 2. Calculate the average gradient value of the mapping block
[0120]
[0121] Wherein, N×N represents the number of 4×4 sub-blocks in the mapping block;
[0122] 3. Calculate the value of the quantization parameter offset Qp-delta of the mapping block:
[0123]
[0124] Among them, α is the constraint factor of the quantization parameter offset Qp-delta. The larger the value of α, the larger the adjustment of the quantization parameter offset Qp-delta. The value range of α is (1 to 6). The value of α depends on the needs of the actual application scenario and the encoding scenario. When the value of α is larger (for example, α is 6), the distortion of the current video frame is smaller and the code stream size output by the encoder is larger; when the value of α is smaller (for example, α is 1), the distortion of the current video frame is larger and the code stream size output by the encoder is smaller; when α takes an intermediate value (for example, α takes 3 or 4), the distortion of the current video frame and the code stream size are in a relatively balanced state.
[0125] Among them, the final first quantization parameter Qp of the mapping block in the region of interest is set :
[0126] Q set =Qp base -Δ Qp (9)
[0127] Q base is the initial configuration parameter input by the region of interest detection module or the user input interface, i.e., Qp base It can be set by the user or input through encoding parameters stored in the hardware driver of the video encoder.
[0128] like Figure 7 As shown, in another embodiment of the present invention, the calculation device of the video frame quantization parameter offset also includes a second calculation module, and the second calculation module is used to calculate the second quantization parameter offset of the non-interest area in the video frame except the interest area, and obtain the second quantization parameter of the non-interest area. That is to say, in this other embodiment, the quantization parameter offset Qp-delta calculation model includes two parts: one is the quantization parameter offset Qp-delta calculation model of the interest area; the other is the quantization parameter offset Qp-delta calculation model of the non-interest area. Among them, the quantization parameter offset Qp-delta calculation model of the non-interest area is to solve the problem of bit rate surge caused by the encoding process of the video encoder only adjusting the first quantization parameter Qp of the interest area.
[0129] like Figure 8 As shown, in another embodiment of the present invention, the calculation method performed by the video frame quantization parameter offset calculation device includes:
[0130] S100: Identify the region of interest of the current video frame;
[0131] S200: Calculate a first quantization parameter offset of the region of interest to obtain a first quantization parameter of the region of interest;
[0132] S300: Calculate the second quantization parameter offset of the non-interest region except the interest region in the current video frame to obtain the second quantization parameter of the non-interest region.
[0133] The calculation process of S100 and S200 is as described above and will not be repeated here.
[0134] Among them, S300 specifically includes:
[0135] S310: Divide the non-interest area according to the size of the mapping block divided by the interest area;
[0136] S320: Calculate the second quantization parameter offset of the non-interested area in units of mapping blocks to obtain a second quantization parameter.
[0137] The mapping block division process of S310 is the same as the step S210 of dividing the region of interest, and S320 is the calculation process of the second quantization parameter offset of the non-region of interest of the current video frame, which specifically includes:
[0138] S321: Obtain a left-quantization parameter offset corresponding to a left mapping block and an upper-quantization parameter offset corresponding to an upper mapping block located in an adjacent region of the mapping block;
[0139] S322: Calculate a second quantization parameter offset of the non-interested region based on the left quantization parameter offset and the upper quantization parameter offset;
[0140] S323: Obtain a second quantization parameter of the non-interested region based on the second quantization parameter offset and a preset basic quantization parameter.
[0141] Specifically, only adjusting the first quantization parameter Qp of the region of interest will increase the bit rate of the overall encoding and may not maximize the quality of the encoding. In order to solve this problem, another embodiment of the present invention proposes a quantization parameter offset Qp-delta calculation model for non-ROI. The quantization parameter offset Qp-delta calculation model for non-ROI is an upper-quantization parameter offset Δ calculated based on the top-map block and the left-map block in the adjacent area of a single mapping block. Qp-top and left - quantization parameter offset Δ Qp-left A coarse-grained second quantization parameter offset Δ is obtained by linear calculation Qp-Non-ROI .
[0142] The calculation steps of the second quantization parameter offset Qp-delta of the non-ROI are as follows:
[0143] 1. Divide the non-interest area according to the mapping block size;
[0144] 2. Calculate the second quantization parameter offset Qp-deltaΔ of the non-interested area in units of mapping blocks Qp-Non-ROI :
[0145]
[0146] Among them, the second quantization parameter Qp of the mapping block of the non-interest area is set-non-roi :
[0147] Q set-non-roi =Qp base +Δ Qp-Non-ROI (11)
[0148] Another embodiment of the present invention discloses a computer-readable storage medium, in which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer executes a method for calculating a video frame quantization parameter offset.
[0149] Another embodiment of the present invention discloses a computer program product. The computer program product includes a computer program. When the computer program product is run on a computer, the computer executes a method for calculating a video frame quantization parameter offset.
[0150] The present invention discloses a method, device and video encoder for calculating the quantization parameter offset of a video frame. The calculation method performed by the calculation device is implemented in a preprocessing module of the video encoder and has simple calculation logic. It is parallel to the normal encoding work of the video encoder and does not affect the normal encoding time. It is suitable for implementation in hardware and has high calculation accuracy, which can improve the subjective quality of encoding of the region of interest of the video frame to a certain extent.
[0151] It should be understood that the above description of the specific embodiments of the present invention is only for illustrating the technical route and features of the present invention, and its purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly, but the present invention is not limited to the above specific implementation methods. Any changes or modifications made within the scope of the claims of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for calculating a video frame quantization parameter offset, characterized in that: The calculation method includes: S100: Identify the region of interest of the current video frame; S200: Calculate a first quantization parameter offset of the region of interest to obtain a first quantization parameter of the region of interest.
2. The method for calculating the video frame quantization parameter offset according to claim 1, characterized in that: S200 specifically includes: S210: Divide the region of interest into a plurality of mapping blocks, and divide each mapping block into a plurality of sub-blocks; S220: constructing a texture attribute calculation model for each sub-block in each mapping block in sequence in the region of interest according to a raster scanning order, and obtaining an edge gradient value of each sub-block; S230: constructing a motion attribute calculation model for each sub-block in each mapping block in the region of interest in sequence according to a raster scanning order, and obtaining a motion vector gradient value for each sub-block; S240: constructing a quantization parameter offset calculation model for the entire mapping block based on a linear combination of the texture attribute model and the motion attribute model, calculating a first quantization parameter offset of the region of interest, and obtaining a first quantization parameter.
3. The method for calculating the video frame quantization parameter offset according to claim 2, characterized in that: S220 specifically includes: S221: Obtain pixel values of each pixel block in a single sub-block; S222: for a single pixel block, calculating a horizontal gradient value and a vertical gradient value of the single pixel block based on pixel values of all neighboring pixel blocks around the single pixel block; S223: adding the absolute values of the horizontal gradient value and the vertical gradient value of the single pixel block to obtain the texture gradient value of the single pixel block; S224: Add the texture gradient values of each pixel block to obtain the edge gradient value of the single sub-block.
4. The method for calculating the video frame quantization parameter offset according to claim 2, characterized in that: S230 specifically includes: S231: Determine whether the current video frame is an initial frame; if not, execute S232; if so, execute S235; S232: based on the position information of the single sub-block in the current video frame, searching for a co-located sub-block with the same position information as the single sub-block in the encoded frame located in the previous frame of the current video frame; if the co-located sub-block exists in the encoded frame, executing S233; if not, executing S235; S233: Calculate the motion vector of the single sub-block, and the horizontal and vertical motion vectors of the single sub-block are the horizontal motion vector and vertical motion vector of the sub-block at the same position; S234: adding the absolute values of the horizontal motion vector and the vertical motion vector of the single sub-block to obtain a motion vector gradient value of the single sub-block; S235: Assign the motion vector gradient value of the single sub-block to 0.
5. The method for calculating the video frame quantization parameter offset according to claim 2, characterized in that: S240 specifically includes: S241: obtaining a feature gradient value corresponding to each sub-block based on an edge gradient value and a motion vector gradient value corresponding to each sub-block in the mapping block; S242: obtaining an average gradient value of the mapping block based on the number of sub-blocks in the mapping block and the characteristic gradient values corresponding to each sub-block; S243: obtaining a first quantization parameter offset of the region of interest based on a maximum characteristic gradient value, a minimum characteristic gradient value and an average gradient value in the mapping block; S244: Obtain a first quantization parameter of the region of interest based on the first quantization parameter offset and a preset basic quantization parameter.
6. The method for calculating the video frame quantization parameter offset according to claim 1, characterized in that: The calculation method further includes: S300: calculating the second quantization parameter offset of the non-interest region except the interest region in the current video frame to obtain the second quantization parameter of the non-interest region.
7. The method for calculating the video frame quantization parameter offset according to claim 6, characterized in that: S300 specifically includes: S310: Dividing the non-interested region according to the size of the mapping block divided by the interested region; S320: Calculate the second quantization parameter offset of the non-interested region in units of mapping blocks to obtain a second quantization parameter.
8. The method for calculating the video frame quantization parameter offset according to claim 6, characterized in that: S320 specifically includes: S321: Obtain a left-quantization parameter offset corresponding to a left mapping block and an upper-quantization parameter offset corresponding to an upper mapping block located in an adjacent region of the mapping block; S322: Calculate a second quantization parameter offset of the non-interested region based on the left quantization parameter offset and the upper quantization parameter offset; S323: Obtain a second quantization parameter of the non-interest region based on the second quantization parameter offset and a preset basic quantization parameter.
9. A device for calculating a video frame quantization parameter offset, characterized in that: comprising an identification module and a first calculation module; The identification module is used to identify the region of interest of the video frame; The first calculation module is used to calculate a first quantization parameter offset of the region of interest.
10. The device for calculating the video frame quantization parameter offset according to claim 9, characterized in that: The method further comprises a second calculation module, wherein the second calculation module is used to calculate a second quantization parameter offset of a non-interest region except the interest region in the video frame to obtain a second quantization parameter of the non-interest region.
11. A video encoder, characterized in that: It comprises a preprocessing module and an encoder module, wherein the preprocessing module is provided with a video frame quantization parameter offset calculation device as claimed in claim 9 or 10, and the calculation device and the encoder module can be processed in parallel.
12. The video encoder according to claim 11, characterized in that The computing device obtains basic quantization parameters through an external user input interface or a region of interest detection module disposed in the preprocessing module.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed on a computer, enables the computer to execute the method for calculating the video frame quantization parameter offset as claimed in any one of claims 1 to 8.
14. A computer program product, characterized in that The computer program product comprises a computer program, which, when executed on a computer, enables the computer to execute the method for calculating the video frame quantization parameter offset according to any one of claims 1 to 8.