[FFmpeg-user] How to obtain packets as soon as sending a frame?

linzehui linzehui1 at huawei.com
Wed Nov 3 02:49:47 EET 2021


I am experimenting with the encoder example<https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/encode_video.c>. According to the FFmpeg encoding and decoding API overview<https://ffmpeg.org/doxygen/3.3/group__lavc__encdec.html>, the codec might accept multiple input frames without returning a packet, until its internal buffers are filled.

Is there a way to receive a packet as soon as I send a frame?

Specifically, I am using libx265. The first frame is always an I frame (key frame) which can be encoded without later frames. However, I have to send quite a few following frames to obtain the first packet, and this leads to severe latency.

I tried av_opt_set(codecContext->priv_data, "x265-params", "force-flush=1", 0); and avcodec_flush_buffers(), but both of them don't work. I also tried to look into AVCodecContext<https://github.com/FFmpeg/FFmpeg/blob/ed6549887a1969636b30295b3da87313b7c46864/libavcodec/avcodec.h> structure but failed to find any related option.



Thankful for any help you can offer.

Regards,
Zehui Lin


More information about the ffmpeg-user mailing list