CN108810545B - Method, apparatus, computer readable medium and electronic device for video encoding - Google Patents
Method, apparatus, computer readable medium and electronic device for video encoding Download PDFInfo
- Publication number
- CN108810545B CN108810545B CN201810726552.9A CN201810726552A CN108810545B CN 108810545 B CN108810545 B CN 108810545B CN 201810726552 A CN201810726552 A CN 201810726552A CN 108810545 B CN108810545 B CN 108810545B
- Authority
- CN
- China
- Prior art keywords
- frame
- quantization parameter
- video
- current frame
- encoding
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 78
- 238000013139 quantization Methods 0.000 claims abstract description 194
- 238000012986 modification Methods 0.000 claims description 20
- 230000004048 modification Effects 0.000 claims description 20
- 238000004590 computer program Methods 0.000 claims description 9
- 241000023320 Luma <angiosperm> Species 0.000 claims description 6
- OSWPMRLSEDHDFF-UHFFFAOYSA-N methyl salicylate Chemical compound COC(=O)C1=CC=CC=C1O OSWPMRLSEDHDFF-UHFFFAOYSA-N 0.000 claims description 6
- 238000012937 correction Methods 0.000 claims description 3
- 230000001105 regulatory effect Effects 0.000 claims description 3
- 230000001276 controlling effect Effects 0.000 claims description 2
- 238000007906 compression Methods 0.000 description 18
- 230000006835 compression Effects 0.000 description 18
- 238000010586 diagram Methods 0.000 description 17
- 238000012545 processing Methods 0.000 description 11
- 230000006870 function Effects 0.000 description 10
- 230000008569 process Effects 0.000 description 10
- 238000005516 engineering process Methods 0.000 description 8
- 238000004891 communication Methods 0.000 description 6
- 239000013598 vector Substances 0.000 description 6
- 230000008859 change Effects 0.000 description 4
- 238000006243 chemical reaction Methods 0.000 description 4
- 230000000694 effects Effects 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 4
- 102000037983 regulatory factors Human genes 0.000 description 4
- 108091008025 regulatory factors Proteins 0.000 description 4
- 238000012360 testing method Methods 0.000 description 4
- 230000008901 benefit Effects 0.000 description 3
- 238000005457 optimization Methods 0.000 description 3
- 230000000644 propagated effect Effects 0.000 description 3
- 230000000007 visual effect Effects 0.000 description 3
- 230000009471 action Effects 0.000 description 2
- 230000006978 adaptation Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 2
- 238000013144 data compression Methods 0.000 description 2
- 239000013307 optical fiber Substances 0.000 description 2
- 238000013441 quality evaluation Methods 0.000 description 2
- 230000011218 segmentation Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 238000007619 statistical method Methods 0.000 description 2
- 230000002457 bidirectional effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000001186 cumulative effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000018109 developmental process Effects 0.000 description 1
- 238000011156 evaluation Methods 0.000 description 1
- 239000000835 fiber Substances 0.000 description 1
- 238000001914 filtration Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 230000035945 sensitivity Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/30—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using hierarchical techniques, e.g. scalability
- H04N19/395—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using hierarchical techniques, e.g. scalability involving distributed video coding [DVC], e.g. Wyner-Ziv video coding or Slepian-Wolf video coding
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
- H04N19/102—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
- H04N19/124—Quantisation
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
- H04N19/134—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
- H04N19/146—Data rate or code amount at the encoder output
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
- H04N19/169—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
- H04N19/186—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being a colour or a chrominance component
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Signal Processing (AREA)
- Compression Or Coding Systems Of Tv Signals (AREA)
Abstract
Description
技术领域technical field
本申请涉及计算机技术领域,具体而言,涉及一种用于视频编码的方法、装置、计算机可读介质及电子设备。The present application relates to the field of computer technology, in particular, to a video encoding method, device, computer-readable medium and electronic equipment.
背景技术Background technique
视频编码技术在视频直播和点播中不断的使用,并且日趋成熟,在片源数据量巨大的情况下,常见的电视剧或者电影中常常会出现一些亮度较暗或者近似黑色的场景。例如,在电影场景中常常会出现连续3s或以上的帧是低亮度或者黑暗的场景。这些低亮度帧的存在在观影过程中虽然不会影响人们的视觉体验,但是视频序列中的当前帧在作为后续视频帧的参考帧的时候,会影响到后续的视频帧。Video coding technology is continuously used in live video and on-demand video, and it is becoming more and more mature. In the case of a huge amount of source data, there are often some darker or near-black scenes in common TV dramas or movies. For example, in a movie scene, there are often scenes in which consecutive 3s or more frames are low-brightness or dark. Although the existence of these low-brightness frames will not affect people's visual experience during the movie viewing process, when the current frame in the video sequence is used as a reference frame for subsequent video frames, it will affect subsequent video frames.
上述问题在传统的非分布式视频编码中存在,通过分析分布式的编码数据,这种情况在分布式编码中更为严重。The above problems exist in traditional non-distributed video coding, and this situation is more serious in distributed coding by analyzing distributed coding data.
在分布式编码中,由于完整视频序列在切割成多段小视频序列的过程中,切断了视频的完整性和连续性。在切断的分布式的切片点处可能发生的帧类型改变和/或编码过程中产生的编码信息的缺失对后续的视频质量的影响是一个逐渐累加的过程,尤其对上述提及到的类似场景的低亮度或者黑暗帧的质量影响较为突出,从而会导致视频序列在这些特定场景下会存在较大的质量波动。In distributed coding, since the complete video sequence is cut into multiple small video sequences, the integrity and continuity of the video are cut off. The impact of the frame type change that may occur at the cut-off distributed slice point and/or the lack of coding information generated during the coding process on the subsequent video quality is a gradual cumulative process, especially for the similar scenarios mentioned above The quality impact of low-brightness or dark frames is more prominent, which will cause large quality fluctuations in the video sequence in these specific scenes.
因此,需要一种新的用于视频编码的方法、装置、计算机可读介质及电子设备。Therefore, there is a need for a new method, device, computer-readable medium and electronic device for video encoding.
需要说明的是,在上述背景技术部分公开的信息仅用于加强对本发明的背景的理解,因此可以包括不构成对本领域普通技术人员已知的现有技术的信息。It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to those of ordinary skill in the art.
发明内容Contents of the invention
本发明实施例提供一种用于视频编码的方法、装置、计算机可读介质及电子设备,能够降低视频序列的质量波动。Embodiments of the present invention provide a method, device, computer-readable medium, and electronic device for video encoding, which can reduce quality fluctuations of video sequences.
本发明的其他特性和优点将通过下面的详细描述变得显然,或部分地通过本发明的实践而习得。Other features and advantages of the invention will become apparent from the following detailed description, or in part, be learned by practice of the invention.
根据本发明实施例的一方面,提供了一种用于视频编码的方法,视频序列采用n路编码;其中,所述方法包括:对所述视频序列进行第(n-1)路编码生成第(n-1)路分析文件,并获得所述视频序列中视频帧的第(n-1)路编码信息;获取所述视频帧的第n路编码码率控制阶段的量化参数;基于所述第(n-1)路分析文件对所述视频序列进行第n路编码,并根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数;其中,n为大于等于2的正整数。According to an aspect of the embodiments of the present invention, a method for video coding is provided, and the video sequence adopts n-pass encoding; wherein, the method includes: performing (n-1)-th pass encoding on the video sequence to generate the first (n-1) path analysis file, and obtain the (n-1) path encoding information of the video frame in the video sequence; obtain the quantization parameter of the n-th path encoding bit rate control stage of the video frame; based on the described The (n-1)th path analysis file performs the nth path encoding on the video sequence, and corrects the nth path encoding rate control stage of the video frame according to the (n-1)th path encoding information of the video frame The quantization parameter of ; wherein, n is a positive integer greater than or equal to 2.
在本发明的一些实施例中,基于前述方案,所述第(n-1)路编码信息包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比;其中,所述根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数,包括:若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第一阈值且所述当前帧非场景切换帧,则根据所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比修正所述当前帧的量化参数。In some embodiments of the present invention, based on the aforementioned solution, the (n-1)th channel of encoding information includes the peak signal-to-noise ratio of the (n-1)th channel of luminance component and chrominance component of the video frame; wherein, The modifying the quantization parameters of the nth encoding rate control stage of the video frame according to the (n-1)th encoding information of the video frame includes: if the (nth) of the current frame in the video frame -1) The peak signal-to-noise ratio of the luminance component and the chrominance component of the path is greater than the first threshold and the current frame is not a scene switching frame, then according to the peak signal-to-noise ratio of the (n-1)th path of the luminance component and the chrominance component of the current frame The noise ratio modifies the quantization parameter of the current frame.
在本发明的一些实施例中,基于前述方案,所述根据所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比修正所述当前帧的量化参数,包括:若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间至第m1区间中的任意一个,则采用相应的调控因子修正所述当前帧的量化参数;其中,m1为大于等于1的正整数。In some embodiments of the present invention, based on the foregoing solution, the modifying the quantization parameter of the current frame according to the peak signal-to-noise ratio of the (n-1)th path of the luminance component and the chrominance component of the current frame includes: if If the peak signal-to-noise ratio of the (n-1)th luminance component and chrominance component of the current frame is in any one of the first interval to the m1th interval, the quantization parameter of the current frame is corrected by using a corresponding regulation factor; Wherein, m1 is a positive integer greater than or equal to 1.
在本发明的一些实施例中,基于前述方案,m1等于5;其中,所述若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间至第m区间中的任意一个,则采用相应的调控因子修正所述当前帧的量化参数,包括:若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间,则采用第一调控因子修正所述当前帧的量化参数;或若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第2区间,则采用第二调控因子修正所述当前帧的量化参数;或若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第3区间,则采用第三调控因子修正所述当前帧的量化参数;或若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第4区间,则采用第四调控因子修正所述当前帧的量化参数;或若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第5区间,则采用第五调控因子修正所述当前帧的量化参数。In some embodiments of the present invention, based on the foregoing solution, m1 is equal to 5; wherein, if the peak signal-to-noise ratio of the (n-1)th path of the current frame is between the luminance component and the chrominance component in the first interval to the first interval In any one of the m intervals, the quantization parameter of the current frame is corrected by using the corresponding control factor, including: if the peak signal-to-noise ratio of the (n-1)th road luminance component and chrominance component of the current frame is at the first interval, the quantization parameter of the current frame is corrected by using the first control factor; or if the peak signal-to-noise ratio of the (n-1)th road luminance component and chrominance component of the current frame is in the second interval, the second modifying the quantization parameter of the current frame by the regulatory factor; or if the peak signal-to-noise ratio of the (n-1)th road brightness component and chrominance component of the current frame is in the third interval, the third regulatory factor is used to modify the current The quantization parameter of the frame; or if the peak signal-to-noise ratio of the (n-1)th road luminance component and chrominance component of the current frame is in the fourth interval, then the quantization parameter of the current frame is corrected by using the fourth regulation factor; or If the peak signal-to-noise ratio of the (n-1)th channel of the current frame is in the fifth interval, the quantization parameter of the current frame is corrected by using a fifth regulation factor.
在本发明的一些实施例中,基于前述方案,若所述视频序列为分段视频序列,则所述第一至第五调控因子分别为:1.2、1.8、2.2、3、4.5。In some embodiments of the present invention, based on the foregoing solutions, if the video sequence is a segmented video sequence, the first to fifth regulatory factors are respectively: 1.2, 1.8, 2.2, 3, and 4.5.
在本发明的一些实施例中,基于前述方案,所述第(n-1)路编码信息包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比;其中,所述根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数,包括:若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第二阈值且处于第m2区间,且所述当前帧为第一帧间预测帧,则获取所述当前帧的前向参考帧的量化参数;根据所述前向参考帧的量化参数修正所述当前帧的量化参数;其中,m2为大于等于1的正整数。In some embodiments of the present invention, based on the aforementioned solution, the (n-1)th channel of encoding information includes the peak signal-to-noise ratio of the (n-1)th channel of luminance component and chrominance component of the video frame; wherein, The modifying the quantization parameters of the nth encoding rate control stage of the video frame according to the (n-1)th encoding information of the video frame includes: if the (nth) of the current frame in the video frame -1) The peak signal-to-noise ratio of the luminance component and the chrominance component of the road is greater than the second threshold and is in the m2th interval, and the current frame is the first inter-frame prediction frame, then obtain the quantization of the forward reference frame of the current frame Parameter; modify the quantization parameter of the current frame according to the quantization parameter of the forward reference frame; wherein, m2 is a positive integer greater than or equal to 1.
在本发明的一些实施例中,基于前述方案,采用以下公式修正所述第一帧间预测帧的量化参数:q’=q-(ref0Qp+a)*b,其中,ref0Qp为所述前向参考帧的量化参数;a和b为常数;q为所述第一帧间预测帧的量化参数;q’为所述第一帧间预测帧修正后的量化参数。In some embodiments of the present invention, based on the foregoing solution, the following formula is used to modify the quantization parameter of the first inter-frame prediction frame: q'=q-(ref0Qp+a)*b, where ref0Qp is the forward A quantization parameter of the reference frame; a and b are constants; q is a quantization parameter of the first inter-prediction frame; q' is a corrected quantization parameter of the first inter-prediction frame.
在本发明的一些实施例中,基于前述方案,所述第(n-1)路编码信息包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比;其中,所述根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数,包括:若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第二阈值且处于第m2区间,且所述当前帧为第二帧间预测帧,则获取所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数;根据所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数修正所述当前帧的量化参数;其中,m2为大于等于1的正整数。In some embodiments of the present invention, based on the aforementioned solution, the (n-1)th channel of encoding information includes the peak signal-to-noise ratio of the (n-1)th channel of luminance component and chrominance component of the video frame; wherein, The modifying the quantization parameters of the nth encoding rate control stage of the video frame according to the (n-1)th encoding information of the video frame includes: if the (nth) of the current frame in the video frame -1) The peak signal-to-noise ratio of the luminance component and the chrominance component of the road is greater than the second threshold and is in the m2th interval, and the current frame is the second inter-frame prediction frame, then obtain the quantization of the forward reference frame of the current frame parameter and/or the quantization parameter of the backward parameter frame of the current frame; modify the current frame according to the quantization parameter of the forward reference frame of the current frame and/or the quantization parameter of the backward parameter frame of the current frame The quantization parameter of ; wherein, m2 is a positive integer greater than or equal to 1.
在本发明的一些实施例中,基于前述方案,采用以下公式修正所述第二帧间预测帧的量化参数:q’=q–((ref0Qp+c1)+(ref1Qp+c2))*d,其中,ref0Qp为所述前向参考帧的量化参数;ref1Qp为所述后向参考帧的量化参数;c1、c2和d为常数;q为所述第二帧间预测帧的量化参数;q’为所述第二帧间预测帧修正后的量化参数。In some embodiments of the present invention, based on the foregoing solution, the following formula is used to modify the quantization parameter of the second inter-frame prediction frame: q'=q-((ref0Qp+c1)+(ref1Qp+c2))*d, Wherein, ref0Qp is the quantization parameter of the forward reference frame; ref1Qp is the quantization parameter of the backward reference frame; c1, c2 and d are constants; q is the quantization parameter of the second inter-frame prediction frame; q' A modified quantization parameter for the second inter-frame prediction frame.
根据本发明实施例的一方面,提供了一种用于视频编码的装置,视频序列采用n路编码;其中,所述装置包括:第一编码模块,配置为对所述视频序列进行第(n-1)路编码生成第(n-1)路分析文件,并获得所述视频序列中视频帧的第(n-1)路编码信息;量化参数获取模块,配置为获取所述视频帧的第n路编码码率控制阶段的量化参数;第二编码模块,配置为基于所述第(n-1)路分析文件对所述视频序列进行第n路编码,并根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数;其中,n为大于等于2的正整数。According to an aspect of the embodiments of the present invention, there is provided a device for video encoding, where the video sequence adopts n-pass encoding; wherein, the device includes: a first encoding module configured to perform (nth) encoding on the video sequence -1) Encoding generates the (n-1)th path analysis file, and obtains the (n-1)th path encoding information of the video frame in the video sequence; the quantization parameter acquisition module is configured to obtain the first (n-1) path of the video frame. The quantization parameters of the n-way encoding rate control stage; the second encoding module is configured to carry out the n-th way encoding to the video sequence based on the (n-1)th way analysis file, and according to the (n-1)th way of the video frame. n-1) channel encoding information modifying the quantization parameters of the nth encoding rate control stage of the video frame; wherein, n is a positive integer greater than or equal to 2.
在本发明的一些实施例中,基于前述方案,所述第(n-1)路编码信息包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比;其中,所述第二编码模块包括:第一量化参数修正单元,配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第一阈值且所述当前帧非场景切换帧,则根据所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比修正所述当前帧的量化参数。In some embodiments of the present invention, based on the aforementioned solution, the (n-1)th channel of encoding information includes the peak signal-to-noise ratio of the (n-1)th channel of luminance component and chrominance component of the video frame; wherein, The second encoding module includes: a first quantization parameter correction unit, configured to if the peak signal-to-noise ratio of the (n-1)th luma component and chrominance component of the current frame in the video frame is greater than a first threshold and the If the current frame is not a scene-switching frame, the quantization parameter of the current frame is corrected according to the peak signal-to-noise ratio of the (n-1)th luminance component and chrominance component of the current frame.
在本发明的一些实施例中,基于前述方案,所述第一量化参数修正单元包括:第一量化参数修正子单元,配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第一阈值且所述当前帧非场景切换帧,且所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间至第m1区间中的任意一个,则采用相应的调控因子修正所述当前帧的量化参数;其中,m1为大于等于1的正整数。In some embodiments of the present invention, based on the foregoing solution, the first quantization parameter modification unit includes: a first quantization parameter modification subunit configured to, if the (n-1)th way of the current frame in the video frame The peak signal-to-noise ratio of the luminance component and the chrominance component is greater than the first threshold and the current frame is not a scene switching frame, and the peak signal-to-noise ratio of the (n-1)th path of the luminance component and the chrominance component of the current frame is at the first In any one of intervals to the m1th interval, the quantization parameter of the current frame is corrected using a corresponding regulation factor; wherein, m1 is a positive integer greater than or equal to 1.
在本发明的一些实施例中,基于前述方案,所述第(n-1)路编码信息包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比;其中,所述第二编码模块包括:第二量化参数修正单元,配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第二阈值且处于第m2区间,且所述当前帧为第一帧间预测帧,则获取所述当前帧的前向参考帧的量化参数;根据所述前向参考帧的量化参数修正所述当前帧的量化参数;和/或第三量化参数修正单元,配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于所述第二阈值且处于第m2区间,且所述当前帧为第二帧间预测帧,则获取所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数;根据所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数修正所述当前帧的量化参数;其中,m2为大于等于1的正整数。In some embodiments of the present invention, based on the aforementioned solution, the (n-1)th channel of encoding information includes the peak signal-to-noise ratio of the (n-1)th channel of luminance component and chrominance component of the video frame; wherein, The second encoding module includes: a second quantization parameter modification unit, configured to if the peak signal-to-noise ratio of the (n-1)th road brightness component and chrominance component of the current frame in the video frame is greater than a second threshold and is in In the m2th interval, and the current frame is the first inter-frame prediction frame, then obtain the quantization parameter of the forward reference frame of the current frame; modify the quantization parameter of the current frame according to the quantization parameter of the forward reference frame ; and/or a third quantization parameter correction unit, configured to if the peak signal-to-noise ratio of the (n-1)th luma component and chrominance component of the current frame in the video frame is greater than the second threshold and is in the m2th interval, and the current frame is a second inter-frame prediction frame, then obtain the quantization parameter of the forward reference frame of the current frame and/or the quantization parameter of the backward parameter frame of the current frame; according to the current frame The quantization parameter of the forward reference frame and/or the quantization parameter of the backward parameter frame of the current frame modifies the quantization parameter of the current frame; wherein, m2 is a positive integer greater than or equal to 1.
根据本发明实施例的一方面,提供了一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现如上述实施例中所述的用于视频编码的方法。According to an aspect of the embodiments of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for video encoding as described in the above-mentioned embodiments is implemented.
根据本发明实施例的一方面,提供了一种电子设备,包括:一个或多个处理器;存储装置,配置为存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行时,使得所述一个或多个处理器实现如上述实施例中所述的用于视频编码的方法。According to an aspect of the embodiments of the present invention, there is provided an electronic device, including: one or more processors; a storage device configured to store one or more programs, when the one or more programs are executed by the one or more When executed by multiple processors, the one or more processors implement the method for video encoding as described in the foregoing embodiments.
在本发明的一些实施例所提供的技术方案中,通过对视频序列进行第(n-1)路编码获得所述视频序列中视频帧的第(n-1)路编码信息,并基于所述第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数,从而可以降低视频序列的质量波动,给用户带来更好的视觉体验。In the technical solution provided by some embodiments of the present invention, the (n-1)th encoding information of the video frame in the video sequence is obtained by performing the (n-1)th encoding on the video sequence, and based on the The (n-1)th coding information modifies the quantization parameters of the nth coding rate control stage of the video frame, so as to reduce the quality fluctuation of the video sequence and bring better visual experience to the user.
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本发明。It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention.
附图说明Description of drawings
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本发明的实施例,并与说明书一起用于解释本发明的原理。显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。在附图中:The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description serve to explain the principles of the invention. Apparently, the drawings in the following description are only some embodiments of the present invention, and those skilled in the art can obtain other drawings according to these drawings without creative efforts. In the attached picture:
图1示出了可以应用本发明实施例的用于视频编码的方法或用于视频编码的装置的示例性系统架构的示意图;FIG. 1 shows a schematic diagram of an exemplary system architecture of a method for video encoding or an apparatus for video encoding to which an embodiment of the present invention can be applied;
图2示出了适于用来实现本发明实施例的电子设备的计算机系统的结构示意图;FIG. 2 shows a schematic structural diagram of a computer system suitable for implementing an electronic device according to an embodiment of the present invention;
图3示意性示出了根据本发明的一实施例的用于视频编码的方法的流程图;Fig. 3 schematically shows a flowchart of a method for video encoding according to an embodiment of the present invention;
图4示出了图3中所示的步骤S310在一实施例中的处理过程示意图;FIG. 4 shows a schematic diagram of the processing process of step S310 shown in FIG. 3 in an embodiment;
图5示出了图3中所示的步骤S330在一实施例中的处理过程示意图;FIG. 5 shows a schematic diagram of the processing process of step S330 shown in FIG. 3 in an embodiment;
图6示意性示出了根据本发明的又一实施例的用于视频编码的方法的流程图;FIG. 6 schematically shows a flowchart of a method for video encoding according to yet another embodiment of the present invention;
图7示意性示出了根据本发明的再一实施例的用于视频编码的方法的流程图;Fig. 7 schematically shows a flowchart of a method for video encoding according to yet another embodiment of the present invention;
图8示意性示出了根据本发明的一实施例的用于视频编码的装置的框图;Fig. 8 schematically shows a block diagram of a device for video encoding according to an embodiment of the present invention;
图9示意性示出了根据本发明的又一实施例的用于视频编码的装置的框图。Fig. 9 schematically shows a block diagram of an apparatus for video encoding according to yet another embodiment of the present invention.
具体实施方式Detailed ways
现在将参考附图更全面地描述示例实施方式。然而,示例实施方式能够以多种形式实施,且不应被理解为限于在此阐述的范例;相反,提供这些实施方式使得本发明将更加全面和完整,并将示例实施方式的构思全面地传达给本领域的技术人员。Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete and fully convey the concept of example embodiments to those skilled in the art.
此外,所描述的特征、结构或特性可以以任何合适的方式结合在一个或更多实施例中。在下面的描述中,提供许多具体细节从而给出对本发明的实施例的充分理解。然而,本领域技术人员将意识到,可以实践本发明的技术方案而没有特定细节中的一个或更多,或者可以采用其它的方法、组元、装置、步骤等。在其它情况下,不详细示出或描述公知方法、装置、实现或者操作以避免模糊本发明的各方面。Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided in order to give a thorough understanding of embodiments of the invention. However, those skilled in the art will appreciate that the technical solutions of the present invention may be practiced without one or more of the specific details, or other methods, components, means, steps, etc. may be employed. In other instances, well-known methods, apparatus, implementations, or operations have not been shown or described in detail to avoid obscuring aspects of the invention.
附图中所示的方框图仅仅是功能实体,不一定必须与物理上独立的实体相对应。即,可以采用软件形式来实现这些功能实体,或在一个或多个硬件模块或集成电路中实现这些功能实体,或在不同网络和/或处理器装置和/或微控制器装置中实现这些功能实体。The block diagrams shown in the drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices entity.
附图中所示的流程图仅是示例性说明,不是必须包括所有的内容和操作/步骤,也不是必须按所描述的顺序执行。例如,有的操作/步骤还可以分解,而有的操作/步骤可以合并或部分合并,因此实际执行的顺序有可能根据实际情况改变。The flow charts shown in the drawings are only exemplary illustrations, and do not necessarily include all contents and operations/steps, nor must they be performed in the order described. For example, some operations/steps can be decomposed, and some operations/steps can be combined or partly combined, so the actual order of execution may be changed according to the actual situation.
图1示出了可以应用本发明实施例的用于视频编码的方法或用于视频编码的装置的示例性系统架构100的示意图。Fig. 1 shows a schematic diagram of an
如图1所示,系统架构100可以包括终端设备101、102、103中的一种或多种,网络104和服务器105。网络104用以在终端设备101、102、103和服务器105之间提供通信链路的介质。网络104可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 1 , the
应该理解,图1中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。比如服务器105可以是多个服务器组成的服务器集群等。It should be understood that the numbers of terminal devices, networks and servers in Fig. 1 are only illustrative. According to the implementation needs, there can be any number of terminal devices, networks and servers. For example, the
用户可以使用终端设备101、102、103通过网络104与服务器105交互,以接收或发送消息等。终端设备101、102、103可以是具有显示屏的各种电子设备,包括但不限于智能手机、平板电脑、便携式计算机和台式计算机、数字电影放映机等等。Users can use
服务器105可以是提供各种服务的服务器。例如用户利用终端设备103(也可以是终端设备101或102)向服务器105发送视频直播或者视频点播请求。服务器105可以基于该视频直播或者视频点播中携带的相关信息,在数据库中检索到匹配的搜索结果,并将搜索结果例如相应的视频信息反馈给终端设备103,进而用户可以基于终端设备103上显示的内容观看相应的视频。The
又如终端设备103(也可以是终端设备101或102)可以是电影院的数字电影放映机,用户可以通过该数字电影放映机向服务器105发送视频播放指令。服务器105可以基于该视频播放指令,在数据库中检索到匹配的电影视频返回给该数字电影放映机,进而通过该数字电影放映机将返回的电影视频进行播放。Another example is that the terminal device 103 (or the
图2示出了适于用来实现本发明实施例的电子设备的计算机系统的结构示意图。Fig. 2 shows a schematic structural diagram of a computer system suitable for implementing the electronic device of the embodiment of the present invention.
需要说明的是,图2示出的电子设备的计算机系统200仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。It should be noted that the
如图2所示,计算机系统200包括中央处理单元(CPU)201,其可以根据存储在只读存储器(ROM)202中的程序或者从存储部分208加载到随机访问存储器(RAM)203中的程序而执行各种适当的动作和处理。在RAM 203中,还存储有系统操作所需的各种程序和数据。CPU201、ROM202以及RAM 203通过总线204彼此相连。输入/输出(I/O)接口205也连接至总线204。As shown in FIG. 2 , a
以下部件连接至I/O接口205:包括键盘、鼠标等的输入部分206;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分207;包括硬盘等的存储部分208;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分209。通信部分209经由诸如因特网的网络执行通信处理。驱动器210也根据需要连接至I/O接口205。可拆卸介质211,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器210上,以便于从其上读出的计算机程序根据需要被安装入存储部分208。The following components are connected to the I/O interface 205: an
特别地,根据本发明的实施例,下文参考流程图描述的过程可以被实现为计算机软件程序。例如,本发明的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分209从网络上被下载和安装,和/或从可拆卸介质211被安装。在该计算机程序被中央处理单元(CPU)201执行时,执行本申请的方法和/或装置中限定的各种功能。In particular, according to an embodiment of the present invention, the processes described below with reference to the flowcharts may be implemented as computer software programs. For example, the embodiments of the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, where the computer program includes program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via
需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. A computer readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable Programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, in which computer-readable program codes are carried. Such propagated data signals may take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. . Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
附图中的流程图和框图,图示了按照本发明各种实施例的方法、装置和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the figures illustrate the architecture, functions and operations of possible implementations of methods, apparatuses and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, program segment, or portion of code that includes one or more logical functions for implementing specified executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved. It should also be noted that each block in the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a A combination of dedicated hardware and computer instructions.
描述于本发明实施例中所涉及到的模块和/或单元和/或子单元可以通过软件的方式实现,也可以通过硬件的方式来实现,所描述的模块和/或单元和/或子单元也可以设置在处理器中。其中,这些模块和/或单元和/或子单元的名称在某种情况下并不构成对该模块和/或单元和/或子单元本身的限定。The modules and/or units and/or subunits involved in the embodiments described in the present invention can be realized by software or by hardware. The described modules and/or units and/or subunits It can also be set in the processor. Wherein, the names of these modules and/or units and/or subunits do not constitute limitations on the modules and/or units and/or subunits themselves under certain circumstances.
作为另一方面,本申请还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的电子设备中所包含的;也可以是单独存在,而未装配入该电子设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该电子设备执行时,使得该电子设备实现如下述实施例中所述的方法。例如,所述的电子设备可以实现如图3或图4或图5或图6或图7所示的各个步骤。As another aspect, the present application also provides a computer-readable medium. The computer-readable medium may be included in the electronic device described in the above-mentioned embodiments; or it may exist independently without being assembled into the electronic device. middle. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by an electronic device, the electronic device is made to implement the methods described in the following embodiments. For example, the electronic device may implement various steps as shown in FIG. 3 or FIG. 4 or FIG. 5 or FIG. 6 or FIG. 7 .
图3示意性示出了根据本发明的一实施例的用于视频编码的方法的流程图。Fig. 3 schematically shows a flowchart of a method for video encoding according to an embodiment of the present invention.
本发明实施方式提供的用于视频编码的方法,视频序列可以采用n路编码,其中,n为大于等于2的正整数。In the video encoding method provided by the embodiment of the present invention, the video sequence may adopt n-pass encoding, where n is a positive integer greater than or equal to 2.
例如,n可以为2,则当前视频序列采用2路编码,即首先将当前视频序列进行第一路编码(1pass);然后再基于1pass编码后的分析文件,对当前视频序列进行第二路编码(2pass)。当当前视频序列采用2路编码时,1pass编码一般仅保留需要的有效信息并存储为文件,以供2pass编码时读取该文件中的有效信息进行第二路编码。For example, if n can be 2, then the current video sequence adopts 2-pass encoding, that is, the current video sequence is first encoded (1pass); and then based on the analysis file encoded by 1pass, the current video sequence is encoded in the second pass (2pass). When the current video sequence adopts 2-way encoding, 1pass encoding generally only retains the required effective information and stores it as a file, so that the effective information in the file can be read for 2pass encoding to perform the second-pass encoding.
其中,2pass编码方式可以精确的得到想要的平均码率,2pass代表将视频序列做2次编码,第一路编码视频编码器例如x264先分析整个视频序列,可以得到一个stats文件和一个mbtree文件(默认使用mbtree)。第二路编码可以以这两个文件作参考分配合理的码率。需要特定的码率或文件大小需要使用2pass或者多pass编码。Among them, the 2pass encoding method can accurately obtain the desired average bit rate. 2pass means that the video sequence is encoded twice. The first encoding video encoder such as x264 first analyzes the entire video sequence, and a stats file and an mbtree file can be obtained. (By default mbtree is used). The second encoding can use these two files as a reference to assign a reasonable bit rate. If you need a specific bit rate or file size, you need to use 2pass or multi-pass encoding.
再例如,n可以为3,则当前视频序列采用3路编码,即首先将当前视频序列进行第一路编码(1pass);然后再基于1pass编码后的分析文件,对当前视频序列进行第二路编码(2pass);接着再基于2pass编码后的分析文件,对当前视频序列进行第三路编码(3pass)。以此类推,可以对当前视频序列进行多路编码,具体的编码路数可以根据应用场景而定,本发明对此不作限定。即除了2pass,还有多pass编码方式,在之前分析的基础上再继续分析,理论上会使码率分配更加合理,但实际上2pass已经足够了。For another example, n can be 3, then the current video sequence adopts 3-pass encoding, that is, the current video sequence is first encoded (1pass); and then based on the analysis file after 1pass encoding, the current video sequence is encoded in the second pass Encoding (2pass); then, based on the analysis file encoded by 2pass, a third pass of encoding (3pass) is performed on the current video sequence. By analogy, the current video sequence can be encoded in multiple channels, and the specific number of encoding channels can be determined according to the application scenario, which is not limited in the present invention. That is to say, in addition to 2pass, there are also multi-pass encoding methods. Continuing the analysis on the basis of the previous analysis will theoretically make the code rate allocation more reasonable, but in fact 2pass is enough.
需要说明的是,在下面的举例中,均以视频序列采用2路编码为例进行说明,但本发明并不限定于此。It should be noted that, in the following examples, the video sequence adopts 2-way encoding as an example for illustration, but the present invention is not limited thereto.
如图3所示,本发明实施方式提供的用于视频编码的方法可以包括以下步骤。本发明实施方式的方法可以由终端设备执行,也可以由服务端执行,或者由终端设备和服务端交互执行,例如,可以由上述图1中的服务器105执行,但本发明并不限定于此。As shown in FIG. 3 , the method for video coding provided by the embodiment of the present invention may include the following steps. The method in the embodiment of the present invention may be executed by a terminal device, or may be executed by a server, or may be executed interactively by a terminal device and a server, for example, may be executed by the
在步骤S310中,对所述视频序列进行第(n-1)路编码生成第(n-1)路分析文件,并获得所述视频序列中视频帧的第(n-1)路编码信息。In step S310, the (n-1)th pass encoding is performed on the video sequence to generate the (n-1)th pass analysis file, and the (n-1)th pass encoding information of the video frame in the video sequence is obtained.
在示例性实施例中,所述第(n-1)路编码信息可以包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比(即视频帧的第(n-1)路YUV PSNR,下文中记为(n-1)passPSNR)。In an exemplary embodiment, the (n-1)th way of encoding information may include the peak signal-to-noise ratio of the (n-1)th way of the video frame luminance component and chrominance component (that is, the (n-th)th way of the video frame -1) pass YUV PSNR, hereinafter denoted as (n-1)passPSNR).
其中,PSNR(Peak Signal to Noise Ratio,峰值信噪比),是一种评价图像的客观标准。通常在经过影像压缩之后,输出的影像都会在某种程度与原始影像不同。为了衡量经过处理后的影像品质,通常会参考PSNR值来衡量某个处理是否令人满意。PSNR的单位是dB,数值越大表示失真越小。PSNR是普遍和使用较为广泛的一种图像客观评价指标,它是基于对应像素点间的误差,即基于误差敏感的图像质量评价。Among them, PSNR (Peak Signal to Noise Ratio, peak signal-to-noise ratio) is an objective standard for evaluating images. Usually after image compression, the output image will be different from the original image to some extent. In order to measure the image quality after processing, the PSNR value is usually used to measure whether a certain processing is satisfactory. The unit of PSNR is dB, and the larger the value, the smaller the distortion. PSNR is a common and widely used image objective evaluation index, which is based on the error between corresponding pixels, that is, image quality evaluation based on error sensitivity.
在步骤S320中,获取所述视频帧的第n路编码码率控制阶段的量化参数(Quantization Parameter,QP,下文中记为q)。In step S320, the quantization parameter (Quantization Parameter, QP, hereinafter denoted as q) of the nth coding rate control stage of the video frame is obtained.
本发明实施例中,在对所述视频序列中第n路编码之前,视频编码器会预先自动给所述视频序列中的各个视频帧分配一个初始的量化参数q。In the embodiment of the present invention, before encoding the nth channel in the video sequence, the video encoder will automatically assign an initial quantization parameter q to each video frame in the video sequence in advance.
在步骤S330中,基于所述第(n-1)路分析文件对所述视频序列进行第n路编码,并根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数。In step S330, the video sequence is encoded based on the (n-1)th way analysis file, and the video frame is corrected according to the (n-1)th way encoding information of the video frame Quantization parameter in the rate control stage of the n-th encoding.
本发明实施例中,利用各视频帧的第(n-1)路编码信息对编码中所使用的量化参数值进行修正,然后利用修正后的量化参数值进行编码。In the embodiment of the present invention, the (n-1)th coding information of each video frame is used to modify the quantization parameter value used in coding, and then the coding is performed using the modified quantization parameter value.
在示例性实施例中,所述根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数,可以包括:若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第一阈值且所述当前帧非场景切换帧,则根据所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比修正所述当前帧的量化参数。In an exemplary embodiment, the modifying the quantization parameters of the nth encoding rate control stage of the video frame according to the (n-1)th encoding information of the video frame may include: if the video frame The peak signal-to-noise ratio of the (n-1)th path luminance component and chrominance component of the current frame in the current frame is greater than the first threshold and the current frame is not a scene switching frame, then according to the (n-1)th path of the current frame The peak signal-to-noise ratio of the luma component and the chrominance component modifies the quantization parameter of the current frame.
例如,所述第一阈值可以为61。但本发明并不限定于此,所述第一阈值的取值可以根据所述视频序列是否分段视频序列以及具体的应用场景来确定。For example, the first threshold may be 61. However, the present invention is not limited thereto, and the value of the first threshold may be determined according to whether the video sequence is a segmented video sequence and a specific application scenario.
本发明实施例中,可以将(n-1)passPSNR大于所述第一阈值的视频帧称之为低亮度帧。例如,低亮度帧可以是指视频帧的第(n-1)路YUV PSNR值大于61的视频帧。In the embodiment of the present invention, a video frame whose (n-1) passPSNR is greater than the first threshold may be referred to as a low-brightness frame. For example, the low-brightness frame may refer to a video frame whose YUV PSNR value of the (n-1)th way of the video frame is greater than 61.
这里对视频编码的基本原理进行简单说明:视频图像数据有极强的相关性,也就是说有大量的冗余信息。其中冗余信息可分为空域冗余信息和时域冗余信息。压缩技术就是将数据中的冗余信息去掉,去除数据之间的相关性,压缩技术包含帧内图像数据压缩技术、帧间图像数据压缩技术和熵编码压缩技术。视频文件一般涉及到三个参数:帧率、分辨率和码率。其中,帧率是指每秒显示的图片数,帧率影响画面流畅度,与画面流畅度成正比。码率是指把每秒显示的图片进行压缩后的数据量,码率影响体积,与体积成正比。分辨率是指(矩形)图片的长度和宽度,即图片的尺寸。其中,帧率乘以分辨率等于压缩前的每秒数据量,单位为字节。压缩比等于压缩前的每秒数据量/码率,对于同一个视频源并采用同一种视频编码算法,则压缩比越高,画面质量越差。Here is a brief description of the basic principle of video coding: video image data has a strong correlation, that is to say, there is a large amount of redundant information. The redundant information can be divided into air domain redundant information and time domain redundant information. Compression technology is to remove redundant information in the data and remove the correlation between data. Compression technology includes intra-frame image data compression technology, inter-frame image data compression technology and entropy coding compression technology. Video files generally involve three parameters: frame rate, resolution and bit rate. Among them, the frame rate refers to the number of pictures displayed per second, and the frame rate affects the smoothness of the picture, and is directly proportional to the fluency of the picture. The bit rate refers to the amount of data after compressing the pictures displayed per second. The bit rate affects the volume and is proportional to the volume. Resolution refers to the length and width of a (rectangular) picture, ie the dimensions of the picture. Wherein, the frame rate multiplied by the resolution is equal to the amount of data per second before compression, and the unit is byte. The compression ratio is equal to the amount of data/bit rate per second before compression. For the same video source and the same video coding algorithm, the higher the compression ratio, the worse the picture quality.
视频质量可以通过主观和客观方式来表现,主观方式就是通常人们提到的视频清晰度,而客观参数则是量化参数或者压缩比或者码率。在视频源一样,压缩算法也一样的前提下比较,量化参数、压缩比和码率之间是有直接的比例关系的。Video quality can be expressed in subjective and objective ways. The subjective way is usually referred to as video clarity, while the objective parameters are quantization parameters or compression ratio or bit rate. Comparing on the premise that the video source is the same and the compression algorithm is the same, there is a direct proportional relationship between quantization parameters, compression ratio and bit rate.
其中,视频的码率直接影响到了视频的编码质量。为了在信道带宽和传输时延受限的情况下,有效地传输视频数据以满足网络视频业务的服务要求,通常需要对视频编码进行码率控制。所谓的码率控制就是通过设置适当的编码参数,在保证恢复视频质量的前提之下,使视频编码产生的码率尽可能的接近已定好的目标码率。Among them, the bit rate of the video directly affects the encoding quality of the video. In order to effectively transmit video data to meet the service requirements of network video services under the condition of limited channel bandwidth and transmission delay, it is usually necessary to perform rate control on video coding. The so-called bit rate control is to make the bit rate generated by video encoding as close to the set target bit rate as possible under the premise of ensuring the restored video quality by setting appropriate encoding parameters.
在示例性实施例中,所述根据所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比修正所述当前帧的量化参数,可以包括:若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间至第m1区间中的任意一个,则采用相应的调控因子修正所述当前帧的量化参数;其中,m1为大于等于1的正整数。In an exemplary embodiment, the modifying the quantization parameter of the current frame according to the peak signal-to-noise ratio of the (n-1)th luminance component and chrominance component of the current frame may include: if the current frame The peak signal-to-noise ratio of the (n-1)th road luminance component and chrominance component is in any one of the first interval to the m1th interval, and the corresponding control factor is used to modify the quantization parameter of the current frame; wherein, m1 is greater than A positive integer equal to 1.
本发明实施例中,m1等于5。但本发明并不限定于此,具体的区间划分可以根据实际应用场景选择,这里仅用于举例说明。In the embodiment of the present invention, m1 is equal to 5. However, the present invention is not limited thereto, and specific interval divisions may be selected according to actual application scenarios, which are only used for illustration here.
在示例性实施例中,所述若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间至第m区间中的任意一个,则采用相应的调控因子修正所述当前帧的量化参数,可以包括:In an exemplary embodiment, if the peak signal-to-noise ratio of the (n-1)th luminance component and chrominance component of the current frame is in any one of the first interval to the mth interval, the corresponding regulation is adopted Modifying the quantization parameter of the current frame by a factor may include:
若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间,则采用第一调控因子qFactor1修正所述当前帧的量化参数;或If the peak signal-to-noise ratio of the (n-1)th luma component and chrominance component of the current frame is in the first interval, then use the first regulation factor qFactor1 to modify the quantization parameter of the current frame; or
若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第2区间,则采用第二调控因子qFactor2修正所述当前帧的量化参数;或If the peak signal-to-noise ratio of the (n-1)th luminance component and chrominance component of the current frame is in the second interval, the quantization parameter of the current frame is corrected by using the second regulation factor qFactor2; or
若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第3区间,则采用第三调控因子qFactor3修正所述当前帧的量化参数;或If the peak signal-to-noise ratio of the (n-1) luminance component and chrominance component of the current frame is in the third interval, the quantization parameter of the current frame is corrected by using the third regulation factor qFactor3; or
若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第4区间,则采用第四调控因子qFactor4修正所述当前帧的量化参数;或If the peak signal-to-noise ratio of the (n-1) luminance component and chrominance component of the current frame is in the fourth interval, the quantization parameter of the current frame is corrected by using the fourth regulation factor qFactor4; or
若所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第5区间,则采用第五调控因子qFactor5修正所述当前帧的量化参数。If the peak signal-to-noise ratio of the (n-1)th channel of the current frame is in the fifth interval, the quantization parameter of the current frame is corrected by using the fifth adjustment factor qFactor5.
本发明实施例通过评测低亮度的视频帧(可以简写为低亮度帧)和统计低亮度的视频帧的YUV PSNR值进行分区间,将低亮度场景的视频帧划分成5个区间,在各个区间中采用大量数据的经验值得出的相应调控因子来调整量化参数,可以有效提高低亮度场景的视频帧的视频质量,减少质量波动,特别是针对分布式编码效果显著,可以将其应用视频点播和直播平台中。The embodiment of the present invention divides the video frames of the low-brightness scene into 5 intervals by evaluating the low-brightness video frames (which can be abbreviated as low-brightness frames) and counting the YUV PSNR values of the low-brightness video frames. In the method, the corresponding regulatory factors derived from the empirical value of a large amount of data are used to adjust the quantization parameters, which can effectively improve the video quality of video frames in low-brightness scenes and reduce quality fluctuations. Especially for distributed coding, the effect is remarkable, and it can be applied to video-on-demand and live platform.
在示例性实施例中,若所述视频序列为分段视频序列,则所述第一至第五调控因子分别为:1.2、1.8、2.2、3、4.5。In an exemplary embodiment, if the video sequence is a segmented video sequence, the first to fifth regulation factors are respectively: 1.2, 1.8, 2.2, 3, and 4.5.
需要说明的是,上述第一至第五调控因子是针对分布式编码中的分段视频序列进行大量数据统计分析获得的经验值,若所述视频序列的编码方式发生改变例如采用非分布式编码,则相应的上述第一至第五调控因子可以发生相应的变化。此外,虽然上述以分布式视频编码为例进行说明,但本发明实施例提供的方法也可以应用非分布式编码方式中。It should be noted that the above-mentioned first to fifth regulatory factors are empirical values obtained by statistical analysis of a large amount of data for segmented video sequences in distributed coding. , then the corresponding above-mentioned first to fifth regulatory factors can undergo corresponding changes. In addition, although the description above takes distributed video coding as an example, the method provided in the embodiment of the present invention may also be applied in a non-distributed coding manner.
其中,视频转换编码简称视频转码,是指视频从一种格式到另一种格式的转换,其中格式是由码率、帧率、空间分布率和编码算法所表征。随着高清电影的发展,影片的片源容量从几G增加到几十G不等,对此类片源转码所需的时间也急剧增加。另外,由于转码需要适配的用户终端类型增多,转码任务日趋繁多。目前主流的转码模式有分布式的,即采用多台转码服务器同时对视频文件进行转码。将视频在片源分段,将每段传输到对应的转码服务器上,转码完成后将各段合并成一个视频文件,返回该视频。这种方式优点是并行转码,时间成本低,可以应对并发转码任务。例如基于Hadoop平台的分布式视频转码方案,使用HDFS(Hadoop Distributed System,分布式文件系统)存储视频文件和利用MapReduce编程框架进行分布式转码,转码工具采用FFMPEG,将视频存储和转码集成一体,达到减少转码时所需网络带宽和耗时的目的。Among them, video conversion coding is referred to as video transcoding, which refers to the conversion of video from one format to another, where the format is characterized by bit rate, frame rate, spatial distribution rate and coding algorithm. With the development of high-definition movies, the capacity of movie sources has increased from a few gigabytes to tens of gigabytes, and the time required to transcode such movie sources has also increased dramatically. In addition, as the types of user terminals that need to be adapted for transcoding increase, transcoding tasks become increasingly numerous. At present, the mainstream transcoding mode is distributed, that is, multiple transcoding servers are used to transcode video files at the same time. Divide the video into segments at the source, transmit each segment to the corresponding transcoding server, merge each segment into a video file after transcoding, and return the video. The advantage of this method is parallel transcoding, low time cost, and can handle concurrent transcoding tasks. For example, the distributed video transcoding solution based on the Hadoop platform uses HDFS (Hadoop Distributed System, distributed file system) to store video files and uses the MapReduce programming framework for distributed transcoding. The transcoding tool uses FFMPEG to store and transcode video Integrated to achieve the purpose of reducing the network bandwidth and time-consuming required for transcoding.
其中,整个系统可以包括一个WebServer和一个Hadoop集群。WebServer负责处理用户请求,包括视频的存取和转码。Hadoop集群中的NameNode负责接收WebServer转发的用户请求,调度集群中的DataNodes进行视频存储或者转码。HDFS中文件都以数据块形式存储,一个文件由一个或多个数据块组成,其中数据块的大小可以调整,故在存储视频文件时需要分段(对视频分段即分块)。Wherein, the whole system may include a WebServer and a Hadoop cluster. WebServer is responsible for processing user requests, including video access and transcoding. The NameNode in the Hadoop cluster is responsible for receiving user requests forwarded by the WebServer, and dispatching the DataNodes in the cluster for video storage or transcoding. Files in HDFS are stored in the form of data blocks. A file is composed of one or more data blocks, and the size of the data blocks can be adjusted. Therefore, segmentation is required when storing video files (segmentation of video is block).
在分布式编码中,分段视频序列的切片点也是一个视频帧。位于切片点处的视频帧一方面可能发生帧类型(例如I帧,或者P帧,或者B帧)的改变;另一方面,即使切片点处的视频帧不发生帧类型的改变,由于分布式编码中视频连续性受到了影响,也会影响视频质量。例如,当前帧如果是帧间预测帧,需要参考前向的视频帧,切片会导致编码信息的缺失。因此,在分布式编码中因为切片点的帧类型改变和/或编码信息的缺失会导致视频的质量波动更严重。In distributed coding, a slice point of a segmented video sequence is also a video frame. On the one hand, the frame type (such as I frame, or P frame, or B frame) may change in the video frame at the slice point; on the other hand, even if the frame type does not change in the video frame at the slice point, due to distributed Video continuity is affected during encoding, which also affects video quality. For example, if the current frame is an inter-frame prediction frame, it needs to refer to the forward video frame, and slicing will result in the loss of coding information. Therefore, in the distributed encoding, the change of the frame type of the slice point and/or the lack of encoding information will lead to more serious fluctuations in the quality of the video.
在示例性实施例中,其中,所述根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数,可以包括:若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第二阈值且处于第m2区间,且所述当前帧为第一帧间预测帧,则获取所述当前帧的前向参考帧的量化参数;根据所述前向参考帧的量化参数修正所述当前帧的量化参数;其中,m2为大于等于1的正整数。In an exemplary embodiment, wherein, the modifying the quantization parameters of the nth encoding rate control stage of the video frame according to the (n-1)th encoding information of the video frame may include: if the The peak signal-to-noise ratio of the (n-1) luminance component and chrominance component of the current frame in the video frame is greater than the second threshold and is in the m2th interval, and the current frame is the first inter-frame prediction frame, then the obtained The quantization parameter of the forward reference frame of the current frame; the quantization parameter of the current frame is corrected according to the quantization parameter of the forward reference frame; wherein, m2 is a positive integer greater than or equal to 1.
在示例性实施例中,m1可以等于m2,例如m1=m2=5。但本发明并不限定于此。In an exemplary embodiment, m1 may be equal to m2, eg m1=m2=5. However, the present invention is not limited thereto.
在示例性实施例中,可以采用以下公式修正所述第一帧间预测帧的量化参数:In an exemplary embodiment, the quantization parameter of the first inter-frame prediction frame may be corrected by using the following formula:
q’=q-(ref0Qp+a)*b (1)q'=q-(ref0Qp+a)*b (1)
其中,上述公式(1)中,ref0Qp为所述第一帧间预测帧的前向参考帧的量化参数;a和b为常数,例如a可以取值为4,b可以取值为2,但本发明并不限定于此;q为所述第一帧间预测帧的量化参数;q’为所述第一帧间预测帧修正后的量化参数。Wherein, in the above formula (1), ref0Qp is the quantization parameter of the forward reference frame of the first inter-frame prediction frame; a and b are constants, for example, a can take a value of 4, and b can take a value of 2, but The present invention is not limited thereto; q is a quantization parameter of the first inter-frame prediction frame; q' is a corrected quantization parameter of the first inter-frame prediction frame.
在示例性实施例中,所述根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数,可以包括:若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第二阈值且处于第m2区间,且所述当前帧为第二帧间预测帧,则获取所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数;根据所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数修正所述当前帧的量化参数;其中,m2为大于等于1的正整数。In an exemplary embodiment, the modifying the quantization parameters of the nth encoding rate control stage of the video frame according to the (n-1)th encoding information of the video frame may include: if the video frame The peak signal-to-noise ratio of the (n-1)th luminance component and chrominance component of the current frame in the current frame is greater than the second threshold and is in the m2th interval, and the current frame is the second inter-frame prediction frame, then the current The quantization parameter of the forward reference frame of the frame and/or the quantization parameter of the backward parameter frame of the current frame; according to the quantization parameter of the forward reference frame of the current frame and/or the backward parameter frame of the current frame The quantization parameter of the current frame is modified by the quantization parameter; wherein, m2 is a positive integer greater than or equal to 1.
在示例性实施例中,所述第二阈值大于等于所述第一阈值,例如所述第二阈值可以取值为97。本发明实施例中,一方面可以采用相应的调控因子对低亮度帧的量化参数进行优化;另一方面,还可以采用当前帧的前向参考帧和/或后向参考帧的量化参数可以针对更低亮度帧甚至近似黑暗的场景的视频帧进行所述当前帧的量化参数的进一步优化处理。In an exemplary embodiment, the second threshold is greater than or equal to the first threshold, for example, the second threshold may be 97. In the embodiment of the present invention, on the one hand, corresponding control factors can be used to optimize the quantization parameters of low-brightness frames; on the other hand, the quantization parameters of the forward reference frame and/or backward reference frame of the current frame can be used to The quantization parameter of the current frame is further optimized for the lower brightness frame or even the video frame of an approximately dark scene.
在示例性实施例中,可以采用以下公式修正所述第二帧间预测帧的量化参数:In an exemplary embodiment, the quantization parameter of the second inter-frame prediction frame may be modified by using the following formula:
q’=q–((ref0Qp+c1)+(ref1Qp+c2))*d (2)q’=q–((ref0Qp+c1)+(ref1Qp+c2))*d (2)
其中,上述公式(2)中,ref0Qp为所述第二帧间预测帧的前向参考帧的量化参数;ref1Qp为所述第二帧间预测帧的后向参考帧的量化参数;c1、c2和d为常数,例如c1和c2可以相等,两者均取值为4,d可以取值为2,但本发明并不限定于此;q为所述第二帧间预测帧的量化参数;q’为所述第二帧间预测帧修正后的量化参数。Wherein, in the above formula (2), ref0Qp is the quantization parameter of the forward reference frame of the second inter-frame prediction frame; ref1Qp is the quantization parameter of the backward reference frame of the second inter-frame prediction frame; c1, c2 and d are constants, for example, c1 and c2 can be equal, both of which can take a value of 4, and d can take a value of 2, but the present invention is not limited thereto; q is the quantization parameter of the second inter-frame prediction frame; q' is a modified quantization parameter of the second inter-frame prediction frame.
本发明实施例中,由于H.261、H.263、H.264和MPEG2、MPEG4等编码标准均采用帧层码率控制算法来对视频进行压缩,所以本发明适用范围涵盖以上这些编码标准。In the embodiment of the present invention, since coding standards such as H.261, H.263, H.264, MPEG2, and MPEG4 all use the frame layer rate control algorithm to compress video, the scope of application of the present invention covers the above coding standards.
本发明实施方式提供的用于视频编码的方法,基于多路(包括两路)编码的方式,通过对视频序列进行前一路编码保留的前一路编码信息,可以对当前路编码的码率控制阶段的量化参数进行优化,从而可以弥补视频帧的质量波动以达到减少质量损失和减少波动的效果。特别是针对分布式编码中的低亮度视频帧这种局部特殊场景,可以有效的调整质量波动。The method for video encoding provided by the embodiment of the present invention is based on a multi-channel (including two-channel) encoding method, and the code rate control stage of the current channel encoding can be controlled by performing the previous encoding information on the video sequence and retaining the previous encoding information. The quantization parameters are optimized, so that the quality fluctuation of the video frame can be compensated to achieve the effect of reducing quality loss and reducing fluctuation. Especially for local special scenes such as low-brightness video frames in distributed coding, quality fluctuations can be effectively adjusted.
下面结合图4-7,并以视频序列采用两路编码为例,对上述实施例提供的用于视频编码的方法进行举例说明。The method for video encoding provided by the above embodiment will be illustrated below with reference to FIGS. 4-7 and taking two-way encoding as an example for a video sequence.
本发明实施例中,在进入第二路编码码率控制阶段的量化参数调整前,首先会对视频序列进行第一路编码(1pass编码)的第一路编码信息(例如第一路编码的onepassPSNR)的获取并存入分析文件file,并在所述视频文件的第二路编码(2pass)阶段进行所述一路编码信息的获取。具体的操作如流程图4和流程图5所示。In the embodiment of the present invention, before entering the quantization parameter adjustment of the second coding rate control stage, the first coding information (such as the onepassPSNR of the first coding) of the first coding (1pass coding) will be first performed on the video sequence ) is acquired and stored in the analysis file file, and the encoding information of one pass is acquired during the second pass encoding (2pass) stage of the video file. The specific operations are shown in
图4示出了图3中所示的步骤S310在一实施例中的处理过程示意图。本发明实施方式的方法步骤可以由终端设备执行,也可以由服务端执行,或者由终端设备和服务端交互执行,例如,可以由上述图1中的服务器105执行,但本发明并不限定于此。FIG. 4 shows a schematic diagram of a processing procedure of step S310 shown in FIG. 3 in an embodiment. The method steps in the embodiments of the present invention may be executed by a terminal device, or may be executed by a server, or may be executed interactively by a terminal device and a server, for example, may be executed by the
如图4所示,本发明实施方式中,上述步骤S310可以进一步包括以下步骤。As shown in FIG. 4 , in the implementation manner of the present invention, the above step S310 may further include the following steps.
在步骤S311中,判断视频序列是否存在;若视频序列存在,则进入步骤S312;反之,跳转到步骤S315结束本次操作。In step S311, determine whether the video sequence exists; if the video sequence exists, proceed to step S312; otherwise, jump to step S315 to end the operation.
在步骤S312中,判断所述视频序列当前是否为第一路编码(1pass编码);若是第一路编码,则进入步骤S313;反之,进入步骤S314。In step S312, it is judged whether the video sequence is currently the first-pass encoding (1pass encoding); if it is the first-pass encoding, proceed to step S313; otherwise, proceed to step S314.
在步骤S313中,对所述视频序列中的视频帧进行第一路编码(1pass编码)并收集所述视频帧的第一路编码信息。In step S313, a first-pass encoding (1-pass encoding) is performed on the video frames in the video sequence and first-pass encoding information of the video frames is collected.
在步骤S314中,输出错误信息。In step S314, an error message is output.
在步骤S315中,结束。In step S315, end.
图5示出了图3中所示的步骤S330在一实施例中的处理过程示意图。本发明实施方式的方法步骤可以由终端设备执行,也可以由服务端执行,或者由终端设备和服务端交互执行,例如,可以由上述图1中的服务器105执行,但本发明并不限定于此。FIG. 5 shows a schematic diagram of the processing process of step S330 shown in FIG. 3 in an embodiment. The method steps in the embodiments of the present invention may be executed by a terminal device, or may be executed by a server, or may be executed interactively by a terminal device and a server, for example, may be executed by the
如图5所示,本发明实施方式中,上述步骤S330可以进一步包括以下步骤。As shown in FIG. 5 , in the implementation manner of the present invention, the above step S330 may further include the following steps.
在步骤S331中,判断视频序列是否存在;若视频序列存在,则进入步骤S332;反之,跳转到步骤S336结束本次操作。In step S331, determine whether the video sequence exists; if the video sequence exists, proceed to step S332; otherwise, jump to step S336 to end this operation.
在步骤S332中,判断所述视频序列当前是否为第二路编码(2pass编码);若是第二路编码(2pass编码),则进入步骤S333;反之,进入步骤S335。In step S332, it is judged whether the video sequence is currently the second-pass encoding (2pass encoding); if it is the second-pass encoding (2pass encoding), proceed to step S333; otherwise, proceed to step S335.
本发明实施例中,2pass是2次编码的意思,fil分析文件,记录了1pass中的信息。2次编码就相当于2次转换,虽然转换时间会延长,但压缩出来的视频会有更好的画质,画面细节更好,而且体积会更小。2pass主要是针对非实时的视频编码如文件来说的,第一路编码是先对整个视频文件进行扫描,记录一些统计信息,第二路编码时根据前面记录的统计信息再进行编码,这样的好处是可以提高编码的质量。In the embodiment of the present invention, 2pass means 2 times of encoding, and fil analyzes the file and records the information in 1pass. Two encodings are equivalent to two conversions. Although the conversion time will be extended, the compressed video will have better image quality, better picture details, and smaller size. 2pass is mainly for non-real-time video encoding such as files. The first encoding is to scan the entire video file and record some statistical information. The second encoding is based on the previously recorded statistical information before encoding. The advantage is that the quality of the encoding can be improved.
在步骤S333中,判断是否存在第一路分析文件(file);若存在所述第一路分析文件,则进入步骤S334;反之,跳转到步骤S336结束本次操作。In step S333, it is judged whether there is a first path analysis file (file); if there is the first path analysis file, then go to step S334; otherwise, jump to step S336 to end this operation.
在步骤S334中,读取所述第一路分析文件,基于所述第一路分析文件对所述视频序列中的视频帧进行第二路编码。In step S334, the first path analysis file is read, and a second path of encoding is performed on the video frames in the video sequence based on the first path analysis file.
在步骤S335中,输出错误信息。In step S335, an error message is output.
在步骤S336中,结束。In step S336, end.
下面通过图6和图7分别对第二路编码码率控制阶段的量化参数进行修正的方案进行举例说明。The schemes of modifying the quantization parameters in the rate control stage of the second encoding pass are illustrated below with reference to FIG. 6 and FIG. 7 respectively.
需要说明的是,下述图6和图7中的方案可以结合起来对量化参数q进行优化,也可以仅采用图6或者图7中的一种方案对量化参数q进行优化,在下面的实施例中,以图6和图7中的方案结合起来对量化参数q进行优化为例进行说明。It should be noted that the following schemes in Figure 6 and Figure 7 can be combined to optimize the quantization parameter q, or only one of the schemes in Figure 6 or Figure 7 can be used to optimize the quantization parameter q, in the following implementation In the example, the optimization of the quantization parameter q by combining the schemes in FIG. 6 and FIG. 7 is taken as an example for illustration.
图6示意性示出了根据本发明的又一实施例的用于视频编码的方法的流程图。Fig. 6 schematically shows a flowchart of a method for video encoding according to yet another embodiment of the present invention.
本发明实施例中,通过分析多个视频序列数据和场景,得出基于第一路编码信息(YUV PSNR值)对视频帧进行进行一个人为的分类,例如,这里假设YUV PSNR值在0-60dB之间为普通的视频场景、61-89dB为较暗的视频场景、90-100dB划分为近似黑夜的视频场景,具体的流程图如图6所示。In the embodiment of the present invention, by analyzing multiple video sequence data and scenes, it is obtained that video frames are artificially classified based on the first encoding information (YUV PSNR value), for example, it is assumed here that the YUV PSNR value is between 0-60dB 61-89dB is a darker video scene, and 90-100dB is divided into a near-night video scene. The specific flow chart is shown in Figure 6.
需要说明的是,上述数值仅用于举例说明,实际应用中可以进行相应的调整。It should be noted that the above numerical values are only used for illustration, and corresponding adjustments can be made in practical applications.
本发明实施例中,在进行第二路编码码率控制编码的时候,首先获取第一路编码信息,然后在正式开始码率控制阶段的时候进行量化参数的调控。In the embodiment of the present invention, when performing the second code rate control coding, the first code information is obtained first, and then the quantization parameter is adjusted when the code rate control stage is formally started.
如图6所示,本发明实施方式提供的用于视频编码的方法可以包括以下步骤。本发明实施方式的方法步骤可以由终端设备执行,也可以由服务端执行,或者由终端设备和服务端交互执行,例如,可以由上述图1中的服务器105执行,但本发明并不限定于此。As shown in FIG. 6 , the method for video coding provided by the embodiment of the present invention may include the following steps. The method steps in the embodiments of the present invention may be executed by a terminal device, or may be executed by a server, or may be executed interactively by a terminal device and a server, for example, may be executed by the
在步骤S601中,判断视频序列中的当前帧是否IDR(Instantaneous DecodingRefresh,即时解码刷新)帧;若所述当前为IDR帧,则跳转到步骤S612;若所述当前帧不为IDR帧,则进入步骤S602。In step S601, determine whether the current frame in the video sequence is an IDR (Instantaneous Decoding Refresh, instant decoding refresh) frame; if the current frame is an IDR frame, then jump to step S612; if the current frame is not an IDR frame, then Go to step S602.
本发明实施例中,视频帧的帧类型可以包括I帧、P帧和B帧,其中IDR帧属于I帧中的一种情况。In the embodiment of the present invention, the frame types of the video frame may include I frame, P frame and B frame, wherein the IDR frame belongs to one of the I frames.
I帧为帧内编码帧,是一种自带全部信息的独立帧,无需参考其他图像便可独立进行解码,视频序列中的第一个帧始终都是I帧。I和IDR帧都是使用帧内预测的。在编码和解码中为了方便,为了把首个I帧和其他I帧区别开,把第一个I帧叫IDR帧,这样就方便控制编码和解码流程。An I-frame is an intra-coded frame, which is an independent frame with all its information, and can be decoded independently without referring to other images. The first frame in a video sequence is always an I-frame. Both I and IDR frames use intra prediction. For convenience in encoding and decoding, in order to distinguish the first I frame from other I frames, the first I frame is called an IDR frame, which is convenient for controlling the encoding and decoding process.
其中,IDR帧的作用是立刻刷新,使错误不致传播,从IDR帧开始,重新算一个新的序列开始编码。而I帧不具有随机访问的能力,这个功能是由IDR承担。IDR会导致DPB(Decoded Picture Buffer,参考帧列表)清空,而I不会。IDR帧一定是I帧,但I帧不一定是IDR帧。一个视频序列中可以有很多的I帧,I帧之后的视频帧可以引用I帧之间的视频帧做运动参考。Among them, the function of the IDR frame is to refresh immediately, so that the error will not be propagated. Starting from the IDR frame, a new sequence is recalculated to start encoding. The I frame does not have the ability of random access, this function is undertaken by the IDR. IDR will cause DPB (Decoded Picture Buffer, reference frame list) to be cleared, but I will not. An IDR frame must be an I frame, but an I frame is not necessarily an IDR frame. There may be many I frames in a video sequence, and the video frames after the I frame may refer to the video frames between the I frames as motion references.
对于IDR帧来说,在IDR帧之后的所有帧都不能引用任何IRD帧之前的帧的内容,与此相反,对于普通的I帧来说,位于其之后的B和P帧可以引用位于普通I帧之前的I帧。从随机存取的视频流中,播放器永远可以从一个IDR帧播放,因为在它之后没有任何帧引用之前的帧。但是,不能在一个没有IDR帧的视频中从任意点开始播放,因为后面的帧总是会引用前面的帧。For IDR frames, all frames after the IDR frame cannot refer to the content of any frame before the IRD frame. On the contrary, for ordinary I frames, the B and P frames located after it can refer to the content of the ordinary I The I frame before the frame. From a random access video stream, the player can always play from an IDR frame, because no frame after it refers to the previous frame. However, it is not possible to start playback from an arbitrary point in a video without an IDR frame, because subsequent frames will always refer to previous frames.
对IDR帧的处理与I帧的处理相同:进行帧内预测,决定所采用的帧内预测模式;像素值减去预测值,得到残差;对残差进行变换和量化;变长编码和算术编码;重构图像并滤波,得到的图像作为其它帧的参考帧。The processing of the IDR frame is the same as that of the I frame: perform intra-frame prediction, determine the intra-frame prediction mode used; subtract the predicted value from the pixel value to obtain the residual; transform and quantize the residual; variable length coding and arithmetic Coding; reconstructing the image and filtering, and the obtained image is used as a reference frame for other frames.
需要说明的是,本发明实施例中,均以IDR作为判断当前帧是否为场景切换帧的标识,但本发明并不限定于此。It should be noted that, in the embodiments of the present invention, the IDR is used as an identifier for judging whether the current frame is a scene switching frame, but the present invention is not limited thereto.
本发明实施例中,首先判断当前帧的帧类型是否为IDR帧,如果是IDR帧则进入编码器默认操作,此时不对所述当前帧的量化参数q进行调整;否则,接下来判断当前帧对应在一路编码中的YUV PSNR值。In the embodiment of the present invention, first judge whether the frame type of the current frame is an IDR frame, if it is an IDR frame, enter the default operation of the encoder, and do not adjust the quantization parameter q of the current frame at this time; otherwise, judge the current frame next Corresponding to the YUV PSNR value in one encoding.
在步骤S602中,判断所述当前帧的第一路编码信息中的YUV PSNR值onepassPSNR是否大于97且小于等于100;若所述当前帧的97<onepassPSNR≤100,则跳转到步骤S611;若所述当前帧不满足97<onepassPSNR≤100,则进入步骤S603。In step S602, it is judged whether the YUV PSNR value onepassPSNR in the first coded information of the current frame is greater than 97 and less than or equal to 100; if 97<onepassPSNR≤100 of the current frame, then jump to step S611; if If the current frame does not satisfy 97<onepassPSNR≤100, go to step S603.
在步骤S603中,判断所述当前帧的第一路编码信息中的YUV PSNR值onepassPSNR是否大于90且小于等于97;若所述当前帧的90<onepassPSNR≤97,则跳转到步骤S610;若所述当前帧不满足90<onepassPSNR≤97,则进入步骤S604。In step S603, it is judged whether the YUV PSNR value onepassPSNR in the first coded information of the current frame is greater than 90 and less than or equal to 97; if 90<onepassPSNR≤97 of the current frame, then jump to step S610; if If the current frame does not satisfy 90<onepassPSNR≤97, go to step S604.
在步骤S604中,判断所述当前帧的第一路编码信息中的YUV PSNR值onepassPSNR是否大于85且小于等于90;若所述当前帧的85<onepassPSNR≤90,则跳转到步骤S609;若所述当前帧不满足85<onepassPSNR≤90,则进入步骤S605。In step S604, it is judged whether the YUV PSNR value onepassPSNR in the first coded information of the current frame is greater than 85 and less than or equal to 90; if 85<onepassPSNR≤90 of the current frame, then jump to step S609; if If the current frame does not satisfy 85<onepassPSNR≤90, go to step S605.
在步骤S605中,判断所述当前帧的第一路编码信息中的YUV PSNR值onepassPSNR是否大于70且小于等于85;若所述当前帧的70<onepassPSNR≤85,则跳转到步骤S608;若所述当前帧不满足70<onepassPSNR≤85,则进入步骤S606。In step S605, it is judged whether the YUV PSNR value onepassPSNR in the first coded information of the current frame is greater than 70 and less than or equal to 85; if 70<onepassPSNR≤85 of the current frame, then jump to step S608; if If the current frame does not satisfy 70<onepassPSNR≤85, go to step S606.
在步骤S606中,判断所述当前帧的第一路编码信息中的YUV PSNR值onepassPSNR是否大于60且小于等于70;若所述当前帧的60<onepassPSNR≤70,则跳转到步骤S607;若所述当前帧不满足60<onepassPSNR≤70,则进入步骤S612。In step S606, it is judged whether the YUV PSNR value onepassPSNR in the first coded information of the current frame is greater than 60 and less than or equal to 70; if 60<onepassPSNR≤70 of the current frame, then jump to step S607; if If the current frame does not satisfy 60<onepassPSNR≤70, go to step S612.
在步骤S607中,60<onepassPSNR≤70,q’=q-qFactor1,之后进入步骤S612进入其他编码阶段。In step S607, 60<onepassPSNR≤70, q'=q-qFactor1, then enter step S612 to enter other encoding stages.
本发明实施例中,当onepassPSNR在(60,70]区间时,q’=q-qFactor1。In the embodiment of the present invention, when the onepassPSNR is in the (60,70] interval, q'=q-qFactor1.
其中,q为二路编码码率控制阶段的量化参数;q’为修正后的二路编码码率控制阶段的量化参数。需要说明的是,如果当前视频序列采用n路编码,则q为n路编码码率控制阶段的量化参数,相应的onepassPSNR修改为(n-1)passPNSR即第(n-1)路编码的YUV PSNR值。Among them, q is the quantization parameter of the two-way coding rate control stage; q' is the quantization parameter of the modified two-way coding rate control stage. It should be noted that if the current video sequence adopts n-pass encoding, then q is the quantization parameter of the n-pass encoding rate control stage, and the corresponding onepassPSNR is modified to (n-1)passPNSR, which is the YUV of the (n-1)th encoding PSNR value.
在步骤S608中,70<onepassPSNR≤85,q’=q-qFactor2,之后进入步骤S612进入其他编码阶段。In step S608, 70<onepassPSNR≤85, q'=q-qFactor2, then enter step S612 to enter other encoding stages.
本发明实施例中,当onepassPSNR在(70,85]区间时,q’=q-qFactor2。In the embodiment of the present invention, when the onepassPSNR is in the (70,85] interval, q'=q-qFactor2.
在步骤S609中,85<onepassPSNR≤90,q’=q-qFactor3,之后进入步骤S612进入其他编码阶段。In step S609, 85<onepassPSNR≤90, q'=q-qFactor3, then enter step S612 to enter other encoding stages.
本发明实施例中,当onepassPSNR在(85,90]区间时,q’=q-qFactor3。In the embodiment of the present invention, when the onepassPSNR is in the (85,90] interval, q'=q-qFactor3.
在步骤S610中,90<onepassPSNR≤97,q’=q-qFactor4,之后进入步骤S612进入其他编码阶段。In step S610, 90<onepassPSNR≤97, q'=q-qFactor4, then enter step S612 to enter other encoding stages.
本发明实施例中,当onepassPSNR在(90,97]区间时,q’=q-qFactor4。In the embodiment of the present invention, when the onepassPSNR is in the (90,97] interval, q'=q-qFactor4.
在步骤S611中,97<onepassPSNR≤100,q’=q-qFactor5,之后进入步骤S612进入其他编码阶段。In step S611, 97<onepassPSNR≤100, q'=q-qFactor5, then enter step S612 to enter other encoding stages.
本发明实施例中,当onepassPSNR在(97,100]区间时,q’=q-qFactor5。In the embodiment of the present invention, when the onepassPSNR is in the (97,100] interval, q'=q-qFactor5.
需要说明的是,实际情况中,onepassPSNR值并不是整数,一般编码时,onepassPSNR值是double类型的,小数点后面还有两位,所以虽然本发明实施例中对onepassPSNR值的区间划分以整数例如100、97、90、85、70、60为例作为端点值,但这种划分只是一种近似取值。It should be noted that, in actual situations, the value of onepassPSNR is not an integer. In general encoding, the value of onepassPSNR is of double type, and there are two digits after the decimal point. Therefore, although the interval division of the value of onepassPSNR in the embodiment of the present invention is divided into integers such as 100 , 97, 90, 85, 70, and 60 are taken as the endpoint values, but this division is only an approximate value.
本发明实施例中,qFactor1-qFactor5qFactor为根据统计分析获得的优化经验值,例如,qFactor1到qFactor5取值可以分别为1.2,1.8,2.2,3,4.5。但本发明并不限定于此。In the embodiment of the present invention, qFactor1-qFactor5qFactor are optimized empirical values obtained according to statistical analysis, for example, the values of qFactor1 to qFactor5 may be 1.2, 1.8, 2.2, 3, 4.5 respectively. However, the present invention is not limited thereto.
在步骤S612中,其他编码阶段。In step S612, another encoding stage.
在步骤S613中,结束。In step S613, end.
图7示意性示出了根据本发明的再一实施例的用于视频编码的方法的流程图。Fig. 7 schematically shows a flowchart of a method for video encoding according to yet another embodiment of the present invention.
如图7所示,本发明实施方式提供的用于视频编码的方法还可以包括以下步骤。本发明实施方式的方法步骤可以由终端设备执行,也可以由服务端执行,或者由终端设备和服务端交互执行,例如,可以由上述图1中的服务器105执行,但本发明并不限定于此。As shown in FIG. 7 , the method for video encoding provided by the embodiment of the present invention may further include the following steps. The method steps in the embodiments of the present invention may be executed by a terminal device, or may be executed by a server, or may be executed interactively by a terminal device and a server, for example, may be executed by the
在步骤S701中,判断视频序列中当前帧的第一路编码信息中的YUV PSNR值onepassPSNR是否大于97且小于等于100且为第二路编码;若所述当前帧的97<onepassPSNR≤100且为第二路编码,则进入步骤S702;若所述当前帧不满足97<onepassPSNR≤100或者不为第二路编码,则进入步骤S709结束本次操作。In step S701, it is judged whether the YUV PSNR value onepassPSNR in the first coding information of the current frame in the video sequence is greater than 97 and less than or equal to 100 and is the second coding; if 97<onepassPSNR≤100 of the current frame is For the second pass of encoding, proceed to step S702; if the current frame does not satisfy 97<onepassPSNR≤100 or is not for the second pass of encoding, proceed to step S709 to end this operation.
本发明实施例中,通过分析多个视频序列数据,onePassPSNR在区间(97,100)之间且当前编码为非一路编码(这里以二路编码为例)时候,采用上述图6所述方法对这类视频帧优化后,质量波动仍可以进一步改善。因此,当此类视频帧非场景切换帧(这里以IDR帧为例,但本发明并不限定于此)之时,使用此类视频帧的参考帧(例如前向参考帧和/或后向参考帧)的信息,可以对此类视频帧的量化参数进一步优化。In the embodiment of the present invention, by analyzing a plurality of video sequence data, when the onePassPSNR is in the interval (97,100) and the current encoding is non-one-way encoding (here, two-way encoding is used as an example), the method described in the above-mentioned Figure 6 is used for this type of After video frame optimization, quality fluctuations can still be further improved. Therefore, when such video frames are non-scene switching frames (here, IDR frames are taken as an example, but the present invention is not limited thereto), reference frames (such as forward reference frames and/or backward reference frames) of such video frames are used Reference frame) information, the quantization parameters of such video frames can be further optimized.
本发明实施例中,当前帧的参考帧并非仅可以参考前后几帧,在此类型的编码器中,参考帧最长例如可以是参考前后16帧,因此采用图7所示方法在调整此类场景的视频帧时能够起到一定的效果。In the embodiment of the present invention, the reference frame of the current frame can not only refer to several frames before and after. In this type of encoder, the longest reference frame can be, for example, 16 frames before and after reference. The video frame time of the scene can play a certain effect.
本发明实施例中,在进行第二路编码码率控制编码的时候,首先获取第一路编码信息,然后在正式开始第二路编码码率控制阶段的时候进行量化参数的调控。In the embodiment of the present invention, when the rate control encoding of the second encoding is performed, the encoding information of the first encoding is obtained first, and then the quantization parameter is adjusted when the rate control stage of the second encoding is formally started.
本发明实施例中,首先判断当前帧的onePassPSNR区间范围是否在(97,100]的区间内。In the embodiment of the present invention, it is first judged whether the range of the onePassPSNR interval of the current frame is within the interval of (97,100].
在步骤S702中,判断所述当前帧是否帧间预测帧;若所述当前帧为帧间预测帧,则进入步骤S703;若所述当前帧不为帧间预测帧,则跳转至步骤S708。In step S702, determine whether the current frame is an inter-frame prediction frame; if the current frame is an inter-frame prediction frame, proceed to step S703; if the current frame is not an inter-frame prediction frame, then jump to step S708 .
本发明实施例中,若所述当前帧的onePassPSNR区间范围在(97,100]的区间内,接着判断所述当前帧是否做帧间预测;如果所述当前帧不是做帧间预测,则所述当前帧是做帧内预测,此时保持当前帧的q值不变。In the embodiment of the present invention, if the onePassPSNR interval of the current frame is within the interval (97,100], then it is judged whether the current frame performs inter-frame prediction; if the current frame does not perform inter-frame prediction, the current The frame is for intra-frame prediction, and the q value of the current frame remains unchanged at this time.
需要说明的是,这里所述的所述当前帧是做帧内预测,此时保持当前帧的q值不变,并不意味着q值一定是视频编码器初始预设值的量化参数,如果同时采用图6和图7所述方法对所述视频序列进行处理,则所述当前帧的量化参数q已经经过上述图6所述方法的处理,即97<onepassPSNR≤100,q’=q-qFactor5。It should be noted that the current frame described here is for intra-frame prediction, and keeping the q value of the current frame unchanged at this time does not mean that the q value must be the quantization parameter of the initial preset value of the video encoder. If Simultaneously adopt the method described in Figure 6 and Figure 7 to process the video sequence, then the quantization parameter q of the current frame has been processed by the method described in Figure 6 above, that is, 97<onepassPSNR≤100, q'=q- qFactor5.
在步骤S703中,判断所述当前帧是否为P帧;若所述当前帧为P帧,则进入步骤S704;若所述当前帧不为P帧,则跳转至步骤S706。In step S703, determine whether the current frame is a P frame; if the current frame is a P frame, proceed to step S704; if the current frame is not a P frame, proceed to step S706.
本发明实施例中,若所述当前帧为帧间预测帧,则进一步判断当前帧是帧间P帧还是B帧。In the embodiment of the present invention, if the current frame is an inter-frame prediction frame, it is further judged whether the current frame is an inter-frame P frame or a B frame.
其中,P帧为前向预测编码帧。在针对连续动态图像编码时,将连续若干幅图像分成P、B、I三种类型,P帧由在它前面的P帧或者I帧预测而来,它比较与它前面的P帧或者I帧之间的相同信息或数据,也即考虑运动的特性进行帧间压缩。P帧法是根据本帧与相邻的前一帧I帧或P帧的不同点来压缩本帧数据。采取P帧和I帧联合压缩的方法可达到更高的压缩且无明显的压缩痕迹。Wherein, the P frame is a forward predictive coding frame. When encoding continuous dynamic images, several consecutive images are divided into three types: P, B, and I. The P frame is predicted from the P frame or I frame in front of it, and it is compared with the P frame or I frame in front of it. The same information or data between frames, that is, considering the characteristics of motion for inter-frame compression. The P frame method is to compress the data of this frame according to the difference between this frame and the adjacent previous frame I frame or P frame. The joint compression method of P frame and I frame can achieve higher compression without obvious compression trace.
其中,P帧是以I帧为参考帧,在I帧中找出P帧“某点”预测值和运动矢量,取预测差值和运动矢量一起传送。在接收端根据运动矢量从I帧中找出P帧某点的预测值并与差值相加以得到P帧某点样值,从而可得到完整的P帧。Among them, the P frame uses the I frame as the reference frame, finds out the predictive value and motion vector of the "certain point" of the P frame in the I frame, and transmits the predicted difference value and the motion vector together. At the receiving end, find out the predicted value of a certain point of the P frame from the I frame according to the motion vector and add it to the difference to obtain the sample value of a certain point of the P frame, so as to obtain a complete P frame.
在步骤S704中,判断所述当前帧是否存在前向参考帧;若所述当前帧存在前向参考帧,则进入步骤S705;若所述当前帧不存在前向参考帧,则跳转至步骤S709结束本次操作。In step S704, it is judged whether there is a forward reference frame in the current frame; if there is a forward reference frame in the current frame, then enter step S705; if there is no forward reference frame in the current frame, then jump to step S709 ends this operation.
本发明实施例中,参考帧就是IPB编码时所需参考的帧。参考帧和IPB的关系,需要知道每种帧类型的编码方式。其中,I帧参考本图像内的块编码,不需要参考帧。P帧参考前面的I帧或P帧来编码,参考帧都是前向的。B帧参考前面的和后面的I帧或P帧编码,例如可以前后各一帧,或者只是前向参考帧或后向参考帧(三种任选)。In the embodiment of the present invention, the reference frame is a frame that needs to be referred to during IPB encoding. Referring to the relationship between frames and IPB, it is necessary to know the encoding method of each frame type. Wherein, the I frame refers to the coding of the block in the image, and does not need a reference frame. The P frame is coded with reference to the previous I frame or P frame, and the reference frames are all forward. The B frame is coded with reference to the previous and subsequent I frame or P frame, for example, one frame before and after each, or only a forward reference frame or a backward reference frame (three options).
在步骤S705中,若所述当前帧为P帧,则可以采用以下公式对所述当前帧的量化参数q进行调整:In step S705, if the current frame is a P frame, the quantization parameter q of the current frame can be adjusted by using the following formula:
ref0Qp’=ref0Qp+4,ref0Qp'=
q’=q-ref0Qp’*2,q'=q-ref0Qp'*2,
本发明实施例中,若所述当前帧是帧间P帧,获取refSlice0的ref0Qp值;若所述当前帧帧间的B帧,获取refSlice0和refSlice1的ref0Qp和ref1Qp值。In the embodiment of the present invention, if the current frame is an inter-frame P frame, obtain the ref0Qp value of refSlice0; if the current frame is an inter-frame B frame, obtain the ref0Qp and ref1Qp values of refSlice0 and refSlice1.
其中,refSlice0表示所述当前帧的前向参考帧;ref0Qp表示refSlice0量化参数即QP值。Wherein, refSlice0 represents the forward reference frame of the current frame; ref0Qp represents the quantization parameter of refSlice0, that is, the QP value.
在步骤S706中,若所述当前帧为B帧,则判断所述当前参考是否存在前向参考帧和/或后向参考帧;若所述当前参考存在前向参考帧和/或后向参考帧,则进入步骤S707;若所述当前参考不存在前向参考帧和/或后向参考帧,则跳转至步骤S709结束本次操作。In step S706, if the current frame is a B frame, it is judged whether the current reference has a forward reference frame and/or a backward reference frame; if the current reference has a forward reference frame and/or a backward reference frame frame, go to step S707; if the current reference does not have a forward reference frame and/or a backward reference frame, go to step S709 to end this operation.
本发明实施例中,若所述当前帧为帧间预测的B帧且所述当前帧同时存在前向参考帧和后向参考帧,则获取refSlice0和refSlice1的ref0Qp和ref1Qp值。In the embodiment of the present invention, if the current frame is an inter-frame predicted B frame and the current frame has both a forward reference frame and a backward reference frame, the ref0Qp and ref1Qp values of refSlice0 and refSlice1 are obtained.
其中,refSlice0和refSlice1分别为所述当前帧的前向参考帧和后向参考帧;ref0Qp和ref1Qp分别表示refSlice0和refSlice1的量化参数即QP值。Wherein, refSlice0 and refSlice1 are the forward reference frame and the backward reference frame of the current frame respectively; ref0Qp and ref1Qp respectively represent the quantization parameters of refSlice0 and refSlice1 ie QP values.
本发明实施例中,有的视频序列比较简单,就可能没有B帧。In the embodiment of the present invention, some video sequences may not have B frames because they are relatively simple.
其中,B帧为双向预测内插编码帧。B帧法是双向预测的帧间压缩算法。当把一帧压缩成B帧时,它根据相邻的前一帧、本帧以及后一帧数据的不同点来压缩本帧,也即仅记录本帧与前后帧的差值。采用B帧压缩能达到高压缩。B帧是以前面的I帧或P帧和后面的P帧为参考帧,找出B帧“某点”的预测值和两个运动矢量,并取预测差值和运动矢量传送。接收端根据运动矢量在两个参考帧中。Wherein, the B frame is a bidirectional predictive interpolation coded frame. The B-frame method is a two-way predictive inter-frame compression algorithm. When compressing a frame into a B frame, it compresses this frame according to the difference between the data of the adjacent previous frame, this frame, and the next frame, that is, only records the difference between this frame and the preceding and following frames. High compression can be achieved by using B-frame compression. The B frame uses the previous I frame or P frame and the following P frame as reference frames to find out the predicted value and two motion vectors of "a certain point" in the B frame, and take the prediction difference and the motion vector for transmission. The receiver is in two reference frames according to the motion vector.
在步骤S707中,本发明实施例中,若所述当前帧为帧间预测的B帧且所述当前帧同时存在前向参考帧和后向参考帧,可以采用以下公式对所述当前帧的量化参数q进行修正:In step S707, in the embodiment of the present invention, if the current frame is an inter-frame predicted B frame and the current frame has a forward reference frame and a backward reference frame at the same time, the following formula can be used for the current frame The quantization parameter q is corrected:
ref0Qp’=ref0Qp+4ref0Qp'=
ref1Qp’=ref1Qp+4ref1Qp'=
combine_ref=(ref0Qp’+ref1Qp’)*2combine_ref=(ref0Qp'+ref1Qp')*2
q’=q-combine_ref,q'=q-combine_ref,
其中,combine_ref表示,如果当前帧是B帧且前后向参考帧都存在时的所述当前帧的量化参数的调优常数。Wherein, combine_ref represents an tuning constant of the quantization parameter of the current frame if the current frame is a B frame and both forward and backward reference frames exist.
需要说明的是,上述步骤中均是以当前帧的一个前向参考帧和/或一个后向参考帧为例进行举例说明,但在其他实施例中,所述当前帧可能同时存在多个前向参考帧和/或多个后向参考帧,此时,也可以根据所述当前帧的多个前向参考帧和/或多个后向参考帧的量化参数对所述当前帧的量化参数进行优化,本发明对此不作限定。It should be noted that, the above steps all take a forward reference frame and/or a backward reference frame of the current frame as an example for illustration, but in other embodiments, there may be multiple previous reference frames in the current frame A forward reference frame and/or a plurality of backward reference frames, at this time, the quantization parameters of the current frame may also be determined according to the quantization parameters of the multiple forward reference frames and/or the multiple backward reference frames of the current frame optimization, which is not limited by the present invention.
在步骤S708中,若所述当前帧为帧内预测帧,q不变。In step S708, if the current frame is an intra-frame predicted frame, q remains unchanged.
在步骤S709中,结束。In step S709, end.
本发明实施例中,可以通过SSIM来衡量视频序列的质量波动,即SSIM标准差越小,SSIM平均值越大,则认为相应的视频序列的质量波动越小。In the embodiment of the present invention, the quality fluctuation of the video sequence can be measured by SSIM, that is, the smaller the standard deviation of the SSIM and the larger the average value of the SSIM, the smaller the quality fluctuation of the corresponding video sequence.
其中,SSIM(Structual Ssimilarity,结构相似性),也是一种全参考的图像质量评价指标,它分别从亮度、对比度、结构三方面度量图像相似性。SSIM取值范围[0,1],值越大,表示图像失真越小。Among them, SSIM (Structual Ssimilarity) is also a full-reference image quality evaluation index, which measures image similarity from three aspects: brightness, contrast, and structure. The value range of SSIM is [0,1]. The larger the value, the smaller the image distortion.
实际测试中,以测试序列1和测试序列2为例采用上述方法对视频序列进行优化,具体效果如下表所示:In the actual test, taking
根据上表的测试结果可以看出,视频序列切片后采用本发明实施方式提供的方法优化后,其对应低亮度视频帧的位置处的SSIM标准差小于原始未切片的视频序列相应位置的SSIM标准差;同时,对应于局部出现场景较暗的区域的视频帧位置的SSIM平均值,视频序列切片后采用本发明实施方式提供的方法优化后,其SSIM平均值大于原始未切片视频序列对应位置的SSIM平均值。由此可知,本发明实施方式提供的用于视频编码的方法是可行的,可以在加快视频编解码速度的同时,保证视频质量;优化了视频点播和直播平台,给用户带来更好的视觉体验。According to the test results in the above table, it can be seen that after the video sequence is sliced and optimized by the method provided by the embodiment of the present invention, the SSIM standard deviation at the position corresponding to the low-brightness video frame is smaller than the SSIM standard deviation at the corresponding position of the original unsliced video sequence At the same time, corresponding to the SSIM average value of the video frame position in the darker region of the local scene, after the video sequence is sliced and optimized by the method provided by the embodiment of the present invention, its SSIM average value is greater than that of the corresponding position of the original unsliced video sequence SSIM average. It can be seen from this that the method for video encoding provided by the embodiment of the present invention is feasible, and can ensure video quality while speeding up video encoding and decoding; optimize the video-on-demand and live broadcast platforms, and bring better visual experience to users. experience.
图8示意性示出了根据本发明的一实施例的用于视频编码的装置的框图。Fig. 8 schematically shows a block diagram of a device for video encoding according to an embodiment of the present invention.
本发明实施方式提供的用于视频编码的装置800,视频序列可以采用n路编码。其中,n为大于等于2的正整数。In the
如图8所示,本发明实施方式提供的用于视频编码的装置800可以包括:第一编码模块810、量化参数获取模块820以及第二编码模块830。As shown in FIG. 8 , an
其中,第一编码模块810可以配置为对所述视频序列进行第(n-1)路编码生成第(n-1)路分析文件,并获得所述视频序列中视频帧的第(n-1)路编码信息。Wherein, the
在示例性实施例中,所述第(n-1)路编码信息包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比。In an exemplary embodiment, the (n-1)th channel of encoding information includes the peak signal-to-noise ratio of the (n-1)th channel of luminance component and chrominance component of the video frame.
量化参数获取模块820可以配置为获取所述视频帧的第n路编码码率控制阶段的量化参数。The quantization
第二编码模块830可以配置为基于所述第(n-1)路分析文件对所述视频序列进行第n路编码,并根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数。The
本发明实施例提供的用于视频编码的装置中的各个模块的具体实现可以参照上述用于视频编码的方法中的内容,在此不再赘述。For specific implementation of each module in the device for video coding provided in the embodiment of the present invention, reference may be made to the content in the method for video coding above, and details are not repeated here.
图9示意性示出了根据本发明的又一实施例的用于视频编码的装置的框图。Fig. 9 schematically shows a block diagram of an apparatus for video encoding according to yet another embodiment of the present invention.
如图9所示,本发明实施方式提供的用于视频编码的装置900可以包括:第一编码模块910、量化参数获取模块920以及第二编码模块930。As shown in FIG. 9 , an
其中,第一编码模块910可以配置为对所述视频序列进行第(n-1)路编码生成第(n-1)路分析文件,并获得所述视频序列中视频帧的第(n-1)路编码信息。Wherein, the
在示例性实施例中,所述第(n-1)路编码信息包括所述视频帧的第(n-1)路亮度分量和色度分量峰值信噪比。In an exemplary embodiment, the (n-1)th channel of encoding information includes the peak signal-to-noise ratio of the (n-1)th channel of luminance component and chrominance component of the video frame.
量化参数获取模块920可以配置为获取所述视频帧的第n路编码码率控制阶段的量化参数。The quantization
其中,第一编码模块910和量化参数获取模块920可以参照上述图8所示实施例中的第一编码模块810和量化参数获取模块820。Wherein, the
第二编码模块930可以配置为基于所述第(n-1)路分析文件对所述视频序列进行第n路编码,并根据所述视频帧的第(n-1)路编码信息修正所述视频帧的第n路编码码率控制阶段的量化参数。The
在示例性实施例中,第二编码模块930可以进一步包括:第n路编码单元(图中未示出)。其中,所述第n路编码单元可以配置为基于所述第(n-1)路分析文件对所述视频序列进行第n路编码。In an exemplary embodiment, the
在图9所示实施例中,第二编码模块930还可以包括第一量化参数修正单元931。其中,第一量化参数修正单元931可以配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第一阈值且所述当前帧非场景切换帧,则根据所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比修正所述当前帧的量化参数。In the embodiment shown in FIG. 9 , the
继续参考图9,第一量化参数修正单元931可以包括:第一量化参数修正子单元9311。其中,第一量化参数修正子单元9311可以配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第一阈值且所述当前帧非场景切换帧,且所述当前帧的第(n-1)路亮度分量和色度分量峰值信噪比处于第1区间至第m1区间中的任意一个,则采用相应的调控因子修正所述当前帧的量化参数;其中,m1为大于等于1的正整数。With continued reference to FIG. 9 , the first quantization
继续参考图9,第二编码模块930还可以包括:第二量化参数修正单元932和/或第三量化参数修正单元933。Continuing to refer to FIG. 9 , the
其中,第二量化参数修正单元932可以配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于第二阈值且处于第m2区间,且所述当前帧为第一帧间预测帧,则获取所述当前帧的前向参考帧的量化参数;根据所述前向参考帧的量化参数修正所述当前帧的量化参数;和/或Wherein, the second quantization
第三量化参数修正单元933可以配置为若所述视频帧中的当前帧的第(n-1)路亮度分量和色度分量峰值信噪比大于所述第二阈值且处于第m2区间,且所述当前帧为第二帧间预测帧,则获取所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数;根据所述当前帧的前向参考帧的量化参数和/或所述当前帧的后向参数帧的量化参数修正所述当前帧的量化参数;其中,m2为大于等于1的正整数。The third quantization
在示例性实施例中,所述第二阈值大于所述第一阈值。In an exemplary embodiment, the second threshold is greater than the first threshold.
本发明实施例提供的用于视频编码的装置中的各个模块和/或单元和/或子单元的具体实现可以参照上述用于视频编码的方法中的内容,在此不再赘述。For the specific implementation of each module and/or unit and/or subunit in the device for video coding provided by the embodiment of the present invention, reference may be made to the content in the method for video coding above, and details are not repeated here.
应当注意,尽管在上文详细描述中提及了用于动作执行的设备的若干模块或者单元或者子单元,但是这种划分并非强制性的。实际上,根据本发明的实施方式,上文描述的两个或更多模块或者单元或者子单元的特征和功能可以在一个模块或者单元或者子单元中具体化。反之,上文描述的一个模块或者单元或者子单元的特征和功能可以进一步划分为由多个模块或者单元或者子单元来具体化。It should be noted that although several modules or units or subunits of the device for action execution are mentioned in the above detailed description, this division is not mandatory. Actually, according to the embodiment of the present invention, the features and functions of two or more modules or units or subunits described above may be embodied in one module or unit or subunit. Conversely, the features and functions of one module or unit or subunit described above can be further divided to be embodied by multiple modules or units or subunits.
通过以上的实施方式的描述,本领域的技术人员易于理解,这里描述的示例实施方式可以通过软件实现,也可以通过软件结合必要的硬件的方式来实现。因此,根据本发明实施方式的技术方案可以以软件产品的形式体现出来,该软件产品可以存储在一个非易失性存储介质(可以是CD-ROM,U盘,移动硬盘等)中或网络上,包括若干指令以使得一台计算设备(可以是个人计算机、服务器、触控终端、或者网络设备等)执行根据本发明实施方式的方法。Through the description of the above implementations, those skilled in the art can easily understand that the example implementations described here can be implemented by software, or by combining software with necessary hardware. Therefore, the technical solution according to the embodiment of the present invention can be embodied in the form of a software product, and the software product can be stored in a non-volatile storage medium (which can be a CD-ROM, U disk, mobile hard disk, etc.) or on a network , including several instructions to make a computing device (which may be a personal computer, a server, a touch terminal, or a network device, etc.) execute the method according to the embodiment of the present invention.
本领域技术人员在考虑说明书及实践这里公开的发明后,将容易想到本发明的其它实施方案。本申请旨在涵盖本发明的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本发明的一般性原理并包括本发明未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本发明的真正范围和精神由下面的权利要求指出。Other embodiments of the invention will be readily apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any modification, use or adaptation of the present invention, these modifications, uses or adaptations follow the general principles of the present invention and include common knowledge or conventional technical means in the technical field not disclosed in the present invention . The specification and examples are to be considered exemplary only, with a true scope and spirit of the invention being indicated by the following claims.
应当理解的是,本发明并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本发明的范围仅由所附的权利要求来限制。It should be understood that the present invention is not limited to the precise constructions which have been described above and shown in the accompanying drawings, and various modifications and changes may be made without departing from the scope thereof. The scope of the invention is limited only by the appended claims.
Claims (13)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810726552.9A CN108810545B (en) | 2018-07-04 | 2018-07-04 | Method, apparatus, computer readable medium and electronic device for video encoding |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810726552.9A CN108810545B (en) | 2018-07-04 | 2018-07-04 | Method, apparatus, computer readable medium and electronic device for video encoding |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108810545A CN108810545A (en) | 2018-11-13 |
CN108810545B true CN108810545B (en) | 2023-04-18 |
Family
ID=64074584
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810726552.9A Active CN108810545B (en) | 2018-07-04 | 2018-07-04 | Method, apparatus, computer readable medium and electronic device for video encoding |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108810545B (en) |
Families Citing this family (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109640114A (en) * | 2018-12-12 | 2019-04-16 | 深圳市网心科技有限公司 | Video compiles transcoding compression method, device, equipment and computer readable storage medium |
CN110536134B (en) * | 2019-09-27 | 2022-11-04 | 腾讯科技(深圳)有限公司 | Video encoding method, video decoding method, video encoding apparatus, video decoding apparatus, storage medium, and electronic apparatus |
CN111093095A (en) * | 2019-12-16 | 2020-05-01 | 黔南民族师范学院 | Video transcoding method and system based on spark platform |
CN112468764B (en) * | 2021-01-28 | 2021-05-04 | 浙江华创视讯科技有限公司 | Method, system, server and storage medium for streaming media adaptive transmission |
CN112989934B (en) * | 2021-02-05 | 2024-05-24 | 方战领 | Video analysis method, device and system |
CN112953944A (en) * | 2021-02-23 | 2021-06-11 | 北京华宇信息技术有限公司 | Audio-video transcoding method based on MapReduce |
CN114051139B (en) * | 2021-11-09 | 2024-02-02 | 京东科技信息技术有限公司 | Video coding method and device |
CN113784123B (en) * | 2021-11-11 | 2022-03-15 | 腾讯科技(深圳)有限公司 | Video encoding method and apparatus, storage medium, and electronic device |
CN116055738B (en) * | 2022-05-30 | 2023-10-20 | 荣耀终端有限公司 | Video compression method and electronic equipment |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101547349A (en) * | 2009-04-27 | 2009-09-30 | 宁波大学 | Method for controlling code rate of secondary AVS encoding of video signal |
CN102067610A (en) * | 2008-06-16 | 2011-05-18 | 杜比实验室特许公司 | Rate control model adaptation based on slice dependencies for video coding |
CN102714725A (en) * | 2010-01-06 | 2012-10-03 | 杜比实验室特许公司 | High performance rate control for multi-layered video coding applications |
CN104159109A (en) * | 2014-05-28 | 2014-11-19 | 百视通网络电视技术发展有限责任公司 | Bit rate control method and system based on VBR video encoding |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
TWI254879B (en) * | 2004-12-17 | 2006-05-11 | Quanta Comp Inc | System and method for video encoding |
-
2018
- 2018-07-04 CN CN201810726552.9A patent/CN108810545B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102067610A (en) * | 2008-06-16 | 2011-05-18 | 杜比实验室特许公司 | Rate control model adaptation based on slice dependencies for video coding |
CN101547349A (en) * | 2009-04-27 | 2009-09-30 | 宁波大学 | Method for controlling code rate of secondary AVS encoding of video signal |
CN102714725A (en) * | 2010-01-06 | 2012-10-03 | 杜比实验室特许公司 | High performance rate control for multi-layered video coding applications |
CN104159109A (en) * | 2014-05-28 | 2014-11-19 | 百视通网络电视技术发展有限责任公司 | Bit rate control method and system based on VBR video encoding |
Also Published As
Publication number | Publication date |
---|---|
CN108810545A (en) | 2018-11-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108810545B (en) | Method, apparatus, computer readable medium and electronic device for video encoding | |
US11095877B2 (en) | Local hash-based motion estimation for screen remoting scenarios | |
US10390039B2 (en) | Motion estimation for screen remoting scenarios | |
US9071841B2 (en) | Video transcoding with dynamically modifiable spatial resolution | |
RU2682859C1 (en) | Selection of motion vector precision | |
US11743475B2 (en) | Advanced video coding method, system, apparatus, and storage medium | |
US20150262404A1 (en) | Screen Content And Mixed Content Coding | |
US20150312575A1 (en) | Advanced video coding method, system, apparatus, and storage medium | |
US20150288965A1 (en) | Adaptive quantization for video rate control | |
CN109348309B (en) | Distributed video transcoding method suitable for frame rate up-conversion | |
US11218663B2 (en) | Video chunk combination optimization | |
US11277619B2 (en) | Rate control for video splicing applications | |
US10999599B2 (en) | System and method for non-uniform video coding | |
US20180184089A1 (en) | Target bit allocation for video coding | |
JP2022515518A (en) | Method and device for linear modeling between components for intra-prediction | |
US11343501B2 (en) | Video transcoding method and device, and storage medium | |
US20240314326A1 (en) | Video Coding Method and Related Apparatus Thereof | |
WO2021056575A1 (en) | Low-delay joint source-channel coding method, and related device | |
US20240244229A1 (en) | Systems and methods for predictive coding | |
CN112449184B (en) | Transform coefficient optimization method, encoding and decoding method, device, medium, and electronic device | |
WO2016193949A1 (en) | Advanced video coding method, system, apparatus and storage medium | |
WO2024167518A1 (en) | Cross component intra prediction with multiple parameters | |
WO2025007562A1 (en) | Video processing method and apparatus | |
CN117461314A (en) | System and method for combining sub-block motion compensation and overlapped block motion compensation | |
CN118786665A (en) | System and method for blending block portions in partition-based prediction mode |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |