【视频开发】关于FFMPEG中内存泄漏的问题之av_bitstream_filter_filter
来源:互联网 发布:java代码生成uml类图 编辑:程序博客网 时间:2024/06/08 13:39
How may I free pkt in an ffmpeg write frame method
Posted 28-Feb-14 12:33pm
radnix824
Updated 28-Feb-14 14:55pm
CHill60157.4K
v2
Add a Solution
Comments
You need to write one frame at a time. Also you are freeing a pointer to what it is that you are trying to write before you write it. Thus it crashes. If you don't free it at all you then keep allocating more and more RAM instead of writing to HDD file, and freeing memory for next frame.
Thanks ! yes, you've got me thinking.....:)
Rate this:
Solution 1
Well, I did finally get it working and will post my particular solution here with the hope it may help others. Oh, almost forgot. If you have a suggestion for change to this code, please do:
Hide Expand Copy Code
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>
Permalink
Comments
Looks better. Just remember in a function like this, you need to use your 'dummy' variables correctly. The dummy receives the info, the function operates on the dummy, when the dummy is happy it spits it back in the format you wanted.
Excellent analysis and a pretty good step ahead for future application. The original code is from ffmpeg.c .
Rate this:
Solution 2
Hide Copy Code
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);
阅读全文
1 0
- 【视频开发】关于FFMPEG中内存泄漏的问题之av_bitstream_filter_filter
- 内存泄漏的问题之av_bitstream_filter_filter
- android 面试中或者开发中会提到关于内存泄漏或者内存溢出的问题
- 关于内存泄漏的问题
- 关于内存泄漏的问题
- 关于内存泄漏的问题
- ffmpeg avcodec_open2 内存泄漏问题
- ArcEngine开发程序中关闭时内存泄漏的问题
- android开发中内存泄漏问题总结
- Android开发中常见内存泄漏问题
- 关于内存泄漏问题
- 【VS开发】关于内存泄漏的调试
- 关于ffmpeg合成视频的问题
- 关于 JAVA 的内存泄漏问题
- Android:关于ListView的内存泄漏问题
- 关于performSelector的内存泄漏问题
- 关于DWR内存泄漏的问题
- 关于WebView使用,内存泄漏的问题
- css弹性盒模型:flex
- Android Studio 无法预览xml布局视图的解决办法
- IE8下面parseInt('08')、parseInt('09')会转成0
- DataSet、DataTable和DataGridView知识备忘
- Jacoco 代码覆盖率,监控WEB项目
- 【视频开发】关于FFMPEG中内存泄漏的问题之av_bitstream_filter_filter
- JAVA-服务部署配置
- 牛客网 PAT(甲级) 1012Kuchiguse (20)
- Reactor 模式 通俗版解释
- 大数据中:Hadoop云计算以及Nosql与BI商业智能之间的关系
- AndroidStudio的使用
- hdoj 1008
- 用angr解二进制题目1
- B树