【视频开发】关于FFMPEG中内存泄漏的问题之av_bitstream_filter_filter
How may I free pkt in an ffmpeg write frame method
|
I'm looking at an ffmpeg source code example at :http://svn.perian.org/ffmpeg/ffmpeg.c[^]
In the code, I'm focusing on a method that writes the video frame.
Here is that method:
CopyCode
static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
int ret;
while(bsfc){
AVPacket new_pkt= *pkt;
int a= av_bitstream_filter_filter(bsfc, avctx, NULL,
&new_pkt.data, &new_pkt.size,
pkt->data, pkt->size,
pkt->flags & AV_PKT_FLAG_KEY);
if(a>0){
av_free_packet(pkt);
new_pkt.destruct= av_destruct_packet;
} else if(a<0){
fprintf(stderr, "%s failed for stream %d, codec %s",
bsfc->filter->name, pkt->stream_index,
avctx->codec ? avctx->codec->name : "copy");
print_error("", a);
if (exit_on_error)
exit_program(1);
}
*pkt= new_pkt;
bsfc= bsfc->next;
}
ret= av_interleaved_write_frame(s, pkt);
if(ret < 0){
print_error("av_interleaved_write_frame()", ret);
exit_program(1);
}
}
If I test the code as is, I get a crash at the write "ret= av_interleaved_write_frame(s, pkt);"
But if I comment our the //av_free_packet(pkt);
It works fine, and here is the problem, until after a while, memory grows very very large.
I suspect it's because I've commented out the av_free_packet(pkt)
Any ideas as to why I crash with the original code (with av_free_packet(pkt))?
7:51am
freeing memory for next frame.
2 solutions
|
Solution 1
CopyCode
static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
int ret;
while(bsfc){
AVPacket new_pkt= *pkt;
int a= av_bitstream_filter_filter(bsfc, avctx, NULL,
&new_pkt.data, &new_pkt.size,
pkt->data, pkt->size,
pkt->flags & AV_PKT_FLAG_KEY);
if(a>0){
//av_free_packet(pkt);//-comment this out
if (new_pkt.data != pkt->data)//-added this
{
av_free_packet(pkt);
pkt->data = new_pkt.data;
pkt->size = new_pkt.size;
pkt->destruct = av_destruct_packet;
}
new_pkt.destruct= av_destruct_packet;
} else if(a<0){
fprintf(stderr, "%s failed for stream %d, codec %s",
bsfc->filter->name, pkt->stream_index,
avctx->codec ? avctx->codec->name : "copy");
print_error("", a);
if (exit_on_error)
exit_program(1);
}
<b>// *pkt= new_pkt;//-comment this out</b>
bsfc= bsfc->next;
}
ret= av_interleaved_write_frame(s, pkt);
av_free_packet(pkt);//-added here
av_bitstream_filter_close(bsfc);//-added here
if(ret < 0){
print_error("av_interleaved_write_frame()", ret);
exit_program(1);
}
}</pre>
6:51am
18:17pm
|
Solution 2
AVPacket new_pkt = pkt;
int a = av_bitstream_filter_filter(m_bsfDecoderContext, out_stream->codec,
NULL,
&new_pkt.data,
&new_pkt.size,
pkt.data,
pkt.size,
pkt.flags & AV_PKT_FLAG_KEY);
av_free_packet(&pkt);
pkt.data = new_pkt.data;
pkt.size = new_pkt.size;
if (av_interleaved_write_frame(ofmt_ctx, &pkt) < 0)break;
av_free(new_pkt.data);
【视频开发】关于FFMPEG中内存泄漏的问题之av_bitstream_filter_filter的更多相关文章
- C++中内存泄漏的检测方法介绍
C++中内存泄漏的检测方法介绍 首先我们需要知道程序有没有内存泄露,然后定位到底是哪行代码出现内存泄露了,这样才能将其修复. 最简单的方法当然是借助于专业的检测工具,比较有名如BoundsCheck, ...
- Android开发常见的Activity中内存泄漏及解决办法
上一篇文章楼主提到由Context引发的内存泄漏,在这一篇文章里,我们来谈谈Android开发中常见的Activity内存泄漏及解决办法.本文将会以“为什么”“怎么解决”的方式来介绍这几种内存泄漏. ...
- Cocos性能优化工具的开发介绍Visual Studio内存泄漏检测工具——Visual Leak Detector
然后,Windows下有什么好的内存泄漏检測工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检測功能.我们能够使用第三方工具Visual Leak Detector(下面简 ...
- 浅谈C++中内存泄漏的检测
首先我们需要知道程序有没有内存泄露,然后定位到底是哪行代码出现内存泄露了,这样才能将其修复.最简单的方法当然是借助于专业的检测工具,比较有名如BoundsCheck,功能非常强大,相信做C++开发的人 ...
- 每日一问:Android 中内存泄漏都有哪些注意点?
内存泄漏对每一位 Android 开发一定是司空见惯,大家或多或少都肯定有些许接触.大家都知道,每一个手机都有一定的承载上限,多处的内存泄漏堆积一定会堆积如山,最终出现内存爆炸 OOM. 而这,也是极 ...
- 【视频开发】ffmpeg实现dxva2硬件加速
这几天在做dxva2硬件加速,找不到什么资料,翻译了一下微软的两篇相关文档.这是第二篇,记录用ffmpeg实现dxva2. 第一篇翻译的Direct3D device manager,链接:http: ...
- 什么是内存溢出以及java中内存泄漏5种情况的总结
内存泄漏定义(memory leak):一个不再被程序使用的对象或变量还在内存中占有存储空间. 一次内存泄漏似乎不会有大的影响,但内存泄漏堆积后的后果就是内存溢出.内存溢出 out of memory ...
- linux中内存泄漏的检測(五)记录内存泄漏的代码
到眼下为止,先后通过wrap malloc.new函数重载和计算指针内存大小的方法.基本上满足了对内存泄漏检測的须要. 假设发现了内存泄漏.那么就要找到内存泄漏的地方而且修正它了. 茫茫代码.如何去找 ...
- linux中内存泄漏的检測(一)最简单的方法
什么是内存泄漏 内存泄漏是指程序动态申请的内存在使用完后没有释放,导致这段内存不能被操作系统回收再利用. 比如这段程序,申请了4个字节的空间但没有释放,有4个字节的内存泄漏. #include < ...
随机推荐
- danci8
approach 英 [ə'prəʊtʃ] 美 [ə'protʃ] n. 方法:途径:接近 vt. 接近:着手处理 vi. 靠近 emulate 英 ['emjʊleɪt] 美 ['ɛmjulet] ...
- danci4
advantage 英 [əd'vɑːntɪdʒ] 美 [əd'væntɪdʒ] n. 优势:利益:有利条件 vi. 获利 vt. 有利于:使处于优势 lack 英 [læk] 美 [læk] vt. ...
- django-缓存django-redis
https://django-redis-chs.readthedocs.io/zh_CN/latest/ 安装 django-redis 最简单的方法就是用 pip : pip install dj ...
- python的next()函数
next(iterobject,defalt)函数的第一个参数是一个可迭代对象,第二个参数可以不写.不写的时候,如果可迭代对象的元素取出完毕,会返回StopIteration.如果第二个参数写一个其他 ...
- python的any()函数
any()函数的参数是一个可迭代对象,其中的一个元素有一个为真,则any()函数返回真,除非全部为假的时候才返回假. aaa=[,,,] print(any(aaa)) 返回:false
- 字符串翻转(C++)
1.字符串原地翻转,"abc"->"cba": int str_reverse(string &str,int first,int last) { ...
- AtCoder Beginner Contest 129 解题报告
传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...
- 国赛baby_pwn
国赛baby_pwn-ret2_dl_runtime_resolve之ELF32_rel,Elf32_sym,伪造 0x01 ELF文件的动态链接之延迟绑定 在动态链接下,程序模块之间包含了大量的函数 ...
- BZOJ 4890: [Tjoi2017]城市 树形dp
标签:树形dp,枚举,树的直径 一上来看到这个题就慌了,只想到了 $O(n^3)$ 的做法. 碰到这种题时要一步一步冷静地去分析,观察数据范围. 首先,$n\leqslant 5000$,所以可以先 ...
- php7 configure: error: Cannot find OpenSSL's <evp.h> 问题解决
开始以为是没有安装openssl, openssl-devel,安装后发现还是提示这个错误,搜索了一下evp.h,这个文件也存在.GOOGLE 了一下,在stackoverflow,找到了答案,原来是 ...



