Abstract
A method for optimizing a second coding is provided. The method includes: Setting a quantization parameter of a start frame of a video sequence according to a range of an input quantization parameter QP.sub.0 of a coder; performing first coding with a simplified method, and calculating a frame-level temporal impact factor k.sub.i of a current frame and a block-level temporal impact factor k.sub.B,j of all 16×16 pixel blocks in the current frame; restoring reference list information of the coder after the first coding is completed, and then determining whether a scene is switched; and performing the second coding by setting quantization parameters with different strategies according to whether the scene is switched.
Claims
1. A method for optimizing a two-pass coding, comprising the following steps: S1: setting a start frame of a video sequence as a frame I with a level set to Level 0, wherein the frame I is used as a separate Group of Pictures (GOP); optimizing the start frame, wherein the start frame is the frame I, setting a quantization parameter QP.sub.I of the frame I according to a range of an input quantization parameter QP.sub.0 of a coder: S2: reading in a frame to be coded of the GOP by the coder; S3: a first coding: performing the first coding on a current frame by using a default quantization parameter QP.sub.HM,i set by an High efficiency video coding (HEVC), and obtaining a frame-level temporal impact factor k.sub.i of the current frame and a block-level temporal impact factor k.sub.B,j of 16×16 pixel blocks in the current frame: wherein D.sub.i and D.sub.i.sup.MCP are respectively a coding distortion and a motion compensation prediction error of the current frame; and D.sub.B,j and D.sub.B,j.sup.MCP are respectively a coding distortion and a motion compensation prediction error of a jth 16×16 pixel blocks in the current frame; S4: restoring reference list information of the coder after the first coding is completed, wherein the first coding does not output a code stream of the current frame or store a reconstructed image; after the first coding, resetting a linked image list in the coder to a state before the current frame is coded, comprising restoring a reference frame identifier in the linked image list; S5: determining whether a scene is switched, if the scene is switched, performing step S6, if the scene is not switched, performing step S7; a determination method is: if p.sub.i>4p and p.sub.i>10, a scene switching occurs in the current frame, wherein p.sub.i is an average motion compensation prediction absolute error of the current frame, and p is an a mean value of the average motion compensation prediction absolute error of previous six frames; S6: setting a quantization parameter of the current frame as QP.sub.i=QP.sub.0, then performing the two-pass coding, and outputting the code stream and storing the reconstructed image in a default way of the coder, entering step S8; S7: setting the quantization parameter of the current frame as wherein QP.sub.HM,i is the quantization parameter of the current frame set in an original coder, and Round(⋅) is a rounding operator; after a frame-level Lagrangian multiplier λ.sub.p is calculated through QP.sub.i, obtaining a Lagrangian multiplier λ.sub.n and a quantization parameter QP.sub.n for coding each Coding tree unit (CTU) of the CTUs in the current frame by the following formulas: wherein M is a number of the 16×16 pixel blocks comprised in an nth CTU of the CTUs, N is a number of the CTUs in a coded frame, w.sub.n, w and W.sub.n are intermediate variables; coding the each CTU in the current frame by using the Lagrangian multiplier λ.sub.n and the quantization parameter QP.sub.n, and outputting the code stream and storing the reconstructed image in the default way of the coder; S8: determining whether the coded frame is a last frame of the video sequence, if the coded frame is the last frame of the video sequence, then ending the two-pass coding; if the coded frame is not the last frame of the video sequence, continuing to determine whether the coded frame is the last frame in a current GOP, if the coded frame is the last frame in the current GOP, then performing step S2, if the coded frame is not the last frame in the current GOP, performing step S3.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
(1) FIG. 1 is a main flowchart according to the present invention;
(2) FIG. 2 is a schematic diagram of an example of reference relationship in HEVC low-delay coding;
(3) FIG. 3 is a statistical diagram of a frame-level temporal impact factor k.sub.i according to the present invention;
(4) FIG. 4 is a schematic diagram of an example of a block-level temporal impact factor k.sub.B,j that can be visualized in video;
(5) FIG. 5 is a schematic diagram of comparison of rate distortion curves; and
(6) FIG. 6 is a schematic diagram showing coding time increase and code rate savings of the present invention relative to an HEVC coder.
DETAILED DESCRIPTION OF THE EMBODIMENTS
(7) The present invention will be further described below with reference to the drawings and simulation embodiments, and the effectiveness of the present invention will be pointed out.
Embodiment
(8) This embodiment uses a development environment of Visual Studio 2013 and is implemented based on HEVC reference software HM-16.7.
(9) FIG. 1 is a flowchart of main steps of method for optimizing two-pass coding, specifically including:
(10) S1: optimizing a start frame of a video sequence. Setting a quantization parameter QP.sub.I of a frame I according to a range of an input quantization parameter QP.sub.0 of a coder:
(11)
(12) S2: reading in a frame to be coded of a GOP in a default way of HM-16.7.
(13) S3: performing first coding in a simplified coding process. Performing first coding on a current frame by using a default quantization parameter set by the HEVC and a Lagrange multiplier calculation method, so as to obtain information such as frame-level and 16×16 pixel block-level motion compensation prediction error and coding distortion, and then calculating a frame-level temporal impact factor k.sub.i of the current frame and a block-level temporal impact factor k.sub.B,j of all the 16×16 pixel blocks in the frame according to the formula.
(14) S4: restoring information such as a reference list. The first coding does not output a code stream of the current frame or store a reconstructed image; after the coding, resetting a linked image list in the coder to a state before the current frame is coded, including restoring a reference frame identifier in the linked image list.
(15) S5: determining whether a scene is switched, if yes, then going to step S6, if no, then going to step S7. A determination method for scene switching is: if p.sub.i>4p and p.sub.i>10, it is determined that scene switching occurs in the ith frame, wherein p.sub.i is an average motion compensation prediction absolute error of the current frame, and p is an a mean value of the average motion compensation prediction absolute error of previous 6 frames.
(16) S6: setting a quantization parameter of the current frame as QP.sub.i=QP.sub.0, then performing coding, and outputting the code stream and storing the reconstructed image in a default way of the coder.
(17) S7: setting the quantization parameter of the current frame as
(18)
(19) wherein QP.sub.HM,i is the quantization parameter of the current frame set in the original HEVC coder HM, and Round(⋅) is a rounding operator. It should be noted that the above quantization parameter setting only operates on the coded frames of level 2 and 3, and the quantization parameter of the key frame keeps the setting in the original HEVC coder.
(20) After a frame-level Lagrangian multiplier λ.sub.p is calculated through QP.sub.i, obtaining a Lagrangian multiplier λ.sub.n and a quantization parameter QP.sub.n for coding each CTU in the current frame by the following formulas:
(21)
(22) wherein M is the number of the 16×16 pixel blocks included in an nth CTU, N is the number of the CTUs in a coded frame. Eventually, for a case where scene switching does not occur, coding each CTU in the current frame by using the above calculated Lagrangian multiplier λ.sub.n and quantization parameter QP.sub.n, and outputting the code stream and storing the reconstructed image in a default way of the coder.
(23) S8, determining whether the coded frame is the last frame of the video sequence. If “yes”, then ending the coding; if “no”, continuing to determine whether the coded frame is the last frame in the current GOP. If “yes”, skipping to step S2 to read the next GOP data; if “no”, skipping to step S3 to code the next frame in the current GOP.
(24) The bit stream generated by coding according to the present invention conforms to the syntax format of the HEVC standard, and all generated bit streams can be decoded by a standard HEVC decoder. Coding experiments were conducted according to HEVC general test conditions, and two coder configurations, LDB and LDP, were tested, the reference relationship of which is shown in FIG. 2. It can be seen from FIGS. 3 and 4 that the frame-level temporal impact factor k.sub.i and the block-level temporal impact factor k.sub.B,j proposed by the present invention effectively represent the rate distortion dependence.
(25) FIG. 5 shows a comparison of rate distortion curves of a test sequence PartyScene in coding configurations of LDB and LDP. It can be seen that the rate distortion performance at both low and high code rates according to the present invention is superior to the original HEVC coder HM-16.7.
(26) FIG. 6 is a schematic diagram showing coding time increase and code rate savings of the present invention relative to an original HEVC coder HM-16.7. It can be seen that in a case where coding complexity is increased by an average of 23%, average code rate savings of 5.1% and 5.3% are respectively obtained in coding configurations of LDB and LDP according to the present invention, showing remarkable rate distortion performance improvement.