### Install v4l2rtspserver Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Install the v4l2rtspserver application on the system. This is an optional step. ```bash sudo make install ``` -------------------------------- ### Create a Start Script for v4l2rtspserver Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Setup-on-Pi A bash script to load the necessary kernel module and then start the v4l2rtspserver with predefined parameters. ```bash #!/bin/bash sudo modprobe -v bcm2835-v4l2 v4l2rtspserver -F15 -H 972 -W1296 -P 8555 /dev/video0 ``` -------------------------------- ### Install v4l2rtspserver Dependencies and Build Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Setup-on-Pi Installs necessary packages and builds the v4l2rtspserver from source. If live555 causes issues, a specific command is provided to re-download and build it. ```bash sudo apt-get install cmake liblog4cpp5-dev libv4l-dev git clone https://github.com/mpromonet/v4l2rtspserver.git cd v4l2rtspserver/ cmake . make sudo make install ``` ```bash rm -rf live live555.tar.gz CMakeFiles CMakeCache.txt *.cmake cmake -D LIVE555URL=https://download.videolan.org/pub/contrib/live555/live.2021.01.29.tar.gz . make ``` -------------------------------- ### Install Build Dependencies and Build v4l2rtspserver Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Installs necessary build dependencies on Debian/Ubuntu systems and then clones, builds, and installs the v4l2rtspserver binary. Includes verification and an alternative for live555 download failures. ```bash # Install build dependencies (Debian/Ubuntu) sudo apt-get install cmake libv4l-dev libasound2-dev libssl-dev liblog4cpp5-dev # Clone and build git clone https://github.com/mpromonet/v4l2rtspserver.git cd v4l2rtspserver cmake . make sudo make install # Verify installation v4l2rtspserver -V # Output: # If live555 download fails, use a known-good mirror cmake -DLIVE555URL=https://download.videolan.org/pub/contrib/live555/live.2021.01.29.tar.gz . make ``` -------------------------------- ### Start RTSP Server with Multiple Video Sessions Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Start the RTSP server to create multiple sessions, each capturing video from a different device. ```bash v4l2rtspserver /dev/video0 /dev/video1 ``` -------------------------------- ### Start RTSP Server with Audio and Video from Same Device Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Start the RTSP server to capture both audio and video, associating the ALSA device with the V4L2 device. ```bash v4l2rtspserver /dev/video0,/dev/video0 ``` -------------------------------- ### Start RTSP Server with Audio and Video Capture Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Start the RTSP server to capture both audio and video from their respective devices. ```bash v4l2rtspserver /dev/video0,default ``` -------------------------------- ### Start RTSP Server with Video Capture Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Start the RTSP server to capture video from a specified V4L2 device. ```bash v4l2rtspserver /dev/video0 ``` -------------------------------- ### Start RTSP Server with Audio Capture Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Start the RTSP server to capture audio from a specified ALSA device. ```bash v4l2rtspserver ,default ``` -------------------------------- ### Start RTSP Server with Separate Audio and Video Sessions Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Start the RTSP server to create two separate sessions, one for video and one for audio. ```bash v4l2rtspserver /dev/video0 ,default ``` -------------------------------- ### Start Basic RTSP Unicast Streaming Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Starts streaming from the default V4L2 device (/dev/video0) on the default RTSP port (8554). The server automatically selects the best supported codec. Examples show how to play the stream using ffplay, VLC, and GStreamer. ```bash # Stream /dev/video0 on rtsp://:8554/unicast v4l2rtspserver /dev/video0 # Play with ffplay ffplay rtsp://192.168.1.10:8554/unicast # Play with VLC vlc rtsp://192.168.1.10:8554/unicast # Play with GStreamer (H264) gst-launch-1.0 rtspsrc location=rtsp://192.168.1.10:8554/unicast ! decodebin ! autovideosink ``` -------------------------------- ### Docker Deployment Examples Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Run v4l2rtspserver within a Docker container, exposing host V4L2 devices and custom parameters. ```bash # Basic run (no device, for testing) docker run -p 8554:8554 -it mpromonet/v4l2rtspserver ``` ```bash # Expose host /dev/video0 docker run --device=/dev/video0 -p 8554:8554 -it mpromonet/v4l2rtspserver ``` ```bash # Custom parameters: custom resolution + HLS enabled docker run --device=/dev/video0 -p 8554:8554 \ -it mpromonet/v4l2rtspserver \ -W 1280 -H 720 -F 25 -S ``` ```bash # Print help from container docker run -it mpromonet/v4l2rtspserver -h ``` -------------------------------- ### Stream Authentication Setup Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Protect streams using username/password with '-U'. Use '-R' with MD5-hashed passwords for enhanced security. ```bash # Plain-text credentials (multiple users) v4l2rtspserver -U admin:secret -U viewer:readonly /dev/video0 ``` ```bash # MD5-hashed credentials (more secure) REALM=mycamera v4l2rtspserver -R "$REALM" \ -U "admin:$(echo -n admin:${REALM}:secret | md5sum | cut -d' ' -f1)" \ -U "viewer:$(echo -n viewer:${REALM}:pass | md5sum | cut -d' ' -f1)" \ /dev/video0 ``` ```bash # Play authenticated stream with ffplay ffplay "rtsp://admin:secret@192.168.1.10:8554/unicast" ``` -------------------------------- ### Run v4l2rtspserver Manually Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Setup-on-Pi Example command to run the v4l2rtspserver with specific frame rate, resolution, and port settings for a given video device. ```bash v4l2rtspserver -F15 -H 972 -W1296 -P 8555 /dev/video0 ``` -------------------------------- ### Play HLS/DASH Streams Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Examples for playing HLS and MPEG-DASH streams using VLC, GStreamer, and MP4Client. ```bash vlc http://192.168.1.10:8554/ts.m3u8 ``` ```bash gst-launch-1.0 playbin uri=http://192.168.1.10:8554/ts.m3u8 ``` ```bash MP4Client http://192.168.1.10:8554/ts.mpd ``` -------------------------------- ### Get v4l2rtspserver help in Docker Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Run the v4l2rtspserver Docker container and display the application's help message. ```bash docker run -it mpromonet/v4l2rtspserver -h ``` -------------------------------- ### Enable v4l2rtspserver Systemd Service Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Setup-on-Pi Command to enable the v4l2rtspserver service, ensuring it starts automatically when the system boots. ```bash sudo systemctl enable v4l2rtspserver ``` -------------------------------- ### Configure Resolution, Framerate, and Port Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Customizes capture settings like resolution (width/height), framerate, and the RTSP port. Also demonstrates forcing a specific capture format (H264) and using a shorthand geometry flag. Includes an example for Raspberry Pi cameras. ```bash # 1280x720 @ 30 fps on port 8555, custom unicast URL path v4l2rtspserver -W 1280 -H 720 -F 30 -P 8555 -u live /dev/video0 # Stream available at: rtsp://:8555/live # Shorthand geometry flag v4l2rtspserver -G 1920x1080x25 -P 8554 /dev/video0 # Force a specific capture format (H264) v4l2rtspserver -fH264 -W 1280 -H 720 -F 30 /dev/video0 # Raspberry Pi camera (bcm2835-v4l2 driver) at 15 fps sudo modprobe -v bcm2835-v4l2 v4l2rtspserver -F 15 -H 972 -W 1296 -P 8555 /dev/video0 ``` -------------------------------- ### Create a Systemd Service for v4l2rtspserver Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Setup-on-Pi Defines a systemd service unit to automatically start the v4l2rtspserver on boot. It specifies the executable path, user, and restart behavior. ```systemd [Unit] Description=V4L2 RTSP server After=network.target [Service] Type=simple ExecStart=/usr/local/bin/v4l2rtspserver -F15 -H 972 -W1296 -P 8555 /dev/video0 User=pi Restart=always RestartSec=1 StartLimitIntervalSec=0 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Systemd Service Configuration Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Configure v4l2rtspserver to run as a persistent background service on Linux using systemd. Includes installation and management commands. ```ini # /lib/systemd/system/v4l2rtspserver.service [Unit] Description=V4L2 RTSP server After=network.target [Service] Type=simple ExecStart=/usr/local/bin/v4l2rtspserver -F 15 -H 972 -W 1296 -P 8555 /dev/video0 User=pi Restart=always RestartSec=1 StartLimitIntervalSec=0 [Install] WantedBy=multi-user.target ``` ```bash # Install and enable the service sudo cp v4l2rtspserver.service /lib/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable v4l2rtspserver sudo systemctl start v4l2rtspserver sudo systemctl status v4l2rtspserver ``` -------------------------------- ### Enable HLS and MPEG-DASH HTTP Streaming Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Activates HLS and MPEG-DASH streaming, served on the same port as the RTSP server. Allows customization of segment duration. Examples show how to enable with default and custom segment durations. ```bash # Enable HLS + MPEG-DASH with 2-second segments (default) v4l2rtspserver -S /dev/video0 # HLS: http://:8554/ts.m3u8 # MPEG-DASH: http://:8554/ts.mpd # Custom segment duration (4 seconds) v4l2rtspserver -S4 -P 8080 /dev/video0 # HLS: http://:8080/ts.m3u8 ``` -------------------------------- ### Configure Multicast Streaming Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Enables multicast streaming using either an auto-assigned random group address or an explicitly defined group address and port. Provides an example for receiving H264 multicast streams with GStreamer. ```bash # Multicast with random group address (auto-assigned) v4l2rtspserver -m multicast /dev/video0 # Logs will show: RTP address :20000 # Multicast with explicit group address and port v4l2rtspserver -M 239.255.0.1:5004 -m multicast /dev/video0 # Receive H264 multicast with GStreamer (matching the group/port above) gst-launch-1.0 udpsrc port=5004 multicast-group=239.255.0.1 \ caps="application/x-rtp,media=video,encoding-name=H264" \ ! rtph264depay ! avdec_h264 ! autovideosink ``` -------------------------------- ### V4l2RTSPServer Class Usage Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Demonstrates how to instantiate the V4l2RTSPServer, create video replicators, add various media sessions (unicast, HLS), and run the event loop. ```APIDOC ## C++ API: V4l2RTSPServer Class The `V4l2RTSPServer` class is the main C++ embedding API. Instantiate it, create replicators for each device, then call `AddUnicastSession` / `AddMulticastSession` / `AddHlsSession`, and run the event loop. ```cpp #include "V4l2RTSPServer.h" #include "DeviceSourceFactory.h" // Create server on port 8554, with HLS segments of 2s, and user auth std::list users = {"admin:secret"}; V4l2RTSPServer server(8554, /*httpPort=*/0, /*timeout=*/65, /*hlsSegment=*/2, users, /*realm=*/nullptr, /*webroot=*/"", /*sslCert=*/"", /*enableRTSPS=*/false); if (!server.available()) { std::cerr << "Failed: " << server.getResultMsg() << std::endl; return 1; } // Create video capture replicator from /dev/video0 at 1280x720@30 V4L2DeviceParameters inParam("/dev/video0", {V4L2_PIX_FMT_H264}, 1280, 720, 30, IOTYPE_MMAP, O_RDWR | O_NONBLOCK); V4l2Output *out = nullptr; StreamReplicator *videoReplicator = server.CreateVideoReplicator( inParam, /*queueSize=*/5, V4L2DeviceSource::CAPTURE_INTERNAL_THREAD, /*repeatConfig=*/true, /*outputFile=*/"", IOTYPE_MMAP, out); // Add unicast RTSP session → rtsp://:8554/live ServerMediaSession *sms = server.AddUnicastSession("live", videoReplicator, nullptr); if (sms) { std::cout << "Streaming at: " << server.getRtspUrl(sms) << std::endl; } // Add HLS + MPEG-DASH session → http://:8554/ts.m3u8 server.AddHlsSession("ts", /*hlsSegment=*/2, videoReplicator, nullptr); // Run the event loop until SIGINT char stop = 0; signal(SIGINT, [](int){ /* set stop=1 externally */ }); server.eventLoop(&stop); ``` ``` -------------------------------- ### Instantiate V4l2RTSPServer and Add Sessions Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Instantiate the V4l2RTSPServer, create replicators for devices, add RTSP/HLS sessions, and run the event loop. Server configuration includes port, HLS segment duration, and user authentication. ```cpp #include "V4l2RTSPServer.h" #include "DeviceSourceFactory.h" // Create server on port 8554, with HLS segments of 2s, and user auth std::list users = {"admin:secret"}; V4l2RTSPServer server(8554, /*httpPort=*/0, /*timeout=*/65, /*hlsSegment=*/2, users, /*realm=*/nullptr, /*webroot=*/"", /*sslCert=*/"", /*enableRTSPS=*/false); if (!server.available()) { std::cerr << "Failed: " << server.getResultMsg() << std::endl; return 1; } // Create video capture replicator from /dev/video0 at 1280x720@30 V4L2DeviceParameters inParam("/dev/video0", {V4L2_PIX_FMT_H264}, 1280, 720, 30, IOTYPE_MMAP, O_RDWR | O_NONBLOCK); V4l2Output *out = nullptr; StreamReplicator *videoReplicator = server.CreateVideoReplicator( inParam, /*queueSize=*/5, V4L2DeviceSource::CAPTURE_INTERNAL_THREAD, /*repeatConfig=*/true, /*outputFile=*/"", IOTYPE_MMAP, out); // Add unicast RTSP session → rtsp://:8554/live ServerMediaSession *sms = server.AddUnicastSession("live", videoReplicator, nullptr); if (sms) { std::cout << "Streaming at: " << server.getRtspUrl(sms) << std::endl; } // Add HLS + MPEG-DASH session → http://:8554/ts.m3u8 server.AddHlsSession("ts", /*hlsSegment=*/2, videoReplicator, nullptr); // Run the event loop until SIGINT char stop = 0; signal(SIGINT, [](int){ /* set stop=1 externally */ }); server.eventLoop(&stop); ``` -------------------------------- ### Set up v4l2loopback for video compression Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Configure v4l2loopback to create a virtual V4L2 device and use v4l2compress to send compressed video to it. The v4l2rtspserver then reads from this virtual device. ```bash modprobe v4l2loopback video_nr=10 v4l2compress -fH264 /dev/video0 /dev/video10 & v4l2rtspserver /dev/video10 & ``` -------------------------------- ### Configure Audio-Only and Audio+Video Sessions Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Combines V4L2 video devices with ALSA audio devices for streaming. Shows how to create a single session with both, an audio-only session, and separate sessions for video and audio. Includes options for audio format, sample rate, and channel count, as well as auto-detection of ALSA devices. ```bash # One session: video from /dev/video0 + audio from ALSA "default" v4l2rtspserver /dev/video0,default # Stream: rtsp://:8554/unicast (audio + video) # Audio-only session (no video device before the comma) v4l2rtspserver ,default # Stream: rtsp://:8554/unicast (audio only) # Two separate sessions: one video, one audio v4l2rtspserver /dev/video0 ,default # Streams: rtsp://:8554/video0_unicast and rtsp://:8554/unicast # Audio at 48 kHz, stereo, S16_LE format v4l2rtspserver -A 48000 -C 2 -a S16_LE /dev/video0,default # Auto-detect ALSA device associated with the V4L2 device (same USB device) v4l2rtspserver /dev/video0,/dev/video0 ``` -------------------------------- ### Configure Authentication with Plain Text Passwords Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Configure user credentials using plain text passwords. Use the -U flag followed by username:password. ```bash -U foo:bar -U admin:admin ``` -------------------------------- ### Configure Authentication with MD5 Passwords Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Configure user credentials using MD5 hashed passwords. This requires specifying a realm and generating the hash for each user. ```bash -R myrealm -U foo:$(echo -n foo:myrealm:bar | md5sum | cut -d- -f1) -U admin:$(echo -n admin:myrealm:admin | md5sum | cut -d- -f1) ``` -------------------------------- ### Multiple Devices and Sessions Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Configure multiple V4L2 devices to create separate RTSP sessions. Audio devices can be specified per video device. ```bash # Two video devices → two sessions v4l2rtspserver /dev/video0 /dev/video1 # rtsp://:8554/video0_unicast # rtsp://:8554/video1_unicast ``` ```bash # Two video devices, each with its own ALSA audio v4l2rtspserver /dev/video0,hw:1 /dev/video1,hw:2 # rtsp://:8554/video0_unicast (video0 + hw:1 audio) # rtsp://:8554/video1_unicast (video1 + hw:2 audio) ``` -------------------------------- ### Build v4l2rtspserver Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Build the v4l2rtspserver application using CMake and Make. This process may download and compile Live555 if not found. ```bash cmake . make ``` -------------------------------- ### Expose V4L2 devices with Docker Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Run the v4l2rtspserver Docker container and expose a specific V4L2 device from the host system to the container. ```bash docker run --device=/dev/video0 -p 8554:8554 -it mpromonet/v4l2rtspserver ``` -------------------------------- ### Package v4l2rtspserver Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Create a package for the v4l2rtspserver application. This is an optional step. ```bash cpack . ``` -------------------------------- ### Fetch and Display Server Version Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/index.html Fetches the server version from the '/version' endpoint and updates the footer with the server name and version. Ensure the footer element with id 'footer' exists. ```javascript fetch('version') .then(response => response.text()) .then(version => { document.getElementById("footer").innerHTML = "

