ffmpeg 编码h264设置参数

baseline只有I帧和P帧


参考博客:ffmpeg常用命令

ffmpeg -i input -c:v libx264 -profile:v baseline -preset:v fast -level 3.1 -x264opts crf=18


参考博客:ffmpeg 编码h264 profile如何设置为baseline的问题

使用最新版ffmpeg-0.11 libx264-125,使用默认编码时,用Eyecard发现profile-idc一直是PROFILE_H264_HIGH (profile-idc=100),但是项目要求是baseline,设置了AVCodecContext的->profile=FF_PROFILE_H264_BASELINE也没用,经过多方查找,需要如下解决方法:

AVDictionary *opts = NULL;
av_dict_set(&opts, "profile", "baseline", 0);
/* open the codec */
if (avcodec_open2(m_pEncoderCtx, encoder, &opts) < 0)

参考博客:FFmpeg的设置GOP

既然知道了原因,解决思路就很明确了。只需要在使用ffmpeg进行编码的时候引入两个选项即可:

-keyint_min 48:keyint表示关键帧(IDR帧)间隔,这个选项表示限制IDR帧间隔最小为48帧,与之前设置的GOP等长
-sc_threshold 0:禁用场景识别,即禁止自动添加IDR帧
因此,保证GOP对齐的编码命令应该为:

ffmpeg -i elephants_dream_1080p24.y4m -s 1920x1080 -c:v libx264 -keyint_min 48 -g 48 -sc_threshold 0 -an ED1920x1080.mp4
ffmpeg -i elephants_dream_1080p24.y4m -s 1280x720 -c:v libx264 -keyint_min 48 -g 48 -sc_threshold 0 -an ED1280x720.mp4
ffmpeg -i elephants_dream_1080p24.y4m -s 896x504 -c:v libx264 -keyint_min 48 -g 48 -sc_threshold 0 -an ED896x504.mp4
ffmpeg -i elephants_dream_1080p24.y4m -s 640x360 -c:v libx264 -keyint_min 48 -g 48 -sc_threshold 0 -an ED640x360.mp4
ffmpeg -i elephants_dream_1080p24.y4m -s 256x144 -c:v libx264 -keyint_min 48 -g 48 -sc_threshold 0 -an ED256x144.mp4


在使用ffmpeg设置h264参数时,可以通过调用x264_param_apply_profile函数来设置profile。\[1\]另外,如果你在Ubuntu 16.04上安装了libx264库,可以使用以下命令来安装libx264的库:sudo apt install libx264-148和sudo apt install libx264-dev。\[2\] 在设置x264参数时,你可以使用AVCodecContext结构体来设置编码参数。首先,你需要找到对应的编码器,然后创建编码器上下文。接下来,你可以准备编码参数,并使用avcodec_open2函数来设置编码参数。\[2\] 如果你想设置preset参数,可以在准备编码参数设置。\[2\] 如果你想设置profile参数,可以使用AVDictionary结构体来设置。你可以创建一个AVDictionary对象,并使用av_dict_set函数来设置profile参数的值。然后,将该AVDictionary对象作为第三个参数传递给avcodec_open2函数。\[2\]\[3\] 总结起来,你可以使用x264_param_apply_profile函数来设置profile参数,使用AVCodecContext结构体来设置编码参数,使用AVDictionary结构体来设置preset和profile参数。 #### 引用[.reference_title] - *1* *2* [【FFmpeg设置H264参数](https://blog.csdn.net/u010168781/article/details/107497953)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [ffmpeg 编码h264设置参数](https://blog.csdn.net/qq_32642107/article/details/109668619)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值