本文介绍了ffmpeg如何在windows平台上使用intelmedia SDK执行h264硬代码。 测试版是3.2.2。
ffmeg硬编码流程与软件编码流程相同,唯一不同的是初始化编码器。 软件编码的基本流程如下
介绍,正文从略。 介绍硬代码初始化encoder代码。
intinitencodercodec(intiwidth,int iHeight ) )。
{
av codec * ph 264 codec=av codec _ find _ encoder _ by _ name (h264 _ qsv );
//av codec * ph 264 codec=av codec _ find _ encoder _ by _ name (lib x264 );
//av codec * ph 264 codec=av codec _ find _ encoder (av _ codec _ id _ h264 );
if (null==ph 264编码解码器)。
{
printf(%s )、) avcodec_find_encoder failed );
返回- 1;
}
outputenccontext=av codec _ alloc _ context3(ph 264 codec );
outPutEncContext-gop_size=12;
//outputenccontext-frame rate=30;
//outputenccontext-has _ b _ frames=0;
outputenccontext-max _ b _ frames=0;
//outputenccontext=av codec _ alloc _ context3(ph 264 codec );
outputenccontext-codec _ id=ph 264 codec-id;
outputenccontext-time _ base.num=context-streams [0]-codec-time _ base.num;
outputenccontext-time _ base.den=context-streams [0]-codec-time _ base.den;
outputenccontext-pix _ fmt=* ph 264 codec-pix _ fmts;
outPutEncContext-width=iWidth;
outputenccontext-height=iheight;
//outputenccontext-bit _ rate=4* 1024 * 1024;
AVDictionary *options=nullptr;
outputenccontext-flags|=av _ codec _ flag _ global _ header;
//av_dict_set(options,' preset ',' ultrafast ',0 ); //'ultrafast's
//av_dict_set(options,' preset ',' veryfast ',0 );
//av _ opt _ set (outputenccontext-priv _ data,' tune ',' zerolatency ',0 );
//av _ opt _ set (outputenccontext-priv _ data,' profile ',' baseline ',0 );
intret=av codec _ open2 (outputenccontext,pH264Codec,options );
avqsvcontext * qsv=(avqsvcontext * ) outputenccontext-HW Accel _ context;
是if(ret0)
{
printf((%s )、)开放编码故障);
返回ret;
}
返回1;
}
硬代码和软件代码的性能比较(测试机器,I7 5500 ) ) ) ) ) ) ) ) ) )。
如果视频复杂度较低,例如,通过编码捕获桌面视频(桌面视频没有大的变化) 1080p、25fps )。
软件代码所占的CPU在30% -40%之间。 有硬件代码的cpu是18-25左右
视频负载较高(例如,编码捕获桌面视频(桌面播放高清视频) 1080p、25fps ) )。
软件代码所占的CPU在50% -70%之间。 有硬件代码的cpu是18-25左右
场景复杂度对软编辑的影响非常大,对硬编辑的影响不明显。
如果有交流,请添加流/Ffmpeg/音视频127903734或QQ350197870。
译文: 3358 www.cn blogs.com/wanggang 123/p/6354485.html