Video encoding method and device, storage medium, and electronic device
By using the coding hierarchical structure to adjust the CRF and QP values of each frame in video encoding, the problem of distortion diffusion caused by frame rate changes in constant visual quality mode is solved, and the encoding efficiency and video quality are improved.
Patent Information
- Application Number
- CN202011017864.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-24
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2040-09-24
AI Technical Summary
In constant visual quality mode, existing video coding technology ignores the different frame reference relationships at different levels caused by the coding hierarchical structure, resulting in the spread of low-level frame distortion and reduced coding efficiency.
By obtaining the coding hierarchical structure and fixed code rate coefficient CRF value of the source video, the target quantization parameter QP value is calculated, the CRF value and QP value of each frame are adjusted, and constant visual quality encoding is performed based on the target QP value to avoid distortion diffusion.
It improves the coding performance and coding efficiency of CRF mode, ensures stable visual quality and high bit rate of low-layer frames, and reduces video storage space and decoding volume.
Smart Images

Figure CN112165620B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of video encoding, and in particular to a video encoding method and device, a storage medium, and an electronic device. Background Art
[0002] Related technologies When performing video encoding, it refers to the method of converting the original video format file into another video format file through compression technology. Common codec standards in video streaming transmission include H.264, H.265, AVS, AV1, etc.
[0003] Related technologies include various bit rate control methods in video encoding, including CBR (Constant BitRate) mode with constant bit rate and CRF (Constant Rate Factor) mode with constant visual quality. Each bit rate control method ultimately achieves the bit rate control effect by changing the QP value of each frame. Among them, the CRF mode uses the input CRF value as the benchmark QP (Quant parameter), and adjusts the actual QP value of each frame according to the complexity and motion information of the image to stabilize the output visual quality. For scenes with intense motion or complex scenes, the distortion is relatively difficult to be detected by the naked eye, so the QP can be increased to save bit rate; for flat areas that are sensitive to the human eye, smaller distortions are more easily detected, so the QP needs to be reduced to reduce distortion.
[0004] In the CRF mode of the related technology, the CRF value of each frame is constant, and QP is allocated only based on the complexity information of the image, while ignoring the different frame reference relationships at different levels caused by the coding hierarchical structure. Once the low-level frame is distorted, the high-level frame encoded with reference to the frame will also be further distorted, which can easily lead to distortion of the underlying frame and spread of distortion, thereby reducing the coding efficiency.
[0005] With respect to the above-mentioned problems existing in the related technologies, no effective solutions have been found so far. Summary of the invention
[0006] The embodiments of the present invention provide a video encoding method and device, a storage medium, and an electronic device.
[0007] According to one aspect of an embodiment of the present application, a video encoding method is provided, comprising: obtaining a source fixed rate coefficient CRF value of a source video; calculating a target quantization parameter QP value of the source video according to a coding hierarchy structure of the source video and the source CRF value, wherein the coding hierarchy structure is used to characterize the encoding reference relationship of image frames in a group of pictures GOP of the source video; and performing constant visual quality encoding on the source video based on the target QP value.
[0008] Further, calculating the target quantization parameter QP value of the source video according to the coding hierarchy structure of the source video and the source CRF value includes: adjusting the source CRF value according to the coding hierarchy structure of the source video to obtain a target CRF value; and calculating a target QP value according to the target CRF value.
[0009] Further, the source CRF value is adjusted according to the coding hierarchy structure of the source video to obtain a target CRF value, including: taking the GOP of the source video as a unit, dividing the GOP where the current frame is located into multiple coding layers according to the logical order of the reference frame, wherein each coding layer includes at least one image frame; assigning an adjustment algorithm to the image frame of each coding layer in a preset library; and using the adjustment algorithm to adjust the source CRF value of each frame of the image in the GOP to obtain a target CRF value.
[0010] Further, the source CRF value of each frame image in the GOP is adjusted by using the adjustment algorithm to obtain a target CRF value, including: determining the coding layer where the current frame is located; calculating the source CRF value of each frame image in the GOP by using the following formula to obtain a target CRF value: crf frame =crf+delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0011] Further, the source CRF value of each frame image in the GOP is adjusted by using the adjustment algorithm to obtain a target CRF value, including: determining the coding layer where the current frame is located; calculating the source CRF value of each frame image in the GOP by using the following formula to obtain a target CRF value: crf frame =crf*delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0012] Further, calculating the target QP value according to the target CRF value includes: calculating the base complexity Cplx_base and the actual complexity Cplx_frame of the source video; and calculating the basic intermediate result by the following formula: Qscale base =0.85×2 (目标CRF值-12) / 6 ; The actual intermediate result is calculated by the following formula: The QP value is calculated by the following formula: QP frame =12+6×log2(Qscale frame / 0.85); where Qscale base For the basic intermediate result, Qscale frame is the actual intermediate result, QP frame is the target QP value, and b is a first preset value.
[0013] Further, calculating the target quantization parameter QP value of the source video according to the coding hierarchy structure of the source video and the source CRF value includes: calculating a source QP value according to the source CRF value; and adjusting the source QP value according to the coding hierarchy structure of the source video to obtain a target QP value.
[0014] Further, the source QP value is adjusted according to the coding hierarchy structure of the source video to obtain a target QP value, including: taking the GOP of the source video as a unit, dividing the GOP where the current frame is located into multiple coding layers according to the number of reference frames, wherein each coding layer includes at least one image frame; assigning an adjustment algorithm to the image frame of each coding layer; and using the adjustment algorithm to adjust the source QP value of each frame of the image in the GOP to obtain a target QP value.
[0015] Further, performing constant visual quality encoding on the source video based on the target QP value includes: extracting an original image frame corresponding to the target QP value from the source video; and deleting a corresponding amount of image information in a pixel macroblock of the original image frame based on the target QP value to obtain an encoded image frame.
[0016] According to another aspect of an embodiment of the present application, a video encoding device is also provided, including: an acquisition module for acquiring a source fixed rate coefficient CRF value of a source video; a calculation module for calculating a target quantization parameter QP value of the source video based on a coding hierarchy structure of the source video and the source CRF value, wherein the coding hierarchy structure is used to characterize the encoding reference relationship of image frames in a picture group GOP of the source video; and an encoding module for performing constant visual quality encoding on the source video based on the target QP value.
[0017] Furthermore, the calculation module includes: a first adjustment unit, used to adjust the source CRF value according to the coding hierarchy structure of the source video to obtain a target CRF value; and a first calculation unit, used to calculate a target QP value according to the target CRF value.
[0018] Furthermore, the first adjustment unit includes: a division subunit, which is used to divide the GOP where the current frame is located into multiple coding layers according to the logical order of reference frames, taking the GOP of the source video as a unit, wherein each coding layer includes at least one image frame; an allocation subunit, which is used to allocate an adjustment algorithm to the image frame of each coding layer in a preset library; and an adjustment subunit, which is used to use the adjustment algorithm to adjust the source CRF value of each frame of the image in the GOP to obtain a target CRF value.
[0019] Furthermore, the adjustment subunit is further used to: determine the coding layer where the current frame is located; calculate the source CRF value of each frame image in the GOP using the following formula to obtain the target CRF value: crf frame =crf+delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0020] Furthermore, the adjustment subunit is further used to: determine the coding layer where the current frame is located; calculate the source CRF value of each frame image in the GOP using the following formula to obtain the target CRF value: crf frame =crf*delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0021] Furthermore, the first calculation unit includes: a first calculation subunit, used to calculate the basic complexity Cplx_base and the actual complexity Cplx_frame of the source video; a second calculation subunit, used to calculate the basic intermediate result by the following formula: Qscale base =0.85×2 (目标CRF值-12) / 6 ; The third calculation subunit is used to calculate the actual intermediate result by the following formula: The fourth calculation subunit is used to calculate the QP value by the following formula: QP frame =12+6×log2(Qscale frame / 0.85); where Qscale base For the basic intermediate result, Qscale frame is the actual intermediate result, QP frame is the target QP value, and b is a first preset value.
[0022] Furthermore, the calculation module includes: a second calculation unit, used to calculate a source QP value according to the source CRF value; and a second adjustment unit, used to adjust the source QP value according to the coding hierarchy structure of the source video to obtain a target QP value.
[0023] Furthermore, the second adjustment unit includes: a division subunit, which is used to divide the GOP where the current frame is located into multiple coding layers according to the logical order of reference frames, taking the GOP of the source video as a unit, wherein each coding layer includes at least one image frame; an allocation subunit, which is used to allocate an adjustment algorithm to the image frame of each coding layer; and an adjustment subunit, which is used to use the adjustment algorithm to adjust the source QP value of each frame of the image in the GOP to obtain a target QP value.
[0024] Furthermore, the encoding module includes: an extraction unit, used to extract the original image frame corresponding to the target QP value from the source video; and an encoding unit, used to delete a corresponding amount of image information in the pixel macroblock of the original image frame based on the target QP value to obtain an encoded image frame.
[0025] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above steps are executed when the program is run.
[0026] According to another aspect of an embodiment of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein: the memory is used to store computer programs; and the processor is used to execute the steps in the above method by running the program stored in the memory.
[0027] The embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the steps in the above method.
[0028] Through the present invention, the source fixed bit rate coefficient CRF value of the source video is obtained, and then the target quantization parameter QP value of the source video is calculated according to the coding hierarchy structure of the source video and the source CRF value. Finally, the source video is encoded with constant visual quality based on the target QP value to avoid picture distortion caused by frame rate changes in the constant visual quality mode, solves the technical problem that high-level frames of the video GOP in the related technology are easily distorted, and can improve the encoding performance and encoding efficiency of the CRF mode. For the low-level frames in the GOP, more stable visual quality and higher bit rate can be guaranteed, and high-level frame distortion caused by the distortion of the low-level frames can be avoided. In addition, for the high-level frames in the GOP, the QP value is increased while ensuring the video quality, so as to further reduce the storage space of the video, increase the transmission amount of the video, and reduce the decoding amount. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0030] Figure 1 is a hardware structure block diagram of a server according to an embodiment of the present invention;
[0031] Figure 2 is a flowchart of a video encoding method according to an embodiment of the present invention;
[0032] Figure 3 Schematic diagram of the hierarchical structure of intra-GOP coding in an embodiment of the present invention;
[0033] Figure 4 is a coding flow chart of an embodiment of the present invention;
[0034] Figure 5 is a structural block diagram of a video encoding device according to an embodiment of the present invention;
[0035] Figure 6 It is a structural block diagram of an electronic device implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0037] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0038] Example 1
[0039] The method embodiment provided in the first embodiment of the present application can be executed in a server, a computer, an imaging device, a mobile phone, a tablet or a similar computing device. Taking running on a server as an example, Figure 1 FIG. 1 is a hardware structure diagram of a server according to an embodiment of the present invention. Figure 1 As shown, the server 10 may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Optionally, the server may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0040] The memory 104 can be used to store server programs, for example, software programs and modules of application software, such as a server program corresponding to a video encoding method in an embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the server program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0041] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0042] In this embodiment, a video encoding method is provided. Figure 2is a flowchart of a video encoding method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0043] Step S202, obtaining a source fixed rate factor CRF value of the source video;
[0044] In the constant visual quality (CRF) encoding mode, the CRF value is related to the bit rate and affects the QP (Quant parameter) value in the encoding parameters. The bit rate is the number of data bits transmitted per unit time during data transmission, and the bit rate per second of the encoded video. The bit rate is also called the sampling rate. The higher the sampling rate per unit time, the higher the accuracy, and the closer the processed file is to the original file. The bit rate affects the distortion of the video. The higher the bit rate, the clearer it is. On the contrary, the picture is rough and mosaic.
[0045] Step S204, calculating a target quantization parameter QP value of the source video according to a coding hierarchy structure of the source video and a source CRF value, wherein the coding hierarchy structure is used to characterize a coding reference relationship of image frames in a group of pictures GOP of the source video;
[0046] The GOP (group of pictures) of this embodiment is a group of continuous pictures in a group of coded video streams in video coding. A GOP is composed of the following different types of frames: I frame (intra-coded frame), P frame (predictive coded frame), B frame (bidirectional predictive coded frame). The coding hierarchical structure is that the encoder layers the frames in the GOP according to the reference relationship of the image frames. The high-level frames will refer to the low-level frames for coding, and the highest-level frames will not be referenced by other frames.
[0047] Step S206: performing constant visual quality encoding on the source video based on the target QP value.
[0048] In the coding mode of constant visual quality, due to the hierarchical structure of coding, the reference relationships of frames at different levels are different. The adjusted QP value is used for encoding, and different QP values are assigned to frames at different levels. The lower the level of the frame, the more references it has. The distortion of the lower level frames needs to be reduced to avoid distortion diffusion and reduced coding efficiency. Through adjustment, the QP of the bottom layer frames is relatively the smallest; and the top layer frames will not be referenced by other frames, so the tolerance for their distortion is relatively higher. Through adjustment, the QP of the highest layer frames is relatively the largest.
[0049] Through the above steps, the source fixed bit rate coefficient CRF value of the source video is obtained, and then the target quantization parameter QP value of the source video is calculated according to the coding hierarchy structure of the source video and the source CRF value. Finally, the source video is encoded with constant visual quality based on the target QP value to avoid picture distortion caused by frame rate changes in the constant visual quality mode, which solves the technical problem that high-level frames of the video GOP are easily distorted in the related technology, and can improve the encoding performance and encoding efficiency of the CRF mode. For the low-level frames in the GOP, more stable visual quality and higher bit rate can be guaranteed, and high-level frame distortion caused by low-level frame distortion can be avoided. In addition, for the high-level frames in the GOP, while ensuring the video quality, the QP value is increased to further reduce the storage space of the video, increase the video transmission volume, and reduce the decoding volume.
[0050] In this embodiment, based on the coding hierarchy structure of the source video and the input basic CRF value (source CRF value), the final QP value can be calculated in a variety of ways, such as first adjusting the source CRF value through the coding hierarchy structure, and then calculating the final QP value through the adjusted CRF value, or first calculating the QP value through the source CRF value, and then adjusting the QP value using the coding hierarchy structure. The same technical effect can be achieved, so that the video can reduce the distortion rate of the picture frame and maintain the stability of the picture in the coding mode of constant visual quality (CRF).
[0051] In one implementation of this embodiment, calculating the target quantization parameter QP value of the source video according to the coding hierarchy structure of the source video and the source CRF value includes:
[0052] S11, adjusting the source CRF value according to the coding hierarchy structure of the source video to obtain a target CRF value;
[0053] In one example of the present implementation, the source CRF value is adjusted according to the coding hierarchical structure of the source video to obtain the target CRF value, including: taking the GOP of the source video as a unit, dividing the GOP where the current frame is located into multiple coding layers according to the logical order of the reference frame, wherein each coding layer includes at least one image frame; assigning an adjustment algorithm to the image frame of each coding layer in a preset library; and adjusting the source CRF value of each frame of the image in the GOP using the adjustment algorithm to obtain the target CRF value. In other examples, the hierarchical structure of each GOP in the source video and the coding frame where each frame of the image is located have been preset before encoding, and the coding layer where the frame is located can be determined by reading the coding layer identifier of each frame of the image.
[0054] In one example, a GOP includes 16 frames. Figure 3 Schematic diagram of the hierarchical structure of the coding in GOP in the embodiment of the present invention. The 16 frames contained in a GOP are divided into 5 coding layers, which are 01234 layers from the bottom to the top. The reference logical relationship between the frames is Figure 3 The arrows in correspondence, such as frame 0 is the reference frame of frames 1, 2, and 4, frame 4 refers to frames 0 and 8 during encoding, and is also the reference frame of frames 2, 3, 5, and 6. Among them, the bottom layer (layer 0: frames 0 and 16) does not need to refer to other frames during encoding, but is only referenced by other frames. Therefore, it is necessary to ensure that its distortion is minimal and the allocated QP is minimal; the frames in the top layer (layer 4: frames 1, 3, ..., 15) are not referenced by other frames at all, so relatively speaking, their distortion is allowed to be larger, and the QP of these frames is also the largest.
[0055] In one example, the source CRF value of each frame image in the GOP is adjusted by using an adjustment algorithm to obtain a target CRF value, including: determining the coding layer where the current frame is located; calculating the source CRF value of each frame image in the GOP by using the following formula to obtain the target CRF value: crf frame =crf+delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is the offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0056] For example, the corresponding relationship between the level and the offset delta is: {0th layer: -1, 1st layer: 0, 2nd layer: 1, 3rd / 4th / ... / top layer: 2}. The higher the level of the coding layer, the larger the offset, and the larger the adjusted target CRF value.
[0057] In another example, the source CRF value of each frame image in the GOP is adjusted by using an adjustment algorithm to obtain a target CRF value, including: determining the coding layer where the current frame is located; calculating the source CRF value of each frame image in the GOP by using the following formula to obtain the target CRF value: crf frame =crf*delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is the offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0058] For example, the correspondence between the level and the offset coefficient delta_level is: {0th layer: 0.95, 1st layer: 1, 2nd layer: 1.05, 3rd / 4th / ... / nth layer: 1.1}, etc. The higher the level of the coding layer, the larger the offset coefficient, and the larger the adjusted target CRF value.
[0059] S12, calculating a target QP value according to the target CRF value.
[0060] In an example of this implementation, calculating the target QP value according to the target CRF value includes:
[0061] Calculate the base complexity Cplx_base and actual complexity Cplx_frame of the source video;
[0062] The basic intermediate result is calculated by the following formula: Qscale base =0.85×2 (目标CRF值-12) / 6 ;
[0063] The actual intermediate result is calculated by the following formula:
[0064] The QP value is calculated by the following formula: QP frame =12+6×log2(Qscale frame / 0.85);
[0065] Among them, Qscale base As the basic intermediate result, Qscale frame is the actual intermediate result, QP frame is the target QP value, b is the first preset value, which can be 0.6, 0.5, etc.
[0066] In another implementation of this embodiment, calculating the target quantization parameter QP value of the source video according to the coding hierarchy structure and the source CRF value of the source video includes: calculating the source QP value according to the source CRF value; adjusting the source QP value according to the coding hierarchy structure of the source video to obtain the target QP value.
[0067] Based on the above implementation, the source QP value is adjusted according to the coding hierarchy structure of the source video to obtain the target QP value, including: taking the GOP of the source video as a unit, dividing the GOP where the current frame is located into multiple coding layers according to the logical order of the reference frames, wherein each coding layer includes at least one image frame; assigning an adjustment algorithm to the image frame of each coding layer; and using the adjustment algorithm to adjust the source QP value of each frame of the image in the GOP to obtain the target QP value.
[0068] In this embodiment, when the source QP value of each frame image in the GOP is adjusted by the adjustment algorithm, similar to the use of the adjustment algorithm in the above-mentioned implementation mode to adjust the source CRF value of each frame image in the GOP, the coding layer of each frame in the GOP is first determined. The higher the level of the coding layer, the larger the offset or offset coefficient, and the larger the adjusted target QP value is based on the source QP value.
[0069] Optionally, performing constant visual quality encoding on the source video based on the target QP value includes: extracting an original image frame corresponding to the target QP value from the source video; and deleting a corresponding amount of image information in a pixel macroblock of the original image frame based on the target QP value to obtain an encoded image frame.
[0070] In a specific implementation scenario of this embodiment, a CRF mode encoding method combined with a coding hierarchical structure is proposed: first, the CRF value of each frame is adjusted using the coding hierarchical structure, and then the QP allocation of each frame image is determined in combination with the image information. According to the hierarchical structure within each GOP, the basic CRF value of each frame image is adjusted; (2) for the adjusted basic CRF value, the QP value of each frame encoding is allocated according to the image complexity of each frame. Figure 4 is a coding flow chart of an embodiment of the present invention, such as Figure 4 As shown, the following steps are included:
[0071] Step 1: Adjust the CRF value of each frame according to the coding hierarchical structure;
[0072] like Figure 3 As shown in the figure, it is a hierarchical structure encoded within a GOP, and the 16 frames in a GOP are divided into 5 layers. Usually, the bottom layer (layer 0: frames 0 and 16) is referenced the most by other reference frames, so its distortion must be minimized, so the allocated QP is the smallest; and the frames in the top layer (layer 4: frames 1, 3, ..., 15) are not referenced by other frames at all, so relatively speaking, their distortion is allowed to be larger, and the QP of these frames is also the largest.
[0073] In CRF mode, the input basic CRF value is adjusted according to the hierarchical structure of each frame so that each frame has its own CRF value. The specific adjustment methods include:
[0074] Determine the level of the current frame;
[0075] The CRF value of the current frame is adjusted to the input CRF value plus the offset corresponding to the current layer, as follows:
[0076] crf frame =crf+delta level ;
[0077] The corresponding relationship between the level and the offset delta is: {0th layer: -1, 1st layer: 0, 2nd layer: 1, 3rd / 4th / ... / nth layer: 2}.
[0078] The specific corresponding values of the level and the CRF offset do not need to be exactly the same as the values set in this implementation scenario, and other values can also achieve similar effects. Furthermore, the operation of adding the offset can be changed to the operation of multiplying the offset coefficient. For example, crf_frame = crf*delta_level, and the offset coefficient delta_level can be, for example, {0th layer: 0.95, 1st layer: 1, 2nd layer: 1.05, 3rd / 4th / ... / nth layer: 1.1}, etc.
[0079] From the above correspondence, it can be seen that the range of delta values has upper and lower limits, which are set to [-1, 2] in this implementation scenario. It should be noted that the CRF value can be a decimal or an integer, so each delta value can also be a decimal.
[0080] Step 2: Calculate the QP of each frame using the adjusted CRF value and encode it.
[0081] Step 1 determines the CRF value of each frame. In step 2, the QP value used for encoding each frame is calculated based on the complexity of each frame, and then the actual encoding begins. The specific formula for calculating QP from the CRF value is as follows:
[0082]
[0083]
[0084] QP frame =12+6×log2(Qscale' frame / 0.85);
[0085] Among them, crf_frame is the crf value of each frame adjusted in step 1, Qscale is the intermediate result of the calculation, Cplx_base is the basic complexity (an empirical value related to the resolution), Cplx_frame is the actual complexity of each frame, Qscale' is the Qscale after considering the complexity of the image, and QP_frame is the final encoding QP of each frame. From the formula, we can see that the larger the CRF value of a frame, the larger the Qscale, and the larger the Qscale'; or the higher the complexity of a frame, the larger the Qscale'; and finally the QP of the frame will also be larger, that is, the greater the encoding distortion, the lower the encoding bit rate.
[0086] The solution of this embodiment introduces the QP allocation concept of the coding hierarchy structure into the CRF coding mode, and comprehensively utilizes the coding hierarchy structure and image complexity information to allocate the QP of each frame, thereby further improving the coding performance.
[0087] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0088] Example 2
[0089] In this embodiment, a video encoding device is also provided to implement the above-mentioned embodiments and preferred implementation modes, which have been described and will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0090] Figure 5 is a structural block diagram of a video encoding device according to an embodiment of the present invention. Figure 5 As shown, the device includes: an acquisition module 50, a calculation module 52, and an encoding module 54, wherein:
[0091] An acquisition module 50 is used to acquire a source fixed rate factor CRF value of a source video;
[0092] A calculation module 52, configured to calculate a target quantization parameter QP value of the source video according to a coding hierarchy structure of the source video and the source CRF value, wherein the coding hierarchy structure is used to characterize a coding reference relationship of image frames in a group of pictures GOP of the source video;
[0093] The encoding module 54 is configured to perform constant visual quality encoding on the source video based on the target QP value.
[0094] Optionally, the calculation module includes: a first adjustment unit, used to adjust the source CRF value according to the encoding hierarchy structure of the source video to obtain a target CRF value; and a first calculation unit, used to calculate a target QP value according to the target CRF value.
[0095] Optionally, the first adjustment unit includes: a division subunit, used to divide the GOP of the source video into multiple coding layers according to the logical order of reference frames, wherein each coding layer includes at least one image frame; an allocation subunit, used to allocate an adjustment algorithm to the image frame of each coding layer in a preset library; and an adjustment subunit, used to adjust the source CRF value of each frame of the image in the GOP using the adjustment algorithm to obtain a target CRF value.
[0096] Optionally, the adjustment subunit is further used to: determine the coding layer where the current frame is located; calculate the source CRF value of each frame image in the GOP using the following formula to obtain the target CRF value: crf frame =crf+delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0097] Optionally, the adjustment subunit is further used to: determine the coding layer where the current frame is located; calculate the source CRF value of each frame image in the GOP using the following formula to obtain the target CRF value: crf frame =crf*delta level ; Among them, crf frame is the target CRF value, crf is the source CRF value, delta level is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
[0098] Optionally, the first calculation unit includes: a first calculation subunit, used to calculate the basic complexity Cplx_base and the actual complexity Cplx_frame of the source video; a second calculation subunit, used to calculate the basic intermediate result by the following formula: Qscale base =0.85×2 (目标CRF值-12) / 6 ; The third calculation subunit is used to calculate the actual intermediate result by the following formula: The fourth calculation subunit is used to calculate the QP value by the following formula: QP frame =12+6×log2(Qscale frame / 0.85); where Qscale base For the basic intermediate result, Qscale frame is the actual intermediate result, QP frame is the target QP value, and b is a first preset value.
[0099] Optionally, the calculation module includes: a second calculation unit, used to calculate a source QP value according to the source CRF value; and a second adjustment unit, used to adjust the source QP value according to the encoding hierarchy structure of the source video to obtain a target QP value.
[0100] Optionally, the second adjustment unit includes: a division subunit, used to divide the GOP where the current frame is located into multiple coding layers according to the logical order of reference frames, taking the GOP of the source video as a unit, wherein each coding layer includes at least one image frame; an allocation subunit, used to assign an adjustment algorithm to the image frame of each coding layer; and an adjustment subunit, used to use the adjustment algorithm to adjust the source QP value of each frame of the image in the GOP to obtain a target QP value.
[0101] Optionally, the encoding module includes: an extraction unit, used to extract the original image frame corresponding to the target QP value from the source video; and an encoding unit, used to delete a corresponding amount of image information in a pixel macroblock of the original image frame based on the target QP value to obtain an encoded image frame.
[0102] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0103] Example 3
[0104] An embodiment of the present invention further provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0105] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0106] S1, obtain the source fixed rate factor CRF value of the source video;
[0107] S2, calculating a target quantization parameter QP value of the source video according to a coding hierarchy structure of the source video and the source CRF value, wherein the coding hierarchy structure is used to characterize a coding reference relationship of image frames in a group of pictures GOP of the source video;
[0108] S3, performing constant visual quality encoding on the source video based on the target QP value.
[0109] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0110] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0111] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0112] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0113] S1, obtain the source fixed rate factor CRF value of the source video;
[0114] S2, calculating a target quantization parameter QP value of the source video according to a coding hierarchy structure of the source video and the source CRF value, wherein the coding hierarchy structure is used to characterize a coding reference relationship of image frames in a group of pictures GOP of the source video;
[0115] S3, performing constant visual quality encoding on the source video based on the target QP value.
[0116] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0117] Figure 6 1 is a block diagram of an electronic device implementing an embodiment of the present invention. Figure 6 As shown, it includes a processor 41 and a memory 42 for storing data, which are connected via a communication bus 44, and also includes a communication interface 43 connected to the communication bus 44 for adaptive connection with other components or external devices.
[0118] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0119] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0120] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0121] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0122] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0123] If the integrated unit is implemented in the form of 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 application, 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0124] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A video encoding method, characterized in that: include: Get the source fixed bit rate factor CRF value of the source video; Calculating a target quantization parameter QP value of the source video according to a coding hierarchy structure of the source video and the source CRF value, wherein the coding hierarchy structure is used to characterize a coding reference relationship of image frames in a group of pictures GOP of the source video; Performing constant visual quality encoding on the source video based on the target QP value; Calculating the target quantization parameter QP value of the source video according to the coding hierarchy structure of the source video and the source CRF value includes: adjusting the source CRF value according to the coding hierarchy structure of the source video to obtain a target CRF value; calculating the target QP value according to the target CRF value; Calculating the target QP value according to the target CRF value includes: calculating the basic complexity of the source video and actual complexity ; The basic intermediate result is calculated by the following formula: ; The actual intermediate result is calculated by the following formula: ; Calculate the QP value using the following formula: ;in, is the basic intermediate result, is the actual intermediate result, is the target QP value, b is a first preset value, is an empirical value related to the resolution.
2. The method according to claim 1, characterized in that Adjusting the source CRF value according to the coding hierarchy structure of the source video to obtain a target CRF value includes: Taking the GOP of the source video as a unit, dividing the GOP where the current frame is located into a plurality of coding layers according to the logical order of the reference frames, wherein each coding layer includes at least one image frame; Assigning an adjustment algorithm to each image frame of the coding layer in a preset library; The adjustment algorithm is used to adjust the source CRF value of each frame of the image in the GOP to obtain a target CRF value.
3. The method according to claim 2, characterized in that The source CRF value of each frame of the image in the GOP is adjusted by using the adjustment algorithm to obtain a target CRF value, including: Determine the coding layer where the current frame is located; The source CRF value of each frame image in the GOP is calculated using the following formula to obtain the target CRF value: ; in, is the target CRF value, is the source CRF value, is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
4. The method according to claim 2, characterized in that: The source CRF value of each frame of the image in the GOP is adjusted by using the adjustment algorithm to obtain a target CRF value, including: Determine the coding layer where the current frame is located; The source CRF value of each frame image in the GOP is calculated using the following formula to obtain the target CRF value: ; in, is the target CRF value, is the source CRF value, is an offset, and the offset is positively correlated with the level of the coding layer where the current frame is located.
5. The method according to claim 1, characterized in that Encoding the source video at a constant visual quality based on the target QP value comprises: Extracting an original image frame corresponding to the target QP value from the source video; A corresponding amount of image information is deleted in the pixel macroblock of the original image frame based on the target QP value to obtain an encoded image frame.
6. A video encoding device, characterized in that: include: An acquisition module is used to obtain a source fixed rate factor CRF value of a source video; A calculation module, used for calculating a target quantization parameter QP value of the source video according to a coding hierarchy structure of the source video and the source CRF value, wherein the coding hierarchy structure is used to characterize a coding reference relationship of image frames in a group of pictures GOP of the source video; An encoding module, configured to perform constant visual quality encoding on the source video based on the target QP value; The calculation module includes: a first adjustment unit, configured to adjust the source CRF value according to the coding hierarchy structure of the source video to obtain a target CRF value; a first calculation unit, configured to calculate a target QP value according to the target CRF value; The first calculation unit includes: a first calculation subunit, which is used to calculate the basic complexity of the source video. and actual complexity ; The second calculation subunit is used to calculate the basic intermediate result by the following formula: ; The third calculation subunit is used to calculate the actual intermediate result by the following formula: ; A fourth calculation subunit is used to calculate the QP value using the following formula: ;in, is the basic intermediate result, is the actual intermediate result, is the target QP value, b is a first preset value, is an empirical value related to the resolution.
7. A storage medium, characterized in that: The storage medium includes a stored program, wherein the program executes the method steps of any one of claims 1 to 5 when executed.
8. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface, and the memory communicate with each other via a communication bus; wherein: Memory, used to store computer programs; A processor, configured to execute the method steps of any one of claims 1 to 5 by running a program stored in a memory.
