1

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.

Community
  • 1
  • 1

1 Answers1

0

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.

Raulp
  • 7,758
  • 20
  • 93
  • 155
  • Hi softy, thanks for the reply,I just want to know if the code I list above is working, where should I put them in the ffmpeg.c or I need to use it in my own app. However, I prefer to just modify the existing ffmpeg.c. – Kevin Yen-Fu Ou Apr 13 '12 at 14:15
  • Depends .If it is an addition to ffmpeg you have to put in ffmpeg code and define its prototype in the header files.If not then you have to make a seperate application and link it with libavcodec(and other ffmpeg libraries).Also you have to put an error handling condition for the bitrate.You cant put the bitrate which is not accpetable by CODEC_ID_H263(h.263). – Raulp Apr 13 '12 at 16:10
  • Hi softy, I upload my codes and please see anything I need to modify to make it work? is that ok to put it after the redo: ? – Kevin Yen-Fu Ou Apr 13 '12 at 17:23