FFmpeg: bitrate change dynamically

怎甘沉沦 提交于 2019-12-11 08:23:03

问题


I read the previous thread and this is the response from NISHAnT, FFMPEG: Dynamic change of bit_rate for Video

 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);

And this is my code:

    if(previous_BR != cur_BR){
        previous_BR = cur_BR;

        AVCodecContext* new_c = av_mallocz(sizeof(AVCodecContext));;

        avcodec_copy_context(new_c, ost_table[0]->st->codec);


        avcodec_close(ost_table[0]->st->codec);
        av_free(ost_table[0]->st->codec);

        avcodec_init();
        avcodec_register_all();

        ost_table[0]->enc = avcodec_find_encoder(CODEC_ID_H264);
        new_c = avcodec_alloc_context3(ost_table[0]->enc);
        ost_table[0]->st->codec = new_c;

        AVFrame *picture= avcodec_alloc_frame();

        new_c->bit_rate = cur_BR;
        new_c->width = 352;
        new_c->height = 288;
        int framerate = 30;
        new_c->time_base= (AVRational){1,framerate};
        new_c->pix_fmt = PIX_FMT_YUV420P;
        new_c->codec_type = AVMEDIA_TYPE_VIDEO;
        new_c->codec_id = CODEC_ID_H264;}

I tried to add my code to transcode(), but ffmpeg exits after it goes through my codes. is there something wrong with my codes? or what else I should add?

I put the code after "redo:", so that it will recursively loop back. please help !!

Thank you.


回答1:


c is AVCodecContext Structure. You must configure ffmpeg first for the type of file you are playing.Build it by conifguing first build.sh file in ffmpeg root directory. for the type of file you have to configure the codec9coder-decoder) and muxer/demuxer. for example to play avi file , you have to configure the muxer/demuxer and codec for avi which is MPEG "AVI" amd "MPEG4" respectively.



来源:https://stackoverflow.com/questions/10127470/ffmpeg-bitrate-change-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!