Intel Sandy-Bridge H264 encoder GOP setting

Intel Sandy-bridge HW H264 encoder GOP (Group of Pictures)settings

参考Intel Media SDK提供的sample code,可以设置H264 Encoder的相关参数:

 

Intel(R) Media SDK Encoding Sample
Usage: sample_encode.exe h264|mpeg2 [Options] -i InputYUVFile -o OutputEncodedFi
le -w width -h height
Options:
   [-nv12] - input is in NV12 color format, if not specified YUV420 is expected
   [-tff|bff] - input stream is interlaced, top|bottom fielf first, if not speci
fied progressive is expected
   [-f frameRate] - video frame rate (frames per second)
   [-b bitRate] - encoded bit rate (Kbits per second)
   [-u speed|quality|balanced] - target usage
   [-t numThreads] - number of threads; default value 0
   [-dstw] - destination picture width, invokes VPP resizing
   [-dsth] - destination picture height, invokes VPP resizing
   [-hw] - use platform specific SDK implementation, if not specified software i
mplementation is used
   [-d3d] - work with d3d surfaces

包括:输入格式、帧速率、输出比特率、输入视频流宽高、输出视频流宽高等等。
这里我们发现,比没有设置I、B、P帧信息的相关参数,也就是说Demo中并没有开发这样的参数设置。
下面简单介绍下I、B、P帧
I-帧:也成为关键帧,I-帧完全自我指涉的,并且不使用任何其他帧的信息。它在三种帧中占最大的比例,并且具有最高的质量,但是压缩效率是最低的。
P -帧:P -帧是所谓的“预示”帧。当创建了一个P-帧时,编码器可以向后查看I-帧或者P-帧中冗余的图片信息。P-帧比I-帧效率高,但是没有B-帧的效率高。
B-帧:B-帧是双向预测帧,从图五你可以看到,这意味着当我们创建B-帧,编码器可以同时向前和向后查找冗余的图片信息。这使得B-帧在三种帧中具备最佳的效率。
      注意,B-帧在使用Baseline方式生产视频的时候是不可用的。

通过录制,发现Default的I、B、P帧信息为:相邻I帧间隔255,两帧I帧之间B、P帧分布为:
I*P*B*B*P*B*B*P*B*B*P*B*B...I*P*B*B*P*B*B*P*B*B*P*B*B...

这样的视频用于实时压缩,譬如摄像头实时H264视频压缩,刚开始preview是会有一段时间黑屏。
猜测其原因是I帧相隔太长,如果前面的I帧丢失,后续Decode需要参考下一个I帧。
(纯属猜测,H264种I、B、P帧没有太多研究,欢迎指正)
对于30fps的视频流来说可能需要10秒左右才能正常显示。

出于这样的原因,我们希望可以调整I、B、P的结构。通过查看Intel Media SDK的Guide,
发现Intel有提供这样的参数让我们可以调整I、B、P的构成,具体就是GopOptFlag:
GopOptFlag
Description
    The GopOptFlag enumerator itemizes special properties in the GOP (Group of Pictures) sequence.
Name/Description
    MFX_GOP_CLOSED
    B-frames of the first B-interval can never reference the previous GOP
    MFX_GOP_STRICT
    The encoder must strictly follow the given GOP structure as defined by parameter GopPicSize,
    GopRefDist etc in the mfxVideoParam structure. Otherwise, the encoder can adapt the GOP structure
    for better efficiency, whose range is constrained by parameter GopPicSize and GopRefDist etc.
Change History
    This enumerator is available since SDK API 1.0.

而GopOptFlag所在的位置是:
mfxVideoParam -> mfxInfoMFX -> GopOptFlag
此外还需要利用到的相关参数可以参考mfxInfoMFX的说明,主要包括:
mfxU16 GopPicSize;
mfxU16 GopRefDist;
mfxU16 GopOptFlag;
mfxU16 NumRefFrame;

GopPicSize
    Number of pictures within the current GOP (Group of Pictures); if GopPicSize=0, then the GOP size is unspecified.
    If GopPicSize=1, only I-frames are used. See Example 11 for pseudo-code that demonstrates how SDK uses this parameter.
GopRefDist
    Distance between I- or P- key frames; if it is zero, the GOP structure is unspecified. Note:
    If GopRefDist = 1, there are no B-frames used. See Example 11 for pseudo-code that demonstrates how SDK uses this parameter.
GopOptFlag
    ORs of the GopOptFlag enumerator indicate the additional flags for the GOP specification;
    see Example 11 for an example of pseudo-code that demonstrates how to use this parameter.
NumRefFrame
    Number of reference frames; if NumRefFrame = 0, this parameter is not specified.

这里举例说明下:
GopOptFlag = MFX_GOP_STRICT
GopPicSize = 10;
GOPRefDist = 3;
NumRefFrame = 1;
所得结果如下图:



上述参数设置位置:
mfxStatus MFXVideoENCODE_Init(mfxSession session, mfxVideoParam *par);
保存到其中的mfxVideoParam *par参数中即可。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值