Last active
January 20, 2023 13:32
-
-
Save m1ari/7501151 to your computer and use it in GitHub Desktop.
Stream raspberry pi camera over multicast and cope with raspivid exiting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This requires a couple of windows (or a screen/tmux session) | |
First create a fifo to use | |
mkfifo video.h264 | |
In the first window start raspivid in the following way | |
while true; do raspivid -n -vf -hf -w 460 -h 270 -b 512000 -t 36000000 -o video.h264 -v; done | |
In the second window start vlc like: | |
cvlc video.h264 --sout "#duplicate{dst=std{access=udp,mux=ts,dst=239.255.1.2:1234}}" :demux=h264 --ttl 4 -I http --sout-keep -v --loop | |
With this setup raspivid will run for the time specified by -t (10 hours in this case) if that timeout arrives or it fails for some other reason it will get restarted. The h264 stream is then sent to the fifo named video.h264 (this could be called anything but will need the .h264 extension) | |
VLC then reads in from the fifo and sends the video over a multicast stream to other clients. | |
On a client (on the same local network unless your network is multicast enabled you can run vlc and request the network stream udp://@239.255.1.2:1234 | |
It's also possible to use ffmpeg to stream the data over multicast using a command like | |
ffmpeg -re -f h264 -i video.h264 -metadata title="PiTV" -f sap -vcodec copy -acodec null rtp://239.255.1.1:1234 | |
With this the stream will appear as PiTV in the "Network Streams (SAP)" section of vlc's playlist | |
This is similar to the setup that uses a pipe (raspivid -o - | cvlc stream:///dev/stdin) but uses a named fifo to transfer the data allowing you to detect either application failing. | |
To recieve the multicast stream and send to BATC this seems to work | |
ffmpeg -re -f sap -i PiTV -f flv -vcodec copy -acodec null rtmp://fms.batc.tv/live/q4de2m6n/q4de2m6n | |
(Failed on a VM but worked on the same pi doing the streaming.) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment