2016-10-27 31 views
0

我想實時流編碼爲webm,但ffmpeg卡在現場的鎖5秒鐘後指出C++的ffmpeg「啓動新的羣集」錯誤

[webm @ 0x1d81940] Starting new cluster at offset 0 bytes, pts 5040dts 5040 

我試圖增加相關AVFormatContext PARAMS

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成緩衝? (爲什麼它的文件?)

回答

0

也許,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;