0

I am piping frames into FFmpeg at quite a slow rate (1 per second) and I want to stream them out with very low latency.

There are not only sources (for example here and here) that don't mention that I need to set the GOP size (keyint) to a small value, but there are even sources (like here and here) that explicitly say that I don't have to set the GOP size to a small value.

However, so far the only way I found to reduce the really long start delay is to actually reduce the GOP size to 1.

Anyway, here's my current command line:

ffmpeg -f image2pipe
       -probesize 32
       -i -
       -c:v libx264
       -preset veryfast
       -crf 23
       -vsync 2
       -movflags "frag_keyframe+empty_moov"
       -profile baseline
       -x264-params "intra-refresh=1"
       -tune zerolatency
       -f mp4
       -

(I also tried adding :bframes=0:force-ctr:no-mbtree:sync-lookahead=0:sliced-threads:rc-lookahead=0 to -x264-params (what -tune zerolatency is supposed to do) because some of those values didn't appear in the debug output, but as expected it had no effect.)

As you can see here, we are already 182 frames (= 3 minutes wall clock) into the stream, but it still hasn't emitted anything (size was 1kB from the start).

frame=  182 fps=1.0 q=20.0 size=       1kB time=00:00:07.24 bitrate=   0.8kbits/s speed=0.0402x

This actually talks about the time-to-first-picture, but it makes it seem like it's not a big deal. ;) It is for me, so maybe I have to make the first GOP 1 frame long and then I can switch to longer GOPs? Can FFmpeg do that?

AndreKR
  • 32,613
  • 18
  • 106
  • 168

1 Answers1

0

Adding -force_key_frames expr:eq(n,1) will force a KF on the 2nd frame.

Since your rate is 1 fps, I would suggest an expr of lt(n,5). Also, the default keyint is 250 and min-keyint is 40. So if you want to leave and rejoin the stream, it may take very long to restart. Consider reducing keyint.

Gyan
  • 85,394
  • 9
  • 169
  • 201