如何预先分配LibavCodec的内存来编写解码的帧数据
How do I pre-allocate the memory for libavcodec to write decoded frame data?
我试图通过遵循演示代码来解码视频:shere
我需要能够控制pFrame->data[0]
中的帧数据存储位置。我尝试将pFrame->data
设置为自己的缓冲区,如下所示:
// Determine required buffer size and allocate buffer
int numBytes = av_image_get_buffer_size(pixFmt, width, height, 1);
(uint8_t*) dataBuff = (uint8_t*) malloc (numBytes * sizeof(uint8_t));
// Assign buffer to image planes in pFrame
av_image_fill_arrays(frame->data, frame->linesize, dataBuff, pixFmt, width,
height, 1);
虽然这确实将pFrame->data
设置为dataBuff
(如果我打印其地址,则它们是相同的),但此调用ret = avcodec_receive_frame(pCodecContext, pFrame)
接收解码的数据始终将数据写入其他地址。它似乎可以在基础API中的某个地方管理自己的内存,而忽略了我之前分配给pFrame
的dataBuff
。
所以我被困了 - 我可以告诉libav
将解码的帧数据写入我预先分配的内存吗?我已经看到人们在网上和Libav论坛上都提出类似的问题,但没有找到答案。
非常感谢〜
我发现正确的方法是通过回调函数 get_buffer2
创建自己的自定义分配器,因为此答案证明:
ffmpeg:在解码视频时,可以为用户提供的缓冲区生成结果?
进一步的文档在这里!
相关文章:
- 无法解码base64+deflate数据
- 使用已使用 java 编码的 openssl 解码数据
- 在CRC-16 CCITT中将数据从二进制解码为文本,我应该输入一个码字,使用CRC生成器进行编码
- 如何将 MJPEG 解码为原始 RGB(或 YUV)数据
- 将数据包从C++服务器发送到NodeJs服务器时出现MessagePack解码错误
- 解码 c++ 中以 base64 编码的大量数据
- 获取GIF帧数,而无需解码所有数据
- 从串行端口(带整数的字符串)解码数据
- 使用 UDP 协议从 Windows 套接字发送到 Qt 套接字的网络数据包上的结构编码和解码
- 如何预先分配LibavCodec的内存来编写解码的帧数据
- 寻求使用 FFmpeg 在 mp4 容器中 h264 编解码器的视频帧.数据包 pts 始终为 0
- 如何解码非密钥ASN1数据
- 跨平台UTF-8字符文件数据编码/解码
- 当JPEG数据不正确时,libjpeg解码崩溃
- B64在数据不是3的倍数的情况下的编码/解码处理
- 解码像 FAST 这样的数据协议的快速方法是什么,其中数据以字节为单位编码,并将位作为存在标志
- FFMPEG:编码后直接解码数据包
- 如何使用Zxing C++解码数据
- Windows Media Foundation:获取 AAC 解码数据
- 使用C40技术解码数据矩阵