当前位置:网站首页>FFMpeg AVFrame 的概念.
FFMpeg AVFrame 的概念.
2022-07-02 03:23:00 【hjjdebug】
FFMpeg AVFrame 的概念.
拿这个简单的例子测试一下吧。
$ cat avframe.c
#include "libavcodec/avcodec.h"
// 测试 frame 概念, 查找内存泄漏
void av_frame_test()
{
AVFrame *frame = NULL;
int ret = 0;
frame = av_frame_alloc();
// 1024 *2 * (16/8) =
frame->nb_samples = 1024;
frame->format = AV_SAMPLE_FMT_S16;//AV_SAMPLE_FMT_S16P AV_SAMPLE_FMT_S16
frame->channel_layout = AV_CH_LAYOUT_MONO; //AV_CH_LAYOUT_MONO AV_CH_LAYOUT_STEREO
ret = av_frame_get_buffer(frame, 0); // 根据格式分配内存
if(frame->buf && frame->buf[0])
printf("%s(%d) 1 frame->buf[0]->size = %d\n", __FUNCTION__, __LINE__, frame->buf[0]->size); //受frame->format等参数影响
if(frame->buf && frame->buf[1])
printf("%s(%d) 1 frame->buf[1]->size = %d\n", __FUNCTION__, __LINE__, frame->buf[1]->size); //受frame->format等参数影响
if(frame->buf && frame->buf[0]) // 打印referenc-counted,必须保证传入的是有效指针
printf("%s(%d) ref_count1(frame) = %d\n", __FUNCTION__, __LINE__, av_buffer_get_ref_count(frame->buf[0]));
ret = av_frame_make_writable(frame); // 当frame本身为空时不能make writable
printf("av_frame_make_writable ret = %d\n", ret);
if(frame->buf && frame->buf[0]) // 打印referenc-counted,必须保证传入的是有效指针
printf("%s(%d) ref_count2(frame) = %d\n", __FUNCTION__, __LINE__, av_buffer_get_ref_count(frame->buf[0]));
av_frame_unref(frame); // 释放frame, 当bufs refcount 为0时, 会执行buf释放器,释放buf
if(frame->buf && frame->buf[0]) // 已释放,frame->buf 为0, 不会打印该行了
printf("%s(%d) ref_count3(frame) = %d\n", __FUNCTION__, __LINE__, av_buffer_get_ref_count(frame->buf[0]));
av_frame_free(&frame);
}
[email protected]:/$ cat main.c
#include <stdio.h>
void av_frame_test();
int main()
{
av_frame_test();
printf("finished!\n");
return 0;
}
可以查一下AVFrame 在哪里释放内存的,实际上是在这里。
(gdb) bt
#0 av_free (ptr=0x5555555595c0) at libavutil/mem.c:224
#1 0x00007ffff7cea5b5 in av_buffer_default_free (opaque=0x0, data=0x5555555595c0 "") at libavutil/buffer.c:64
#2 0x00007ffff7cea7b1 in buffer_replace (dst=0x555555559460, src=0x0) at libavutil/buffer.c:120
#3 0x00007ffff7cea808 in av_buffer_unref (buf=0x555555559460) at libavutil/buffer.c:130
#4 0x00007ffff7cfadc9 in av_frame_unref (frame=0x555555559340) at libavutil/frame.c:563
#5 0x0000555555555420 in av_frame_test () at avframe.c:29
#6 0x00005555555554a6 in main () at main.c:5
边栏推荐
- Which of PMP and software has the highest gold content?
- JS introduction < 1 >
- Render header usage of El table
- Merge interval, linked list, array
- Gradle 笔记
- Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
- MySQL advanced (Advanced) SQL statement (II)
- < job search> process and signal
- What is hybrid web containers for SAP ui5
- Aaaaaaaaaaaa
猜你喜欢

Download and use of the super perfect screenshot tool snipaste

Knowing things by learning | self supervised learning helps improve the effect of content risk control

Cache processing scheme in high concurrency scenario

Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性

Continuous assignment of Verilog procedure

The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added

One of the future trends of SAP ui5: embrace typescript

How to develop digital collections? How to develop your own digital collections

焱融看 | 混合云时代下,如何制定多云策略

Xiaomi, a young engineer, was just going to make soy sauce
随机推荐
Detailed explanation of ThreadLocal
aaaaaaaaaaaaa
终日乾乾,夕惕若厉
Gradle 笔记
表单自定义校验规则
Load different fonts in QML
Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
只需简单几步 - 开始玩耍微信小程序
Custom classloader that breaks parental delegation
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
Named block Verilog
What is hybrid web containers for SAP ui5
Knowing things by learning | self supervised learning helps improve the effect of content risk control
Competition and adventure burr
GSE104154_ scRNA-seq_ fibrotic MC_ bleomycin/normalized AM3
在QML中加载不同字体
汇率的查询接口
Delphi xe10.4 installing alphacontrols15.12
竞争与冒险 毛刺
Xiaomi, a young engineer, was just going to make soy sauce