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

Adam Nielsen a.nielsen at shikadi.net
Wed Nov 3 13:43:34 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?

I am no expert but I imagine it is keeping the old packets around so it
can refer to them from later packets, and it only sends them when it no
longer needs to refer back to them.

> 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 suppose you could configure the codec to send an I fraame for every
frame or every second frame?  You'd get almost no compression but the
latency would probably be quite low.

You could also consider increasing the frame rate, e.g. 30 fps in, 120
fps out.  Since you'd be submitting each input frame multiple times,
the encoder would produce an output packet sooner.

There are probably much better ways than this but I imagine you'd have
to delve into the codec source code.

Cheers,
Adam.


More information about the ffmpeg-user mailing list