systemd
This commit is contained in:
72
README.md
72
README.md
@@ -1,9 +1,12 @@
|
|||||||
|
|
||||||
Prerequisities
|
Prerequisities
|
||||||
--------------
|
--------------
|
||||||
|
Update the Raspberry Pi OS
|
||||||
|
> `sudo apt update`
|
||||||
|
`sudo apt full-upgrade`
|
||||||
|
|
||||||
Install the collection of command line video4linux utilities
|
Install the collection of command line video4linux utilities
|
||||||
> `sudo apt-get install v4l-utils`
|
> `sudo apt install v4l-utils ffmpeg`
|
||||||
|
|
||||||
Lists all available cameras
|
Lists all available cameras
|
||||||
> `v4l2-ctl --list-devices`
|
> `v4l2-ctl --list-devices`
|
||||||
@@ -64,14 +67,9 @@ Or using ffmpeg
|
|||||||
Compressed: mjpeg : Motion-JPEG : 160x120 176x144 320x240 352x288 640x480 800x600 960x720
|
Compressed: mjpeg : Motion-JPEG : 160x120 176x144 320x240 352x288 640x480 800x600 960x720
|
||||||
Raw : yuyv422 : YUYV 4:2:2 : 160x120 176x144 320x240 352x288 640x480 800x600 960x720 1600x1200
|
Raw : yuyv422 : YUYV 4:2:2 : 160x120 176x144 320x240 352x288 640x480 800x600 960x720 1600x1200
|
||||||
```
|
```
|
||||||
Lists all available audio recording devices
|
Record a video
|
||||||
> `arecord -l`
|
> `ffmpeg -f v4l2 -input_format h264 -video_size 1920x1080 -framerate 30 -i /dev/video0 -vcodec copy video.mp4`
|
||||||
```
|
|
||||||
**** List of CAPTURE Hardware Devices ****
|
|
||||||
card 1: Q9000 [QuickCam Pro 9000], device 0: USB Audio [USB Audio]
|
|
||||||
Subdevices: 1/1
|
|
||||||
Subdevice #0: subdevice #0
|
|
||||||
```
|
|
||||||
Live Streaming
|
Live Streaming
|
||||||
--------------
|
--------------
|
||||||
Use you own `LIVE-STREAM-KEY` and run
|
Use you own `LIVE-STREAM-KEY` and run
|
||||||
@@ -84,6 +82,14 @@ Note: Does not work on Waylad ([What is Wayland in Linux Distros and Should You
|
|||||||
> `DISPLAY=:0 ffmpeg -hide_banner -f x11grab -framerate 5 -video_size 830x630 -i :0.0+50,95 -vf format=pix_fmts=yuv420p -vcodec libx264 -tune zerolatency -preset veryfast -f flv rtmp://peertube.virtonline.eu:1935/live/LIVE-STREAM-KEY`
|
> `DISPLAY=:0 ffmpeg -hide_banner -f x11grab -framerate 5 -video_size 830x630 -i :0.0+50,95 -vf format=pix_fmts=yuv420p -vcodec libx264 -tune zerolatency -preset veryfast -f flv rtmp://peertube.virtonline.eu:1935/live/LIVE-STREAM-KEY`
|
||||||
|
|
||||||
### Live stream camera with sound and desktop as an overlay to peertube
|
### Live stream camera with sound and desktop as an overlay to peertube
|
||||||
|
Lists all available audio recording devices
|
||||||
|
> `arecord -l`
|
||||||
|
```
|
||||||
|
**** List of CAPTURE Hardware Devices ****
|
||||||
|
card 1: Q9000 [QuickCam Pro 9000], device 0: USB Audio [USB Audio]
|
||||||
|
Subdevices: 1/1
|
||||||
|
Subdevice #0: subdevice #0
|
||||||
|
```
|
||||||
> `DISPLAY=:0` # select display (only if run remotely e.g. ssh)
|
> `DISPLAY=:0` # select display (only if run remotely e.g. ssh)
|
||||||
`ffmpeg -hide_banner` # do not output compile flags
|
`ffmpeg -hide_banner` # do not output compile flags
|
||||||
`-thread_queue_size 4096 -f pulse -ac 2 -i default` # audio input from PulseAudio
|
`-thread_queue_size 4096 -f pulse -ac 2 -i default` # audio input from PulseAudio
|
||||||
@@ -105,56 +111,52 @@ Use the dockerized ffmpeg with precompiled vaapi support, adjust `/dev/video2`
|
|||||||
Adjust `/dev/video2`, `-video_size 1920x1080 -framerate 60` and stream to peertube (if it can handle that much)
|
Adjust `/dev/video2`, `-video_size 1920x1080 -framerate 60` and stream to peertube (if it can handle that much)
|
||||||
> `ffmpeg -hide_banner -y -f v4l2 -input_format mjpeg -video_size 1920x1080 -framerate 60 -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i /dev/video2 -vf 'scale_vaapi=format=nv12' -c:v h264_vaapi -b:v 10M -f flv rtmp://peertube.virtonline.eu:1935/live/LIVE-STREAM-KEY`
|
> `ffmpeg -hide_banner -y -f v4l2 -input_format mjpeg -video_size 1920x1080 -framerate 60 -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i /dev/video2 -vf 'scale_vaapi=format=nv12' -c:v h264_vaapi -b:v 10M -f flv rtmp://peertube.virtonline.eu:1935/live/LIVE-STREAM-KEY`
|
||||||
|
|
||||||
### Setup a systemd service for the non-stop streaming
|
### Setup a systemd service for a non-stop streaming
|
||||||
Adjust `jrottenberg/ffmpeg:4.4-alpine` if you want to use a specific ffmpeg version. For Raspberry Pi (ARM) see https://github.com/colin-nolan/docker-ffmpeg-rpi
|
|
||||||
```
|
```
|
||||||
sudo tee /etc/systemd/system/virt-garage-webcam-streamer.service <<EOF
|
sudo tee /etc/systemd/system/webcam-streamer.service <<EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Garage Webcam Streamer service
|
Description=Webcam Streamer service
|
||||||
Requires=docker.service
|
Requires=network-online.target
|
||||||
After=docker.service
|
After=network-online.target
|
||||||
DefaultDependencies=no
|
DefaultDependencies=no
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
||||||
Environment="HOME=/root"
|
Environment="HOME=/root"
|
||||||
Environment=WEBCAM_URI="rtsp://garagecam.virtonline.eu:554/live3.sdp"
|
|
||||||
Environment=PEERTUBE_LIVE="rtmp://peertube.virtonline.eu:1935/live/LIVE-STREAM-KEY"
|
Environment=PEERTUBE_LIVE="rtmp://peertube.virtonline.eu:1935/live/LIVE-STREAM-KEY"
|
||||||
Environment=FFMPEG="docker run --rm --name virt-garage-webcam-streamer jrottenberg/ffmpeg:4.4-alpine"
|
|
||||||
|
|
||||||
ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker kill virt-garage-webcam-streamer 2>/dev/null || true'
|
ExecStartPre=-/usr/bin/env sh -c 'killall ffmpeg 2>/dev/null || true'
|
||||||
ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-garage-webcam-streamer 2>/dev/null || true'
|
|
||||||
|
|
||||||
# Re-stream (Audio/Video) from IP camera to peertube live
|
ExecStart=/bin/bash -c 'ffmpeg -loglevel error \
|
||||||
ExecStart=/bin/bash -c '${FFMPEG} -loglevel error \
|
-f v4l2 -input_format h264 \
|
||||||
-i ${WEBCAM_URI} \
|
-video_size 1920x1080 \
|
||||||
-c copy \
|
-framerate 20 \
|
||||||
-f flv \
|
-i /dev/video0 \
|
||||||
|
-c copy -f flv \
|
||||||
|
-tune zerolatency \
|
||||||
${PEERTUBE_LIVE}'
|
${PEERTUBE_LIVE}'
|
||||||
|
|
||||||
ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker kill virt-garage-webcam-streamer 2>/dev/null || true'
|
ExecStop=-/usr/bin/env sh -c 'killall ffmpeg 2>/dev/null || true'
|
||||||
ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-garage-webcam-streamer 2>/dev/null || true'
|
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
SyslogIdentifier=virt-garage-webcam-streamer
|
SyslogIdentifier=webcam-streamer
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
Reload systemd manager configuration
|
Reload systemd manager configuration
|
||||||
|
|
||||||
`sudo systemctl daemon-reload`
|
`sudo systemctl daemon-reload`
|
||||||
|
|
||||||
Enable the virt-garage-webcam-streamer service at boot time and also run it
|
Start the service
|
||||||
|
`sudo systemctl start webcam-streamer`
|
||||||
|
|
||||||
`sudo systemctl enable --now virt-garage-webcam-streamer`
|
If it does not work check logs
|
||||||
|
`journalctl -f -u webcam-streamer`
|
||||||
If it does not work check logs
|
|
||||||
|
|
||||||
`journalctl -f -u virt-garage-webcam-streamer`
|
|
||||||
|
|
||||||
|
Enable the webcam-streamer service at boot time
|
||||||
|
`sudo systemctl enable webcam-streamer`
|
||||||
|
|
||||||
### Transcode and scale video file (and copy audio) using VAAPI (see [HWAccelIntro](https://trac.ffmpeg.org/wiki/HWAccelIntro))
|
### Transcode and scale video file (and copy audio) using VAAPI (see [HWAccelIntro](https://trac.ffmpeg.org/wiki/HWAccelIntro))
|
||||||
> `alias ffmpeg='docker run --rm -w $(pwd) -v $(pwd):$(pwd) --device=/dev/dri jrottenberg/ffmpeg:vaapi'`
|
> `alias ffmpeg='docker run --rm -w $(pwd) -v $(pwd):$(pwd) --device=/dev/dri jrottenberg/ffmpeg:vaapi'`
|
||||||
|
|||||||
Reference in New Issue
Block a user