I have to stream two webcam videos from a Raspberry Pi 0 to a mac book air. The webcam is a Trust Trino HD webcam.

Ideally the streams shall have the maximum possibile frame rate (5fps), resolution (1280x720) and quality, with the lowest possibile latency (less then 200 ms).

I use ffmpeg (for streaming) on the raspberry and mpv (for reproduction) on the mac.

After an online search I've found that the Raspberry support hardware encoding using h264 with the codec h264_v4l2m2m. For the mpv I've try to optimize the setting to minimize the latency.

ffmpeg -y \
-f v4l2 -framerate 30 -video_size 640x480 -input_format yuyv422 \
-i /dev/video0 \
-c:v h264_v4l2m2m -bf 0 -f mpegts -b:v 1M -an \
mpv udp:// --no-cache --untimed --no-correct-pts --untimed --no-demuxer-thread --vd-lavc-threads=1

Additioanl notes

  • I've also measured the available bandwith between the two machines and it's approx. 50 Mb/sec.

  • Streaming two webcam at 1280x720p at 5 fps the CPU load is approx 50% and a little bit less that half is the RAM utilization.

  • Streaming two webcam at 1280x720p at 5 fps the latency is around 5 seconds which is too much! and the quality isn't great.

  • I've try to use mjpeg istead of h264 to reduce the compression/decompression time but the CPU usage is around 100% with one camera and the delay is someting around 10 seconds or greater.

  • I've also try to reduce the resolution (640x480) and increase the fps (to 30), the latency is reduce to around 1 sec. This is an option but I would like to have the extra pixels.

  • Besides the latency, the other problem is the quality. I've try to change the encoding option but it's seems they are not supported by h264_v4l2m2m.

Are there some setting that I can apply to ffmpeg to reduce the latency and increse the quality? How can I increase video quality? Is the ffmpeg the best option for my scenario?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.