FFmpeg 'avcodec_copy_context' deprecated (视频裁剪)

博客介绍了在FFmpeg中,由于avcodec_copy_context函数已弃用,推荐使用的新方法。作者引用了雷霄骅的文章,提供新的代码实现,并提及av_free_packet的替换方式。此外,还简要提到了视频裁剪的测试方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在学习一些代码的时候发现有些已经弃用了:记录一下新的写法:


1,avcodec_copy_context
以前的写法:

ret = avcodec_copy_context(outStream->codec, inStream->codec);
    if (ret < 0)
    {
      fprintf(stderr, "Failed to copy context from input to output stream codec context\n");
      goto end;
    }
    outStream->codec->codec_tag = 0;
    if (outFmtCtx->oformat->flags & AVFMT_GLOBALHEADER)
    {
      outStream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
    }

新的写法:(来自雷霄骅:https://blog.youkuaiyun.com/leixiaohua1020/article/details/25422685)

   AVCodecContext *codecCtx = avcodec_alloc_context3(codec);
    ret = avcodec_parameters_to_context(codecCtx, inStream->codecpar);
    if (ret < 0)
    {
      printf("Failed to copy in_stream codecpar to codec context\n");
      goto end;
    }
    codecCtx->codec_tag = 0;
    if (outFmtCtx->oformat->flags & AVFMT_GLOBALHEADER)
    {
      codecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
    }
    ret = avcodec_parameters_from_context(outStream->codecpar, codecCtx);
    if (ret < 0)
    {
      printf("Failed to copy codec context to out_stream codecpar context\n");
      goto end;
    }

2,av_free_packet(&pkt)
新的写法:

av_packet_unref(&pkt);

视频裁剪

#include <stdio.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>

int cutVideo(double fromSeconds
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值