pfharlock
Posts: 11
Joined: Sat Oct 08, 2016 1:30 pm

HOWTO: stream raspberry pi camera video output to another computer using raspivid, netcat, and vlc

Wed Dec 04, 2019 4:05 am

so here is a simple formula for forwarding a video stream from the pi camera to another computer with relatively low latency (around half a second latency on a pi zero w) I tried another method that only involved vlc but not netcat and the latency for that was >2 seconds....

on viewing side... netcat -l -p 5000 | vlc stream:///dev/stdin :demux=h264 --h264-fps=24

on camera side... raspivid -vf -o - -t 0 -n -w 320 -h 240 -fps 24 | nc 192.168.1.<whatever> 5000

Hopefully this helps someone, with this my robot is drive-able.

If anyone knows a good way to get the latency down to the 0-<not noticeable> range, please feel free to chime in :)

User avatar
HermannSW
Posts: 1658
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: HOWTO: stream raspberry pi camera video output to another computer using raspivid, netcat, and vlc

Wed Dec 04, 2019 7:49 am

Lowest latency I have seen among several solutions is using uv4l raspicam driver:
http://www.linux-projects.org/uv4l/installation/

As long as you use it for private projects, usage is free.
Some people don't want to use that because of licensing terms, or because it is not open source.
But they use Raspberry camera and the GPU code is closed source as well ...

The instructions above do not cover Buster yet.
But you can install and use on Buster as well:
viewtopic.php?t=247305#p1572013
(The 676ms latency in that posting were because of slow wireless laptop used for display, you can get much less latency with uv4l)
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7572
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: HOWTO: stream raspberry pi camera video output to another computer using raspivid, netcat, and vlc

Wed Dec 04, 2019 12:52 pm

Adding -fl to the raspivid parameters will reduce it a bit.

Linux pipes are still block based devices, therefore they typically kick the sink end when the block is full, which is not the same as single writes. Adding -fl calls fflush after each write, and that should avoid the buffering.
I'm not aware of a way of doing the same thing with netcat, but I haven't looked.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”