[FFmpeg-user] How to get ffplay live stream latency under 15 seconds

Adam Nielsen a.nielsen at shikadi.net
Mon Jan 3 14:18:55 EET 2022


Hi all,

I'm using ffplay to play a video stream from a Raspberry Pi (encoded
via ffmpeg using the Pi's hardware H264 encoder).

Unfortunately I cannot work out how to get the stream latency lower
than about 15 seconds.  I would be happy if the overall delay could be
reduced to 2 seconds or less.

I have tried a number of things I have found online but none of them
seem to make any difference.  I am seeing the following behaviour:

 * When I start the stream, the video appears within one second (the
   source stream is configured to send key frames once per second),
   however the stream is already 5-6 seconds behind the live image.

 * If I stop the stream at the source, ffplay continues to play the
   stream (with no new data coming in over the network) up until the
   timestamp where I stopped it.  So this tells me ffplay must be
   buffering the data, if it can keep playing for 15 seconds after the
   stream has stopped transmitting data over the network.

 * I have told ffplay to play the incoming stream as fast as possible
   (see below) however it still remains between 5 and 15 seconds
   behind.  It starts off 5 seconds behind and gradually increases to
   around 15 seconds behind, but never gets worse than that.  But
   again, when I stop the stream at the source, ffplay suddenly plays
   the video at a much higher framerate and catches all the way up to
   where the live stream was when it stopped being sent over the
   network.

I have tried various parameters to ffplay:

-sync ext
  Supposed to make the video play as quickly as possible.  Without it
  the playback can lag further and further behind (beyond 15 seconds)
  however with it it still lags by up to 15 seconds.

-probesize 32
  Makes the video start a little quicker but makes no difference to the
  latency.

-vf setpts='N/(30*TB)'
  Supposed to bump the framerate from the source 15 fps to 30 fps.  This
  doesn't seem to do anything until the source stream is terminated.
  At that point it does double the frame rate and quickly renders all
  the frames ffplay has apparently been buffering the whole time.

-vf setpts='PTS-STARTPTS'
  Supposed to remove any offset from the PTS value, but this has no
  effect.

-avioflags direct
  Prevents the video from playing with one message saying "[mpegts]
  Unable to seek back to the start" followed by many messages stating
  "[udp] Part of datagram lost due to insufficient buffer size".

-flags low_delay
-fflags nobuffer
-fflags discardcorrupt
-framedrop
-strict experimental
-sync audio
-sync video
  None of these make any difference one way or another.

Is there any way to get ffplay to render everything in its buffer so
you can consistently get under five seconds latency?  Or does it always
have to buffer a lot of data and run a long way behind the incoming
data?

Cheers,
Adam.


More information about the ffmpeg-user mailing list