Version 1
The setup described in the original post.
- Webcam connected to Proxmox host
- Webcam attached to VM running kubernetes
- Pod mounting that
/dev/video0
runningffmpeg
It worked but there were some stability issues. Still not sure why, but sometimes, things would crash horribly. The stream would be fine for a while, then I would notice the live feed was down, and also that the Proxmox node was inaccessible. This happened a lot. And it was super frustrating.
Version 2
![](https://minio.travnewmatic.com/mastodon/media_attachments/files/106/685/828/136/835/793/original/cf67d152614d2034.jpg)
Removed the webcam from the Proxmox node, and setup a Raspberry Pi running ffmpeg
as a systemd
service. This was very reliable! Maybe had one or two hiccups, but otherwise this was extremely stable.
I added a second webcam, and a second systemd
service to watch the street in front of my apartment. That worked too. I had that streaming to my personal YouTube channel. Raspberry Pi 4 running two ffmpeg
doing two x264 transcodes makes it sweat pretty hard.
![](https://www.travnewmatic.com/wp-content/uploads/2021/08/1924047-1024x111.png)
Happy about the stability, but the stream was choppier. The video quality was never great, but the frame rate was consistent when using the beefier x86 thing.
Version 3
Two streams at the same time.
In the first iteration I had something like this:
ffmpeg -i /dev/video2 -i /dev/video0 -f lavfi -i anullsrc -f flv -filter_complex hstack -rtmp_live live -c:v libx264 rtmp://a.rtmp.youtube.com/live2/youtube-key-here
Which produced something like this:
![](https://www.travnewmatic.com/wp-content/uploads/2021/08/14513488279996-1024x612.png)
This also let me go from two ffmpeg
processes to one, greatly reducing CPU load.
Version 4
Add more Pi’s!
![](https://www.travnewmatic.com/wp-content/uploads/2021/08/14517196080321-1024x473.jpg)
I wanted to put one camera at the other end of the windowsill, but the USB cables wouldn’t allow for it. I wanted to try to make ffmpeg
listen for incoming connections. I used this setup before so motion
could grab frames and post them to mastodon.
- Pi camera close to the nest (on the left):
ffmpeg -i rtmp://192.168.1.14:1935
-i /dev/video0 -f lavfi -i anullsrc -f flv -rtmp_live live -c:v libx264 rtmp://a.rtmp.youtube.com/live2/
token-goes-here - Pi camera on the right:
ffmpeg -i /dev/video0 -f flv -rtmp_live live -listen 2 rtmp://:1935
I would like to give the ffmpeg
doing x264 duties more horsepower, so…
Version 5
Both Pi cameras are running:
ffmpeg -i /dev/video0 -f flv -rtmp_live live -listen 2 rtmp://:1935
To test, in a VM on my x86 thing i’m running:
ffmpeg -i rtmp://192.168.1.12:1935 -i rtmp://192.168.1.10:1935 -f lavfi -i anullsrc -f flv -filter_complex hstack -rtmp_live live -c:v libx264 rtmp://a.rtmp.youtube.com/live2/yt-streaming-token-here
This ran for most of the night last night, but when i woke up this morning, the stream was dead 🙁
Version 6
Need to bring it into Kubernetes.
apiVersion: v1
items:
- apiVersion: v1
kind: Endpoints
metadata:
name: raspberrypi-cam0
namespace: webcam
subsets:
- addresses:
- ip: 192.168.1.10
ports:
- port: 1935
protocol: TCP
- apiVersion: v1
kind: Service
metadata:
name: raspberrypi-cam0
namespace: webcam
spec:
ports:
- port: 1935
protocol: TCP
targetPort: 1935
sessionAffinity: None
type: ClusterIP
- apiVersion: v1
kind: Endpoints
metadata:
name: raspberrypi-cam1
namespace: webcam
subsets:
- addresses:
- ip: 192.168.1.12
ports:
- port: 1935
protocol: TCP
- apiVersion: v1
kind: Service
metadata:
name: raspberrypi-cam1
namespace: webcam
spec:
ports:
- port: 1935
protocol: TCP
targetPort: 1935
sessionAffinity: None
type: ClusterIP
kind: List
metadata:
resourceVersion: ""
selfLink: ""
This will let me hit the external RTMP streams from within the cluster. New deployment configuration looks like this:
spec:
containers:
- command:
- ffmpeg
- -i
- rtmp://raspberrypi-cam0.webcam.svc.cluster.local:1935
- -i
- rtmp://raspberrypi-cam1.webcam.svc.cluster.local:1935
- -f
- lavfi
- -i
- anullsrc
- -f
- flv
- -rtmp_live
- live
- -c:v
- libx264
- rtmp://a.rtmp.youtube.com/live2/yt-stream-token
- -f
- flv
- -filter_complex
- hstack
- -rtmp_live
- live
- -listen
- "2"
- rtmp://:1935
image: jrottenberg/ffmpeg
imagePullPolicy: Always
name: ffmpeg
ports:
- containerPort: 1935
name: rtmp
protocol: TCP
And it appears to be working! We’ll see how long this lasts.
![](https://www.travnewmatic.com/wp-content/uploads/2021/08/image-1024x576.png)
I swapped out the Raspberry Pi 4’s for 3’s. Since transcoding is happening elsewhere, the Pi’s aren’t really working all that hard.
![](https://www.travnewmatic.com/wp-content/uploads/2021/08/image-1-1024x560.png)
Later, when i get my kubernetes monitoring stuff in order (again) I’ll put node_exporter on them so I can have pretty graphs.
Leave a Reply