当前位置: 首页 > news >正文

avcodec_alloc_context3,avcodec_open2,avcodec_free_context,avcodec_close

avcodec_alloc_context3 是创建编解码器上下文,需要使用 avcodec_free_context释放

需要使用avcodec_free_context 释放

/**
 * Allocate an AVCodecContext and set its fields to default values. The
 * resulting struct should be freed with avcodec_free_context().
 *
 * @param codec if non-NULL, allocate private data and initialize defaults
 *              for the given codec. It is illegal to then call avcodec_open2()
 *              with a different codec.
 *              If NULL, then the codec-specific defaults won't be initialized,
 *              which may result in suboptimal default settings (this is
 *              important mainly for encoders, e.g. libx264).
 *
 * @return An AVCodecContext filled with default values or NULL on failure.
 */
AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);

/**
 * Free the codec context and everything associated with it and write NULL to
 * the provided pointer.
 */
void avcodec_free_context(AVCodecContext **avctx);

avcodec_open2 打开编解码器上下文,需要使用 avcodec_free_context 释放

实际上更加合理是说:avcodec_open2 需要使用avcodec_close释放。avcodec_close函数的说明是:只会释放 avcodecContext 内部的元素,但是不会释放 avcodecContext自己。因此也需要使用 avcodec_free_context释放,avcodec_free_context的内部有用的第一句代码就是调用 avcodec_close函数。

/**
 * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
 * function the context has to be allocated with avcodec_alloc_context3().
 *
 * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
 * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
 * retrieving a codec.
 *
 * @note Always call this function before using decoding routines (such as
 * @ref avcodec_receive_frame()).
 *
 * @code
 * av_dict_set(&opts, "b", "2.5M", 0);
 * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
 * if (!codec)
 *     exit(1);
 *
 * context = avcodec_alloc_context3(codec);
 *
 * if (avcodec_open2(context, codec, opts) < 0)
 *     exit(1);
 * @endcode
 *
 * @param avctx The context to initialize.
 * @param codec The codec to open this context for. If a non-NULL codec has been
 *              previously passed to avcodec_alloc_context3() or
 *              for this context, then this parameter MUST be either NULL or
 *              equal to the previously passed codec.
 * @param options A dictionary filled with AVCodecContext and codec-private options.
 *                On return this object will be filled with options that were not found.
 *
 * @return zero on success, a negative value on error
 * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
 *      av_dict_set(), av_opt_find().
 */
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);

/**
 * Close a given AVCodecContext and free all the data associated with it
 * (but not the AVCodecContext itself).
 *
 * Calling this function on an AVCodecContext that hasn't been opened will free
 * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
 * codec. Subsequent calls will do nothing.
 *
 * @note Do not use this function. Use avcodec_free_context() to destroy a
 * codec context (either open or closed). Opening and closing a codec context
 * multiple times is not supported anymore -- use multiple codec contexts
 * instead.
 */
int avcodec_close(AVCodecContext *avctx);

void avcodec_free_context(AVCodecContext **pavctx)
{
    AVCodecContext *avctx = *pavctx;

    if (!avctx)
        return;

    avcodec_close(avctx);

    av_freep(&avctx->extradata);
    av_freep(&avctx->subtitle_header);
    av_freep(&avctx->intra_matrix);
    av_freep(&avctx->inter_matrix);
    av_freep(&avctx->rc_override);
    av_channel_layout_uninit(&avctx->ch_layout);

    av_freep(pavctx);
}

http://www.lryc.cn/news/496306.html

相关文章:

  • 强化学习的几个主要方法(策略梯度、PPO、REINFORCE实现等)(下)
  • 计算机网络:IP协议详细讲解
  • 2024信创数据库TOP30之华为Gauss DB
  • 在线家具商城基于 SpringBoot:设计模式与实现方法探究
  • 九、Spring Boot集成Spring Security之授权概述
  • python之Flask入门—路由参数
  • txt地图格式处理
  • 《数据挖掘:概念、模型、方法与算法(第三版)》
  • GitLab CVE-2024-8114 漏洞解决方案
  • request和websocket
  • 一键生成后端服务,MemFire Cloud重新定义开发效率
  • 短视频矩阵的营销策略:批量混剪实现高效传播
  • 朗迪锋亮相2024人因工程与智能系统交互国际会议
  • spring boot3.3.5 logback-spring.xml 配置
  • Proteus8.17下载安装教程
  • 一次Kafka启动失败引出的问题
  • mysql 查询所有的触发器
  • 704. 二分查找 C++
  • SpringCloud Seata集成分布式事务管理 事务保护 XA AT两种模式的区别
  • node.js基础学习-querystring模块-查询字符串处理(三)
  • 电子电气架构 --- 车载网关GW连接外部IP Tester
  • 鸿蒙LiteOS的核心架构
  • C语言——实现计算房屋总价
  • 【380】基于springboot的闲置图书分享
  • element-ui的下拉框报错:Cannot read properties of null (reading ‘disabled‘)
  • VMware虚拟机——安装保姆级教程(附安装包)
  • 如何实现表格选中时禁用树结构的复选框功能(El-Tree 与 El-Table 联动实现)
  • STM32CUBEIDE FreeRTOS操作教程(十):interrupt on/off中断开关
  • Linux的基本操作及虚拟机设置
  • oracle 用户手册