av_interleaved_write_frame return 0 但没有写入数据

av_interleaved_write_frame return 0 but no data written

我使用 ffmpeg 流式传输编码的 aac 数据,我使用

av_interleaved_write_frame()

写帧。

return值为0,表示成功description

Write a packet to an output media file ensuring correct interleaving.

The packet must contain one audio or video frame. If the packets are already correctly interleaved, the application should call av_write_frame() instead as it is slightly faster. It is also important to keep in mind that completely non-interleaved input will need huge amounts of memory to interleave with this, so it is preferable to interleave at the demuxer level.

Parameters

s media file handle

pkt The packet containing the data to be written. pkt->buf must be set to a valid AVBufferRef describing the packet data. Libavformat takes ownership of this reference and will unref it when it sees fit. The caller must not access the data through this reference after this function returns. This can be NULL (at any time, not just at the end), to flush the interleaving queues. Packet's stream_index field must be set to the index of the corresponding stream in s.streams. It is very strongly recommended that timing information (pts, dts duration) is set to correct values.

Returns

0 on success, a negative AVERROR on error.

但是,我发现没有写入数据。

我错过了什么?如何解决?

av_interleaved_write_frame() 在写出数据之前必须将数据保存在内存中。交错是获取多个流(例如一个音频流,一个视频流)并以单调顺序序列化它们的过程。所以,如果你写了一个音频帧,它会一直保存在内存中,直到你写了一个 'later' 的视频帧。一旦稍后的视频帧被写入,音频帧就可以被刷新'这样可以以不同的速度或在不同的线程中处理流,但输出仍然是单调的。如果您只写一个流(一个 acc 流,没有视频),那么按照建议使用 av_write_frame()。