v4l2rtspserver" + " " + version + "

"; }); ``` -------------------------------- ### Run v4l2rtspserver in Docker with parameters Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Run the v4l2rtspserver Docker container, exposing a V4L2 device and specifying parameters for authentication, resolution, and frame rate. ```bash docker run --device=/dev/video0 -p 8554:8554 -it mpromonet/v4l2rtspserver -u "" -H640 -W480 ``` -------------------------------- ### Load and Display Streams Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/index.html Fetches the list of available streams from '/streamlist'. For each stream, it creates a heading and conditionally displays a snapshot (for JPEG) or a video player (for H.264/MP2T). Requires Hls.js library for HLS playback. ```javascript fetch('streamlist') .then(response => response.json()) .then(streamList => { const content = document.getElementById("content") streamList.forEach(stream => { const [name, formats] = Object.entries(stream)[0] const title = document.createElement("h3") title.innerText = name content.appendChild(title) if (formats.some(fmt => fmt.toUpperCase().includes("JPEG"))) { const img = document.createElement("img") img.src = "/snapshot?" + name content.appendChild(img) } else if (formats.some(fmt => fmt.toUpperCase().includes("MP2T"))) { const video = document.createElement("video") content.appendChild(video) const hls = new Hls() hls.loadSource(stream + ".m3u8") hls.attachMedia(video) hls.on(Hls.Events.MANIFEST_PARSED, function () { video.play() }) } }) }); ``` -------------------------------- ### Transcoding via v4l2loopback Pipeline Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Compress raw camera output to H264 using v4l2compress and stream it via v4l2rtspserver through a virtual v4l2loopback device. ```bash # Load loopback virtual device modprobe v4l2loopback video_nr=10 # Compress raw camera output to H264 on virtual device (requires v4l2tools) v4l2compress -fH264 /dev/video0 /dev/video10 & # Stream the compressed virtual device v4l2rtspserver /dev/video10 & # Result: rtsp://:8554/unicast (H264 stream) ``` -------------------------------- ### Frame Queue and Output Mirroring Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Control internal frame queue size with '-Q' to adjust latency. Mirror frames to a file or another V4L2 device using '-O'. ```bash # Reduce queue to 3 frames for lower latency v4l2rtspserver -Q 3 /dev/video0 ``` ```bash # Mirror stream to a file (e.g., for recording) v4l2rtspserver -O /tmp/capture.h264 /dev/video0 ``` ```bash # Mirror to a v4l2loopback virtual device modprobe v4l2loopback video_nr=10 v4l2rtspserver -O /dev/video10 /dev/video0 ``` -------------------------------- ### ALSACapture Usage Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Shows how to use ALSACapture to capture audio from ALSA devices and integrate it with DeviceSourceFactory for streaming. ```APIDOC ## C++ API: ALSACapture `ALSACapture` implements `DeviceInterface` for ALSA audio devices, providing the same interface as V4L2 capture so it plugs into `DeviceSourceFactory`. ```cpp #include "ALSACapture.h" // Capture 44100 Hz stereo, prefer S16_LE then fall back to S16_BE std::list fmtList = {SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S16_BE}; ALSACaptureParameters params("default", fmtList, 44100, 2); ALSACapture *audio = ALSACapture::createNew(params); if (audio) { std::cout << "Audio format: " << snd_pcm_format_name((snd_pcm_format_t)audio->getAudioFormat()) << " sampleRate=" << audio->getSampleRate() << " channels=" << audio->getChannels() << std::endl; // Create replicator and add to server session StreamReplicator *audioReplicator = DeviceSourceFactory::createStreamReplicator( env, 0 /* raw audio */, audio, 5, V4L2DeviceSource::CAPTURE_INTERNAL_THREAD); server.AddUnicastSession("av", videoReplicator, audioReplicator); } ``` ``` -------------------------------- ### Run v4l2rtspserver using Docker Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Run the v4l2rtspserver application using its official Docker image. This command maps the default RTSP port. ```bash docker run -p 8554:8554 -it mpromonet/v4l2rtspserver ``` -------------------------------- ### Play HLS streams with VLC Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Play HLS streams served by v4l2rtspserver using VLC media player. ```bash vlc http://..../unicast.m3u8 ``` -------------------------------- ### Load bcm2835-v4l2 driver Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Load the bcm2835-v4l2 driver for Raspberry Pi camera support. This command ensures the V4L2 driver is available. ```bash sudo modprobe -v bcm2835-v4l2 ``` -------------------------------- ### RTSP/HTTP Tunneling Configuration Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Configure RTSP tunneling over HTTP to bypass firewalls. Use '-p' to specify the HTTP tunneling port. ```bash # RTSP on 8554, RTSP-over-HTTP on port 8080 v4l2rtspserver -P 8554 -p 8080 /dev/video0 ``` ```bash # Play via RTSP-over-HTTP tunnel with ffplay ffplay "rtsp://192.168.1.10:8554/unicast" # direct ffplay "http://192.168.1.10:8080/unicast" # tunneled ``` -------------------------------- ### TLS Encryption (SRTP/RTSPS) Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Enable SRTP for encrypted media and RTSPS for encrypted signalling using '-x' and '-X' with a PEM certificate. ```bash # Generate a self-signed certificate+key PEM bundle openssl req -x509 -newkey rsa:2048 -keyout server.pem -out server.pem \ -days 365 -nodes -subj "/CN=v4l2rtspserver" ``` ```bash # Enable SRTP only (media encrypted, signalling plain) v4l2rtspserver -x server.pem /dev/video0 ``` ```bash # Enable both SRTP + RTSPS (fully encrypted) v4l2rtspserver -x server.pem -X /dev/video0 # Stream: rtsps://192.168.1.10:8554/unicast ``` ```bash # Play RTSPS with ffplay (skip cert verification for self-signed) ffplay -rtsp_transport tcp "rtsps://192.168.1.10:8554/unicast" ``` -------------------------------- ### Play HLS streams with GStreamer Source: https://github.com/mpromonet/v4l2rtspserver/blob/master/README.md Play HLS streams served by v4l2rtspserver using GStreamer. ```bash gstreamer-launch-1.0 playbin uri=http://.../unicast.m3u8 ``` -------------------------------- ### DeviceSourceFactory Usage Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt Illustrates how to use DeviceSourceFactory to create codec-aware FramedSource and StreamReplicator objects from a V4L2 device. ```APIDOC ## C++ API: DeviceSourceFactory `DeviceSourceFactory` creates codec-aware `FramedSource` and `StreamReplicator` objects from any `DeviceInterface`. It automatically selects the correct live555 source class based on the pixel format. ```cpp #include "DeviceSourceFactory.h" #include "V4l2Capture.h" #include "VideoCaptureAccess.h" // Open a V4L2 device directly V4L2DeviceParameters params("/dev/video0", {V4L2_PIX_FMT_H264}, 640, 480, 25, IOTYPE_MMAP, O_RDWR | O_NONBLOCK); V4l2Capture *capture = V4l2Capture::create(params); // Create a StreamReplicator (H264 → H264_V4L2DeviceSource, HEVC → H265, others → generic) StreamReplicator *replicator = DeviceSourceFactory::createStreamReplicator( env, // UsageEnvironment* capture->getFormat(), // V4L2_PIX_FMT_H264 new VideoCaptureAccess(capture), // DeviceInterface wrapper /*queueSize=*/5, V4L2DeviceSource::CAPTURE_INTERNAL_THREAD, /*outfd=*/-1, /*repeatConfig=*/true ); // replicator can now be passed to AddUnicastSession / AddMulticastSession ``` ``` -------------------------------- ### ALSACapture for Audio Devices Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt ALSACapture implements DeviceInterface for ALSA audio devices, providing compatibility with DeviceSourceFactory. It allows capturing audio with specified formats and sample rates. ```cpp #include "ALSACapture.h" // Capture 44100 Hz stereo, prefer S16_LE then fall back to S16_BE std::list fmtList = {SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S16_BE}; ALSACaptureParameters params("default", fmtList, 44100, 2); ALSACapture *audio = ALSACapture::createNew(params); if (audio) { std::cout << "Audio format: " << snd_pcm_format_name((snd_pcm_format_t)audio->getAudioFormat()) << " sampleRate=" << audio->getSampleRate() << " channels=" << audio->getChannels() << std::endl; // Create replicator and add to server session StreamReplicator *audioReplicator = DeviceSourceFactory::createStreamReplicator( env, 0 /* raw audio */, audio, 5, V4L2DeviceSource::CAPTURE_INTERNAL_THREAD); server.AddUnicastSession("av", videoReplicator, audioReplicator); } ``` -------------------------------- ### Create StreamReplicator using DeviceSourceFactory Source: https://context7.com/mpromonet/v4l2rtspserver/llms.txt DeviceSourceFactory creates codec-aware FramedSource and StreamReplicator objects from DeviceInterface. It automatically selects the correct live555 source class based on the pixel format. ```cpp #include "DeviceSourceFactory.h" #include "V4l2Capture.h" #include "VideoCaptureAccess.h" // Open a V4L2 device directly V4L2DeviceParameters params("/dev/video0", {V4L2_PIX_FMT_H264}, 640, 480, 25, IOTYPE_MMAP, O_RDWR | O_NONBLOCK); V4l2Capture *capture = V4l2Capture::create(params); // Create a StreamReplicator (H264 → H264_V4L2DeviceSource, HEVC → H265, others → generic) StreamReplicator *replicator = DeviceSourceFactory::createStreamReplicator( env, capture->getFormat(), // V4L2_PIX_FMT_H264 new VideoCaptureAccess(capture), // DeviceInterface wrapper /*queueSize=*/5, V4L2DeviceSource::CAPTURE_INTERNAL_THREAD, /*outfd=*/-1, /*repeatConfig=*/true ); // replicator can now be passed to AddUnicastSession / AddMulticastSession ``` -------------------------------- ### Disable Camera LED Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Setup-on-Pi Configuration to disable the camera's activity LED by adding a directive to the Raspberry Pi's boot configuration file. ```config disable_camera_led=1 ``` -------------------------------- ### Receive H264 RTSP Stream Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Home This command is used to receive an H264 stream from an RTSP server. It connects to the specified RTSP location and decodes the stream for display. ```bash gst-launch-0.10 rtspsrc location=rtsp://192.168.0.14:8554/unicast ! decodebin ! ffmpegcolorspace ! autovideosink ``` -------------------------------- ### Receive H264 Multicast RTP Stream Source: https://github.com/mpromonet/v4l2rtspserver/wiki/Home Use this command to receive an H264 stream sent via multicast RTP on a specific port and group. Ensure the correct RTP capabilities are set. ```bash gst-launch-0.10 -v udpsrc port=20000 multicast-group=232.4.5.6 caps="application/x-rtp" ! rtph264depay ! ffdec_h264 ! autovideosink ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.