FFMPEG: Dynamic change of bit_rate for Video

2019-07-20 08:37发布

问题:

I use ffmpeg codes in my C++ app and would like to control the bit_rate parameter for VIDEO there. I tried to change its value in work (via ost->st->codec->codec->bit_rate), but ffmpeg did not wish to change it. Perhaps anybody knows how to make it?

Any ideas?

回答1:

I have tried like this and its working for me.

     avcodec_init();

     avcodec_register_all();

     codec = avcodec_find_encoder(CODEC_ID_H263);

     c = avcodec_alloc_context();

     picture= avcodec_alloc_frame();

        c->bit_rate = bitrate;
        c->width = w;
        c->height = h;
        c->time_base= (AVRational){1,framerate};
        c->pix_fmt = PIX_FMT_YUV420P;

avcodec_close(c);

av_free(c);