ffmpeg解码文件

本文通过实例代码讲解如何利用ffmpeg库进行视频文件的解码操作,旨在帮助读者理解ffmpeg解码流程的关键步骤。
摘要由CSDN通过智能技术生成

只贴出部分代码,重在说明过程


av_register_all();

AVFormatContext* fctx = avformat_alloc_context();
int err = avformat_open_input(&fctx, "b.avi", NULL, NULL);

printf("open input:%d\n", err);

err = avformat_find_stream_info(fctx, NULL);

printf("find stream info:%d, streams:%d\n", err, fctx->nb_streams);

int video_id = -1;
for (int i = 0; i < fctx->nb_streams; i++)    //区分视频流和音频流
{
    if (fctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) //找到视频流,这里也可以换成音频
    {
        video_id = i;
        break;
    }
}

printf("video_id:%d\n", video_id);

AVCodec* codec = avcodec_find_decoder(fctx->streams[video_id]->codec->codec_id);
AVCodecContext* cctx = fctx->streams[video_id]->codec;
err = avcodec_open2(cctx, codec, NULL);    // 打开解码器

printf("open codec:%d\n", err);

int width = cctx->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值