How to reduce latency on FFmpeg video streaming

ffmpeglatencyvideo streamingvideo-codecsvlc-media-player

On a video streaming application between Linux server (FFmpeg) and Windows client (VLC player), there is a noticeable latency of about 10 seconds.

FFmpeg command:

ffmpeg -re -f v4l2 -i /dev/video0 http://192.168.1.101:8090/feed1.ffm

VLC player:

http://192.168.1.101:8090/test.swf

Despite the fact that, both server and client start together, VLC player delays about 10 seconds to play the stream, playing it from the first frame that server captured. For this reason, there is constantly a delay of 10 seconds.

I 'm trying to figure out what causes this latency:

  1. My first thought is that codec delays with encoding. In this case, what codec should I include on my ffserver configuration file? I experimented with many video codecs (rawvideo, flv, mjpeg) but same result.

  2. Secondly, is there a parameter I could include in my ffmpeg command to control latency?

  3. On the other hand, could this latency occurs due to VLC player?

I comprehend that this question is kinda general. However, any help, in case you faced similar problem, would be highly appreciated.

FFserver configuration file:

Port 8090
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 40000  

<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 500M
ACL allow localhost
ACL allow 127.0.0.1
ACL allow 192.168.0.0 192.168.255.255
</Feed>

<Stream test.swf>
Feed feed1.ffm
Format swf
VideoCodec flv
VideoSize 640x480
VideoFrameRate 30
VideoBitRate 400 

AVOptionVideo flags +global_header
AVOptionVideo cpu-used 0
AVOptionVideo qmin 10
AVOptionVideo qmax 42

PreRoll 5
StartSendOnKey
NoAudio
</Stream>

Best Answer

Add the option ffmpeg with -tune zerolatency and best option using x265 codec, reduce VideoSize 640x480 to VideoSize 320x240.

Lastly, change your player from vlc to ffplay

Related Question