very low latency streaminig with ffmpeg using a webcam
Asked Answered
Z

2

6

I'm trying to configure ffmpeg to do a real-time video streaming using a webcam. The ffmpeg encoder command I use is as follows.

ffmpeg -f v4l2 -input_format yuyv422 -s 640x480 -i /dev/video0 -c:v libx264 -profile:v baseline -trellis 0 -subq 1 -level 32 -preset superfast -tune zerolatency -me_method epzs -crf 30 -threads 0 -bufsize 1 -refs 4 -coder 0 -b_strategy 0 -bf 0 -sc_threshold 0 -x264-params vbv-maxrate=2000:slice-max-size=1500:keyint=30:min-keyint=10: -pix_fmt yuv420p -an -f mpegts udp://192.168.1.8:5001

The ffplay command used to display the video feed is,

ffplay -analyzeduration 1 -fflags -nobuffer -i udp://192.168.1.8:5001

However, I'm experiencing a latency of 0.5 - 1.0s latency in the video stream. Is there a way to reduce this to a number less than 100ms. Also, when I replace the v4l2 camera capture with a screen capture using x11grab, the stream is almost real-time and I experience no noticeable delays. Moreover, changing the encoder from x264 to mpeg2 had no effect on the latency. In addition, the statistics from the ffmpeg shows that the encoder is performing at a 30fps rate, which I believe indicates that the encoding is real-time. This leaves me with only one reason for the experienced delay.

  • Is there a significant delay in buffers when using v4l2 during video capturing in a webcam?
  • I don't think the transmission delay is in effect in this case as I see no latencies when screen capture is used under the same conditions.
  • Can this latency be further reduced?. Can someone think of a different encoder configuration to be used instead of the one that I've been using?
Zagazig answered 22/3, 2017 at 13:51 Comment(0)
B
0

i used the same send instruction and i tried this with the ffplay and it worked for me:

ffplay -analyzeduration 1 -fflags -nobuffer -probesize 32 -sync ext -i rtmp://localhost/live/STREAM_NAME
Blatant answered 2/8, 2018 at 7:29 Comment(0)
R
0

I had also many problems in setting up a low latency video streaming system between an odroid spc and windows pc. Finally i found settings resulting in approx 500ms to max. 1s latency.

Setup: ffserver on odroid xu4 with ubuntu 18.04, connected via wifi dongle to network. Windows 10 PC in same wifi network streaming from odroid.

I run the following ffserver config (/etc/ffserver.conf) on my odroid

HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxClients 1000
MaxBandwidth 10000

<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 50M
ACL allow 127.0.0.1
ACL allow localhost
</Feed>

<Stream test1.asf>
Format asf
Feed feed1.ffm
VideoFrameRate 30
VideoSize 640x480
VideoBitRate 600 
#VideoBufferSize 400
VideoQMin 1
VideoQMax 20
NoAudio
ACL allow 127.0.0.1
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>

<Stream stat.html>
Format status
ACL allow 127.0.0.1
ACL allow localhost
</Stream>

and start the camera stream on the odroid with

ffserver -f /etc/ffserver.conf & ffmpeg -f v4l2 -s 640x480 -r 15 -i /dev/video0 -vcodec libx265 -threads 2 -tune zerolatency http://localhost:8090/feed1.ffm

On my Windows PC I tried several settings to get low latency. With VLC-Player I could not manage anything below 8 to 10 seconds. With the following ffplay command I got about 500ms latency:

ffplay -fflags -nobuffer -probesize 32 -i mmsh://ubuntu1804:8090/test1.asf

so, -sync ext and -analyzeduration 1 did not help in reducing the latency.

The "stream production" on the odroid also runs with the same low latency when using libx264 instead of libx265 and removing the -thread 2 flag. But increasing the framerate to 30 or even increasing the resolution leads to significant delays.

Regent answered 30/12, 2018 at 22:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.