From 4f697abc4f7f33e81ef2078bf657e403e8772fee Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 14 Jul 2024 02:20:13 +0000 Subject: [PATCH] Add Scanner AV Streaming on VM in Unraid --- Scanner-AV-Streaming-on-VM-in-Unraid.md | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Scanner-AV-Streaming-on-VM-in-Unraid.md diff --git a/Scanner-AV-Streaming-on-VM-in-Unraid.md b/Scanner-AV-Streaming-on-VM-in-Unraid.md new file mode 100644 index 0000000..14635ee --- /dev/null +++ b/Scanner-AV-Streaming-on-VM-in-Unraid.md @@ -0,0 +1,68 @@ +This article will go through my setup for hosting a scanner A/V stream from an Ubuntu Server VM. + +#Stack +* UnRAID 6.12 running on an old Alienware desktop +* Ubuntu 20.04.6 LTS Virtual Machine +* ALSA +* ffmpeg +* mediamtx +* Radioshack Pro-651 (any scanner with headphone-out should work) +* Logitech C90 webcam + +#Guide +##Assign devices to VM +(This is only necessary if your sound card is PCI-connected) +1. In UnRAID go to Tools -> System Devices +2. Check the box(ex) for the IOMMU group(s) for your audio card +3. Reboot the server + +##Set up the VM +1. Download Ubuntu Server ISO to UnRAID server +2. Create an Ubuntu VM in UnRAID +* Pass through a few CPU cores, at least to start with, this will make installation faster +* Choose 2048-4096MB min ram, at least. Again can be scaled back after installation +* 10GB vdisk should be enough, 20GB is what I used. +* Leave graphic card as is, you'll need VNC to complete the initial installation +* Assign the sound card to the VM +* Assign the USB webcam to the VM +3. Start up the VM and proceed through installation of Ubuntu Server +4. (Optional) Shutdown the VM and adjust the specs back to minimal (1G RAM, 1-2CPU cores) + +##Set up the Software Stack +1. Run these commands +``` +sudo apt update && sudo apt upgrade -y +sudo apt install ffmpeg +wget https://github.com/bluenviron/mediamtx/releases/download/v1.8.4/mediamtx_v1.8.4_linux_amd64.tar.gz +tar -xvf mediamtx_v1.8.4_linux_amd64.tar.gz +sudo mv mediamtx /usr/local/bin/ +``` +2. Edit mediamtx.yml and remove the `paths:` at the end, replacing with: +``` +paths: + scanner: + source: publisher + runOnInit: ffmpeg -f v4l2 -i /dev/video0 -f alsa -i hw:0 -c:v libx264 -preset veryfast -tune zerolatency -pix_fmt yuv420p -f rtsp rtsp://localhost:8554/scanner +``` + +### Paths Section: +- **paths**: This section contains the definitions for different streaming paths. + - **scanner**: This is the name of the path. You can name it whatever makes sense for your use case, such as `scanner`, `camera`, or `stream`. + +### Path Configuration: +- **source: publisher**: This specifies that the stream for this path will be published by an external source. In this case, the source is the FFmpeg command specified in `runOnInit`. +- **runOnInit**: This directive tells MediaMTX to run the specified command when the server starts. The command provided here will initialize the stream. + +### FFmpeg Command Explanation: +- **ffmpeg**: This is the command-line tool used to handle multimedia data. +- **-f v4l2 -i /dev/video0**: This tells FFmpeg to use the Video4Linux2 (v4l2) input format to capture video from the device `/dev/video0`, which is your USB webcam. +- **-f alsa -i hw:0**: This specifies the ALSA input format to capture audio from the device `hw:0`. +- **-c:v libx264**: This sets the video codec to H.264 using the `libx264` encoder. +- **-preset veryfast**: This option sets the encoding preset to `veryfast`, balancing compression efficiency and encoding speed. +- **-tune zerolatency**: This tuning option minimizes latency, which is crucial for real-time streaming. +- **-pix_fmt yuv420p**: This sets the pixel format to `yuv420p`, which is widely compatible with most players and devices. +- **-f rtsp rtsp://localhost:8554/scanner**: This sets the output format to RTSP and specifies the RTSP URL where the stream will be available, in this case, `rtsp://localhost:8554/scanner`. + + + +This configuration sets up MediaMTX to serve RTSP and HLS streams, with the `scanner` path specifically set up to capture and stream video and audio using FFmpeg. \ No newline at end of file