当前位置:网站首页>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
边栏推荐
- Global and Chinese market of X-ray detectors 2022-2028: Research Report on technology, participants, trends, market size and share
- Kotlin基础学习 15
- 3124. Word list
- Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
- 小米青年工程师,本来只是去打个酱油
- verilog REG 寄存器、向量、整数、实数、时间寄存器
- Qualcomm platform WiFi -- P2P issue (2)
- QT environment generates dump to solve abnormal crash
- 2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
- 高并发场景下缓存处理方案
猜你喜欢
Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
【JVM】创建对象的流程详解
寻找重复数[抽象二分/快慢指针/二进制枚举]
小米青年工程师,本来只是去打个酱油
How to develop digital collections? How to develop your own digital collections
表单自定义校验规则
[JS reverse series] analysis of a customs publicity platform
知物由学 | 自监督学习助力内容风控效果提升
Screenshot literacy tool download and use
Delphi xe10.4 installing alphacontrols15.12
随机推荐
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
【JVM】创建对象的流程详解
GB/T-2423. XX environmental test documents, including the latest documents
流线线使用阻塞还是非阻塞
[C Advanced] brother Peng takes you to play with strings and memory functions
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
Go execute shell command
Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
Verilog timing control
Load different fonts in QML
C reflection practice
OSPF LSA message parsing (under update)
Render header usage of El table
venn图取交集
Global and Chinese market of autotransfusion bags 2022-2028: Research Report on technology, participants, trends, market size and share
Continuous assignment of Verilog procedure
spark调优
MySQL connection query and subquery
Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field