[Libav-user] Programmatically setting bit_rate ?

Philip Schneider pjschneider at earthlink.net
Fri Nov 21 18:14:07 CET 2014

Greetings -

I have some code that encodes video (only); this code was basically cloned from the “video_encode_example()” function provided on the FFmpeg web site. I’m using codec AV_CODEC_ID_MPEG2VIDEO, and pixel format AV_PIX_FMT_YUV420P.

The sample code has "c->bit_rate = 400000”. For a moderate-sized image (1280 x 720) at 30fps, the resulting movie shows terrible visual artifacts that look like typical significant undersampling. I increased the bit_rate by a factor of 10, that is, to 4000000. The resulting movie output looks fine at this value — no significant visual artifacts. Poking around the web, I see folks using values quite a lot higher than this, but without any explanation about how their bit_rate was determined...

I have no expertise in video technology or software (the code in question is simply used as a utility to dump movies out of a 3D graphics application), and only enough experience with the FFmpeg libraries to get this simple task done. 

Given those caveats, can someone explain how I can programmatically set the bit_rate? Of course at the time it’s set, I know the size of the frames and the frame rate. Note that I’m presuming that a “sufficient” bit_rate might be dependent on frame size and frame rate… :-)


— Philip

More information about the Libav-user mailing list