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

FFmpeg中结构释放小函数

用于FFmpeg一些结构内存释放问题

#pragma once
#include <iostream>extern "C"
{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libavutil/avutil.h"
#include "libavutil/frame.h"
#include "libavcodec/packet.h"
}// 泛化变参模板 ///
template <typename T, typename... Args>
void CleanUp(T* para, Args&&... args)
{CleanUp(para);	CleanUp(std::forward<Args>(args)...);
}特化模板 /
template<>
inline void CleanUp<AVFormatContext*>(AVFormatContext** pp_fmt_ctx) {	if (pp_fmt_ctx && *pp_fmt_ctx) {avformat_close_input(pp_fmt_ctx);pp_fmt_ctx = nullptr;}
}template<>
inline void CleanUp<AVCodecContext*>(AVCodecContext** pp_codec_cxt) {if (pp_codec_cxt && *pp_codec_cxt) {avcodec_free_context(pp_codec_cxt);pp_codec_cxt = nullptr;}
}template<>
inline void CleanUp<AVPacket*>(AVPacket** pp_pkt) {if (pp_pkt && *pp_pkt) {av_packet_free(pp_pkt);pp_pkt = nullptr;}
}template<>
inline void CleanUp<AVFrame*>(AVFrame** pp_frame) {if (pp_frame && *pp_frame) {av_frame_free(pp_frame);pp_frame = nullptr;}
}template<>
inline void CleanUp<uint8_t*>(uint8_t** u8_buffer) {if (u8_buffer && *u8_buffer) {av_freep(*u8_buffer);u8_buffer = nullptr;}
}template<>
inline void CleanUp<FILE*>(FILE** pp_fp) {if (pp_fp && *pp_fp) {fclose(*pp_fp);pp_fp = nullptr;}
}

测试文件

// 资源释放测试
#include "CDestroyRes.h"
#include "vld.h"
#include <iostream>extern "C"
{
#include <libavutil/avutil.h>
}
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "vld.lib")int main()
{int n = 100;while (--n){AVFormatContext* fmt_ctx = avformat_alloc_context();const AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_H264);AVCodecContext* encoder = avcodec_alloc_context3(codec);AVPacket* pkt = av_packet_alloc();AVFrame* frame = av_frame_alloc();frame->width = 1280;frame->height = 640;frame->format = AV_PIX_FMT_ARGB;av_frame_get_buffer(frame, 0);CleanUp(&fmt_ctx, &encoder, &pkt, &frame);}getchar();return 0;
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 文档图像恢复
  • Linux之实战命令02:shred应用实例(三十六)
  • 1.Spring-容器-注册
  • Ubuntu 22.04 源码下载、编译
  • 【数据结构C语言】【入门】【首次万字详细解析】入门阶段数据结构可能用到的C语言知识,一章让你看懂数据结构!!!!!!!
  • 计算机组成原理之计算机系统的工作原理
  • 第一次安装Pytorch
  • Golang | Leetcode Golang题解之第421题数组中两个数的最大异或值
  • MySql主从复制原理
  • docker 升级步骤
  • C++ prime plus-7-編程練習
  • VMware虚拟机因磁盘空间不足黑屏无法登录
  • matlab绘制二维云图,划分区域,并显示每个区域的均值
  • KVM环境下制作ubuntu qcow2格式镜像
  • 基于SpringBoot的漫画网设计与实现
  • 【从零开始安装kubernetes-1.7.3】2.flannel、docker以及Harbor的配置以及作用
  • DataBase in Android
  • ES10 特性的完整指南
  • React-Native - 收藏集 - 掘金
  • SpringCloud集成分布式事务LCN (一)
  • Swoft 源码剖析 - 代码自动更新机制
  • vue-router的history模式发布配置
  • 爱情 北京女病人
  • 半理解系列--Promise的进化史
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • 使用Tinker来调试Laravel应用程序的数据以及使用Tinker一些总结
  • 小程序开发中的那些坑
  • 延迟脚本的方式
  • 怎样选择前端框架
  • Spring第一个helloWorld
  • 阿里云重庆大学大数据训练营落地分享
  • 交换综合实验一
  • 我们雇佣了一只大猴子...
  • ​ 全球云科技基础设施:亚马逊云科技的海外服务器网络如何演进
  • ​Linux·i2c驱动架构​
  • !!Dom4j 学习笔记
  • #pragam once 和 #ifndef 预编译头
  • #vue3 实现前端下载excel文件模板功能
  • (02)Unity使用在线AI大模型(调用Python)
  • (C#)Windows Shell 外壳编程系列9 - QueryInfo 扩展提示
  • (ctrl.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (含笔试题)深度解析数据在内存中的存储
  • (力扣)循环队列的实现与详解(C语言)
  • (六)Flink 窗口计算
  • (已解决)什么是vue导航守卫
  • *p++,*(p++),*++p,(*p)++区别?
  • .NET 4.0中的泛型协变和反变
  • .net core Redis 使用有序集合实现延迟队列
  • .NET 依赖注入和配置系统
  • .pub是什么文件_Rust 模块和文件 - 「译」
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @EventListener注解使用说明
  • [ Linux ] git工具的基本使用(仓库的构建,提交)