From 3b4fae99a10deedef0364c719d44a0db33f71745 Mon Sep 17 00:00:00 2001 From: cpu Date: Sun, 31 Dec 2023 17:23:19 +0100 Subject: [PATCH] systemd --- README.md | 72 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index dfe638d..3534855 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ Prerequisities -------------- +Update the Raspberry Pi OS +> `sudo apt update` +`sudo apt full-upgrade` Install the collection of command line video4linux utilities -> `sudo apt-get install v4l-utils` +> `sudo apt install v4l-utils ffmpeg` Lists all available cameras > `v4l2-ctl --list-devices` @@ -64,14 +67,9 @@ Or using ffmpeg 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 ``` -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 -``` +Record a video +> `ffmpeg -f v4l2 -input_format h264 -video_size 1920x1080 -framerate 30 -i /dev/video0 -vcodec copy video.mp4` + Live Streaming -------------- 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` ### 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) `ffmpeg -hide_banner` # do not output compile flags `-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) > `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 -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 +### Setup a systemd service for a non-stop streaming ``` -sudo tee /etc/systemd/system/virt-garage-webcam-streamer.service </dev/null || true' -ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-garage-webcam-streamer 2>/dev/null || true' +ExecStartPre=-/usr/bin/env sh -c 'killall ffmpeg 2>/dev/null || true' -# Re-stream (Audio/Video) from IP camera to peertube live -ExecStart=/bin/bash -c '${FFMPEG} -loglevel error \ - -i ${WEBCAM_URI} \ - -c copy \ - -f flv \ +ExecStart=/bin/bash -c 'ffmpeg -loglevel error \ + -f v4l2 -input_format h264 \ + -video_size 1920x1080 \ + -framerate 20 \ + -i /dev/video0 \ + -c copy -f flv \ + -tune zerolatency \ ${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 '/usr/bin/env docker rm virt-garage-webcam-streamer 2>/dev/null || true' +ExecStop=-/usr/bin/env sh -c 'killall ffmpeg 2>/dev/null || true' Restart=always RestartSec=5 -SyslogIdentifier=virt-garage-webcam-streamer +SyslogIdentifier=webcam-streamer [Install] WantedBy=multi-user.target EOF ``` -Reload systemd manager configuration - +Reload systemd manager configuration `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 virt-garage-webcam-streamer` +If it does not work check logs +`journalctl -f -u 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)) > `alias ffmpeg='docker run --rm -w $(pwd) -v $(pwd):$(pwd) --device=/dev/dri jrottenberg/ffmpeg:vaapi'`