C++ c++;ffmpeg";“启动新集群”;错误

C++ c++;ffmpeg";“启动新集群”;错误,c++,ffmpeg,webm,C++,Ffmpeg,Webm,我想将一个实时流编码到webm,但是ffmpeg在5秒后被卡在一个实时锁中 [webm @ 0x1d81940] Starting new cluster at offset 0 bytes, pts 5040dts 5040 我尝试增加相关的AVFormatContext参数 av_opt_set_int(oc->priv_data, "chunk_duration", INT_MAX, 0); av_opt_set_int(oc->priv_data, "cluster_tim

我想将一个实时流编码到
webm
,但是
ffmpeg
在5秒后被卡在一个实时锁中

[webm @ 0x1d81940] Starting new cluster at offset 0 bytes, pts 5040dts 5040
我尝试增加相关的
AVFormatContext
参数

av_opt_set_int(oc->priv_data, "chunk_duration", INT_MAX, 0);
av_opt_set_int(oc->priv_data, "cluster_time_limit", INT_MAX, 0);
av_opt_set_int(oc->priv_data, "cluster_size_limit", INT_MAX, 0);
这样可以避免大约30秒的错误,但是再次
ffmpeg
挂起

[webm @ 0xbc9940] Starting new cluster due to timestamp
[webm @ 0xbc9940] Starting new cluster at offset 0 bytes, pts 32800dts 32800
官方示例中的错误可以通过写入缓冲区而不是这样的文件来重现

oc = avformat_alloc_context();
oc->oformat = av_guess_format("webm", NULL, NULL);
oc->oformat->flags |= AVFMT_NOFILE;
和实际写作

uint8_t *output_buf;
avio_open_dyn_buf(&oc->pb);

avformat_write_header(oc, &opt);
/* or */
av_interleaved_write_frame(fmt_ctx, pkt);

avio_close_dyn_buf(oc->pb, &output_buf);
av_free(output_buf);
如何将webm编码到缓冲区中?
(为什么它适用于文件?

可能,
webm
格式执行某种异步写入操作,这些操作以某种方式与
av\u write\u帧
调用分离。 然而,我能够通过实施一个适当的解决方案来解决我的问题

要设置自定义IO,需要一个回调函数,该函数应如下所示:

static int dispatch_output_packet(void* opaque, uint8_t* buffer, int buffer_size)
{
    YourOutputType *out = (YourOutputType*) opaque;
    int result = out->do_something(buffer, buffer_size);
    return 0;
}
然后创建一个
AVIOContext
并将其插入:

size_t io_buffer_size = 3 * 1024 * 1024;
io_buffer = new unsigned char[io_buffer_size];
AVIOContext* io_ctx = avio_alloc_context(io_buffer, io_buffer_size, AVIO_FLAG_WRITE, &your_output_object, NULL, dispatch_output_packet, NULL);
io_ctx->seekable = 0;
format_context_->oformat->flags |= AVFMT_FLAG_CUSTOM_IO;
format_context_->oformat->flags |= AVFMT_NOFILE;
format_context_->pb = io_ctx;

可能,
webm
格式执行某种异步写入操作,这些操作以某种方式与
av_write_帧
调用分离。 然而,我能够通过实施一个适当的解决方案来解决我的问题

要设置自定义IO,需要一个回调函数,该函数应如下所示:

static int dispatch_output_packet(void* opaque, uint8_t* buffer, int buffer_size)
{
    YourOutputType *out = (YourOutputType*) opaque;
    int result = out->do_something(buffer, buffer_size);
    return 0;
}
然后创建一个
AVIOContext
并将其插入:

size_t io_buffer_size = 3 * 1024 * 1024;
io_buffer = new unsigned char[io_buffer_size];
AVIOContext* io_ctx = avio_alloc_context(io_buffer, io_buffer_size, AVIO_FLAG_WRITE, &your_output_object, NULL, dispatch_output_packet, NULL);
io_ctx->seekable = 0;
format_context_->oformat->flags |= AVFMT_FLAG_CUSTOM_IO;
format_context_->oformat->flags |= AVFMT_NOFILE;
format_context_->pb = io_ctx;