【发布时间】:2021-02-23 15:26:24
【问题描述】:
我想在内存之间重新采样给定的输入格式,到目前为止一切都很好。
但是当试图从 ffmpeg 获取输出标头时它不起作用。
在这里我分配上下文并传递 write_buffer 函数指针,这样它就不会写入文件而是使用所需数据调用我的函数
unsigned char * aviobuffer = (unsigned char *) av_malloc (32768);
AVIOContext * avio = avio_alloc_context (aviobuffer, 32768,1, NULL, NULL, write_buffer, NULL);
AVFormatContext* containerContext;
avformat_alloc_output_context2(&containerContext, NULL, "s16le", NULL);
containerContext->pb = avio;
这是我的 write_buffer 函数
std::vector<char>* data;
int write_buffer(void *opaque, uint8_t *buf, int buf_size)
{
std::vector<char> tmp;
tmp.assign(buf, buf + buf_size);
data->insert(data->end(), tmp.begin(), tmp.end());
return buf_size;
}
现在当我调用 avformat_write_header() 时,它不会调用我的 write_buffer() 函数 + 它返回 0 表示成功。
int ret = avformat_write_header(containerContext, NULL);
之后我调用适当的函数来获取数据体本身,并且我的 write_buffer() 被正常调用,所以我现在只剩下没有标题的数据体了!!
我怎样才能得到输出标题?
【问题讨论】:
标签: c++ c ffmpeg libavformat