C++ FFMPEG "Starting new cluster"错误
c++ ffmpeg "Starting new cluster" error
我想将直播流编码到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
这个错误可以在doc/examples/muxing.c
的官方示例中重现,只需将其写入缓冲区,而不是像这样写入文件
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_write_frame
调用分离。然而,我能够通过实现适当的AVIOContext
来解决我的问题。
要设置自定义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;
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- C++ FFMPEG "Starting new cluster"错误