我尝试使用 FFMPEG 将传入的帧编码为 h264,并将其写入 SD 卡。我从硬件获取原始帧作为内存缓冲区,然后使用 FFMPEG C API 对其进行编码。编码正在运行。但是,帧的隔行性质不正确。我有 480i 输入视频,但输出文件是 720x240“逐行”,即帧是连续的,并且 VLC 不进行去隔行。似乎我错过了某个步骤来告诉输出容器或 x264 视频是一系列隔行帧。到目前为止,我的初始化:
if(framebuffer->videoMode == XVIDC_VM_720x480_60_I){
framebuffer->context->width = 720;
framebuffer->context->height = 240;//240
/* frames per second */
framebuffer->context->time_base = (AVRational){1, 60};
framebuffer->context->framerate = (AVRational){60, 1};
} else {//if(videoMode == XVIDC_VM_720x576_50_P){
framebuffer->context->width = 720;
framebuffer->context->height = 288;//288
/* frames per second */
framebuffer->context->time_base = (AVRational){1, 50};
framebuffer->context->framerate = (AVRational){50, 1};
}
av_dict_set( &opt, "preset", "ultrafast", 0 );
av_dict_set( &opt, "x264opts", "interlaced=1", 0 );//
av_dict_set( &opt, "movflags", "frag_keyframe", 0 );//
av_dict_set( &opt, "flags", "+ildct+ilme", 0 );
framebuffer->context->flags |= AV_CODEC_FLAG_INTERLACED_DCT ;
framebuffer->context->flags2 |= AV_CODEC_FLAG2_FAST ;
据我所知,在终端调用 FFMPEG 时指定 -flags +ildct+ilme 应该足够了,但上述标志与其他针对 x264 的标志的组合对我来说都不起作用。我是否需要在 AVFrames 中设置某些内容来指示帧的隔行性质?