[Libav-user] Rate control for mpeg4 encoding

Sergio Basurco sergio.b at coherentsynchro.com
Fri Oct 17 08:49:24 CEST 2014


Hi,

I mean I'm encoding with the MPEG4 codec. Initialized as:

AVCodec * codec = avcodec_find_encoder(AV_CODEC_ID_MPEG4);

I have little experience with the ffmpeg application. I mostly use libav 
API. There is an example though here : 
https://trac.ffmpeg.org/wiki/Encode/MPEG-4

That shows how to encode with the mpeg4 codec at a constant 555k bitrate:

ffmpeg -y -i input.avi -c:v mpeg4 -vtag xvid -b:v 555k -pass 1 -an -f 
avi /dev/null

I don't know how to achieve that using the libav api. Here is a copy of 
my previous mail in case formatting was off:

--------------

I have an application that encodes mpeg4 video. The encoder was an 
adaptation of the decoding_encoding_8c-example 
(https://www.ffmpeg.org/doxygen/2.4/decoding_encoding_8c-example.html). 
It works well, but bitrate fluctuates without much control. Currently, 
these are my AVCodecContext settings:

     c->bit_rate = 5000000;
     c->width = this->m_width;
     c->height = this->m_height;
     c->time_base.den = 25;
     c->time_base.num = 1;
     c->gop_size = 0;
     c->max_b_frames=0;
     c->pix_fmt = AV_PIX_FMT_YUV420P;

     av_opt_set(c->priv_data, "preset", "ultrafast", 0);
     av_opt_set(c->priv_data, "tune", "zerolatency", 0);

And I get up to 70Mbps depending on the image being encoded. I have also 
tried to set these parameters:

     c->bit_rate = 12e06;
     c->rc_min_rate = c->bit_rate;
     c->rc_max_rate = c->bit_rate;
     c->rc_buffer_size = c->bit_rate * 30;

And it does limit bandwidth, but after a couple minutes of encoding I 
get the error:

     [error] ffmpeg error evaluating rc_eq (null)

My guess is that I'm missing some parameters. I don't quite understand 
what the rc_buffer_size value should be either.

---------------------



El 16-Oct-14 a las #4, Carl Eugen Hoyos escribió:
> Sergio Basurco <sergio.b at ...> writes:
>
>> av_opt_set(c->priv_data, "preset", "ultrafast", 0);
>> av_opt_set(c->priv_data, "tune", "zerolatency", 0);
>
> I don't know what you mean with "mpeg4 video" but
> I believe these are not supported for "mpeg4"
> encoding.
>
> Did you test with ffmpeg (the application)? It
> should tell you if it is possible at all to
> reach the desired bitrate for your input file
> and your options.
>
> (If possible, please set your mailer to "text-only",
> your mails are hard to read here.)
>
> Carl Eugen
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>

-- 
Sergio Basurco,
Coherent Synchro


More information about the Libav-user mailing list