FFmpeg:比特率动态变化 [英] FFmpeg: bitrate change dynamically

查看:830
本文介绍了FFmpeg:比特率动态变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过以前的线程,这是NISHAnT的回复,
FFMPEG:视频的bit_rate动态更改

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

这是我的代码:

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






我试图将代码添加到transcode()中,但是ffmpeg在我的代码之后退出。
我的代码有问题吗?
或还应该添加什么?


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?

我将代码放在redo:之后,以便它会递归循环。
请帮忙!

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

谢谢。

推荐答案

c是 AVCodecContext 结构。
您必须首先配置ffmpeg为您正在播放的文件类型。通过在ffmpeg根目录中创建第一个build.sh文件来创建它。
为您要配置codec9coder-decoder的文件类型)和muxer / demuxer。
例如播放avi文件,您必须分别为MPEGAVI和MPEG4配置avix的muxer / demuxer和codec。

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.

这篇关于FFmpeg:比特率动态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