Question

I'm trying to use libavcodec (ffmpeg) to encode raw pixel data to mp4 format. Every thing goes well and I'm getting .avi file with decent quality but some times the codec gives "encoded frame too large" warning. And when ever it does that, a part of some frames (usually bottom portion of the frame) look garbled or all mixed up. Can any one tell me when this warning is given. Following are the settings I'm using for encoder:

qmax = 6;
qmin = 2;
bit_rate = 200000; // if I increase this, I get more warnings. 
width = 1360;
height = 768;
time_base.den = 15; // frames per second
time_base.num = 1;
gop_size = 48;
pix_fmt = PIX_FMT_YUV420P;

Regards,

Was it helpful?

Solution

From what I can gather ffmpeg allocates a constant buffer size of 2MB to hold a compressed frame. 1080p is 3MB uncompressed for example, and the codec can't always compress a large frame into less than 2MB.

You can possibly fix this by increasing the buffer size, and/or making it dynamic.

OTHER TIPS

Very probably that codec's buffer is not big enough. Try to change rc_buffer_size. Alternatively, you can try this settings:

ctx->bit_rate = 500000;
ctx->bit_rate_tolerance = 0;
ctx->rc_max_rate = 0;
ctx->rc_buffer_size = 0;
ctx->gop_size = 40;
ctx->max_b_frames = 3;
ctx->b_frame_strategy = 1;
ctx->coder_type = 1;
ctx->me_cmp = 1;
ctx->me_range = 16;
ctx->qmin = 10;
ctx->qmax = 51;
ctx->scenechange_threshold = 40;
ctx->flags |= CODEC_FLAG_LOOP_FILTER;
ctx->me_method = ME_HEX;
ctx->me_subpel_quality = 5;
ctx->i_quant_factor = 0.71;
ctx->qcompress = 0.6;
ctx->max_qdiff = 4;
ctx->directpred = 1;
ctx->flags2 |= CODEC_FLAG2_FASTPSKIP;

In the example code I found something like:

outbuf_size = 100000;
outbuf = malloc(outbuf_size);

[...]

out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);

Pushing outbuf_size to be larger resolved the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top