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