Reducing FFMPEG h264 video stream latency

5.4k Views Asked by At

I'm using FFMPEG(h264) and I want to reduce latency as much as possible. Now it's about 700 ms and I can't really make it lower. I tried almost all, so maybe anyone has idea how to help me?

ffmpeg -f dshow -i video="screen-capture-recorder" -pix_fmt yuv420p -probesize 32 -r 100 -an -vcodec libx264 -crf 40 -preset ultrafast -tune zerolatency -threads 8 -thread_type slice -f mpegts udp://192.168.88.228:1234

The weird thing is I got this latency even on 127.0.0.1.... (on the other side I use just ffplay udp:// .......)

2

There are 2 best solutions below

0
On

I would try to set -threads to 1 to disable multi-threaded decoding. Multi-threaded decoding introduces delay by adding a lag of 1 frame for each thread.

0
On

Works with a GoPro Hero 8 Black and Linux

ffmpeg -threads 1 -i 'udp://@0.0.0.0:8554?overrun_nonfatal=1&fifo_size=50000000' -f:v mpegts -fflags nobuffer -vf format=yuv420p -f v4l2 /dev/video0