简体   繁体   English

C ++ FFmpeg刷新后如何继续编码?

[英]C++ FFmpeg how to continue encoding after flushing?

I write the received packets in binary files. 我将接收到的数据包写在二进制文件中。 When the recording of the first file is completed, I call flush: 当第一个文件的录制完成时,我将调用flush:

avcodec_send_frame(context, NULL);

This is the signal to end the stream. 这是结束流的信号。 But when I send a new frame to the encoder, function return AVERROR_EOF (man: the encoder has been flushed, and no new frames can be sent to it) . 但是,当我发送一个新的帧的编码器,函数返回AVERROR_EOF(男子:编码器已刷新,并没有新的帧可以发送给它)。 What to do to make the encoder take the frames after flushing? 如何使编码器在冲洗后拍摄帧?

Example: when decoding, you can call: 示例:解码时,您可以调用:

avcodec_flush_buffers(context);

This function changes the stream, but only for decoding. 此功能更改流,但仅用于解码。 Maybe analogic function for encoding? 也许模拟功能编码?

Ideas: 想法:

1) do not call flush. 1)不要调用冲洗。 But the encoder buffers frames inside and gives some packets only after flushing (using h.264 with b-frames) , while some packets get into the next file. 但是编码器会在内部缓冲帧并仅在刷新后才提供某些数据包(将h.264与b帧一起使用) ,而某些数据包会进入下一个文件。

2) Recreate codec context? 2)重新创建编解码器上下文?

Details: use Win 7, Qt 5.10, ffmpeg 4.0.2 详细信息: 使用Win 7,Qt 5.10,ffmpeg 4.0.2

The correct answer is that you should create a new codec context for each file, or headache will follow. 正确的答案是,您应该为每个文件创建一个新的编解码器上下文,否则将令人头痛。 The little expense of additional headers and key frames should be small unless you are doing something very exotic. 除非您正在做一些非常奇特的事情,否则额外的标题和关键帧的开销应该很小。

B-frames can refer to both previous and future frames, how would you even decide such a beast? B帧既可以引用先前的帧,也可以引用将来的帧,那么您如何确定这种野兽呢?

In theory you could probably force a keyframe and hope for the best, but then there is really no point in not starting a new context, unless the hundreds of bytes or so of H264 init data is a problem. 从理论上讲,您可能会强制设置关键帧并希望达到最佳效果,但是除非没有数百个左右的H264初始化数据问题,否则不启动新上下文实在没有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM