尝试在FFMPEG C项目中使用openH264替代libX264

tis*_*shu 10 c ffmpeg video-encoding openh264

我有一个应用程序使用FFMPEG和x264编码器逐帧转码视频.我希望发布这个应用程序,但x264的许可使我转而使用openh264.

我设法顺利编译所有内容(openh264然后FFMPEG与enable-openh264).我现在正在尝试纠正我的C代码中的编码器设置,因为对libx264起作用的东西不再起作用了.不幸的是我发现FFMPEG/openh264的C/C++示例非常有限,我将不胜感激任何链接/提示.

我使用以下代码(dec_ctx是我正在解码的视频的AVCodecContext)

            enc_ctx->height = dec_ctx->height;
            enc_ctx->width = dec_ctx->width;
            enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio;
            /* take first format from list of supported formats */
            enc_ctx->pix_fmt = encoder->pix_fmts[0];
            /* video time_base can be set to whatever is handy and supported by encoder */
            enc_ctx->time_base = dec_ctx->time_base;

            enc_ctx->gop_size      = 120; /* emit one intra frame every twelve frames at most */
            enc_ctx->max_b_frames = 16;
            enc_ctx->scenechange_threshold = 0;
            enc_ctx->rc_buffer_size = 0;
            enc_ctx->me_method = ME_ZERO;

            enc_ctx->ticks_per_frame = dec_ctx->ticks_per_frame * ifmt_ctx->streams[i]->time_base.den * ifmt_ctx->streams[i]->r_frame_rate.num/ifmt_ctx->streams[i]->r_frame_rate.den;
            // Set Ultrafast profile. internal name for this preset is baseline
            av_opt_set(enc_ctx->priv_data, "preset", "placebo", AV_OPT_SEARCH_CHILDREN);
Run Code Online (Sandbox Code Playgroud)

我在输出中使用[OpenH264]标记得到以下错误:

[OpenH264] this = 0x0000000019C126C0, Warning:bEnableFrameSkip = 0,bitrate can't be controlled for RC_QUALITY_MODE,RC_BITRATE_MODE and RC_TIMESTAMP_MODE without enabling skip frame.
Output #0, mp4, to 'C:\Dev\temp\geoVid.mp4':
Stream #0:0: Video: h264 (libopenh264), yuv420p, 720x480, q=2-31, 200 kb/s, 90k tbn, 180k tbc
Stream #0:1: Audio: aac, 48000 Hz, stereo, fltp, 96 kb/s
[OpenH264] this = 0x0000000019C126C0, Warning:Actual input framerate fAverageFrameRate = 0.000000 is quite different from framerate in setting 60.000000, please check setting or timestamp unit (ms), start_Ts = 0
[OpenH264] this = 0x0000000019C126C0, Warning:Actual input framerate fAverageFrameRate = 0.000000 is quite different from framerate in setting 60.000000, please check setting or timestamp unit (ms), start_Ts = 0
Run Code Online (Sandbox Code Playgroud)

输出视频文件只播放黑帧.任何提示或链接到某些文档将不胜感激.我一直试图理解这些错误但不太确定如何启用"跳帧"或者为什么抱怨我的输入帧速率(这与我用libx264成功编码时的输入相同)

小智 1

警告建议您必须在设置比特率之前设置丢帧模式,因此将比特率设置为 0。