I am attempting to encode video using libavcodec/libavformat. Audio works great, but when I try to encode video I get the following errors:
[libx264 @ 0x10182a000]broken ffmpeg default settings detected
[libx264 @ 0x10182a000]use an encoding preset (vpre)
easy to fix using the command line ffmpeg, but I am trying to do this in C. my options are
AVStream *pVideoOutStream = av_new_stream(pOutFormatCtx, 0);
AVCodecContext *pVideoOutCodecCtx = pVideoOutStream->codec;
pVideoOutCodecCtx->codec_id = CODEC_ID_H264;
pVideoOutCodecCtx->codec_type = CODEC_TYPE_VIDEO;
pVideoOutCodecCtx->bit_rate = pVideoInCodecCtx->bit_rate;
pVideoOutCodecCtx->width = pVideoInCodecCtx->width;
pVideoOutCodecCtx->height = pVideoInCodecCtx->height;
pVideoOutCodecCtx->pix_fmt = pVideoInCodecCtx->pix_fmt;
pVideoOutCodecCtx->sample_rate = pVideoInCodecCtx->sample_rate;
pVideoOutCodecCtx->gop_size = 30;
but avcodec_open() fails.
What other values do I need to set to make x264 happy?
I encode YUV420P pictures into different formats, using different codecs. CodecID I took from AVOutputFormat after using guess_format(...) function. But other codec settings are (All of them has been taken from ffmpeg examples' source code):
This setting must work to most codecs, but I had a problem with fps: not all codecs supports any fps values (and some other parameters too).
Not sure whether you got it working, but the following parameters work for me.
The error message
broken ffmpeg default settings detected
is displayed in the x264 library in x264/encoder/encoder.c when too many settings are the default ffmpeg settings (e.g.qmin = 2, qmax = 31, qcompress = 0.5
), changing these three values to something else, e.g.qmin = 10, qmax = 51, qcompress = 0.6
, resolves the error.Don't forget to use x264 private options. You can always set a profile:
Or set the lowest encoding latency:
Or select a preset:
Before opening a codec
The following is how to interpret the ffmpeg's x264 presets.
Unfortunately I don't know of an easy way to import the presets like ffmpeg does. You can lookup the x264 preset values which are all stored in /usr/local/share/ffmpeg/libx264-{name}.ffpreset, where {name} is specified for ffmpeg as the -vpre {name} command-line argument. So typically ffmpeg would include libx264-medium.ffpreset and then libx264-main.ffpreset, specified as ffmpeg -vpre medium -vpre main
You can lookup all the options (as defined in the libx264-{name}.ffpreset files) to get their structure names by looking in the libavcodec/options.c file, which can be found in the ffmpeg SVN repositories.
Here's how the medium and main presets would be translated into C code:
You'll have to look at the ffmpeg source code if you want to parse those presets automatically.
I hope that the information I just gave would help you out a bit more :)
seems that the ffmpeg version 20130302 requires something like