Creating Backup Stream from Image
A backup video stream from a static image provides a fallback when your primary source fails. The image can display a message like “Technical difficulties, please stand by” or similar service information. This approach is also useful for Emergency Alert Systems (EAS) to broadcast visual warnings.
Create Video File from Image
Section titled “Create Video File from Image”Video encoding is a resource-intensive task. To reduce CPU usage, pre-encode the image into short video files rather than encoding in real-time.
For smooth switching between primary and backup sources, the video codec must match your main stream. Create video files for each codec format you use (H.264, HEVC, etc.).
Check Primary Stream Format
Section titled “Check Primary Stream Format”Use ffprobe to analyze your primary stream:
ffprobe -hide_banner -v error -show_streams -show_format udp://239.255.1.1:1234Look for these important parameters in the output:
- codec_name — video codec:
h264,hevc, ormpeg2video - width and height — video resolution, for example
1920and1080 - r_frame_rate — frame rate, for example
25/1means 25 fps - pix_fmt — pixel format, typically
yuv420p - profile — codec profile, for example
highfor H.264 - level — codec level, for example
40means level 4.0
For a smooth switch between primary and backup sources, your backup video must match:
- Video codec
- Frame rate
- Resolution
- Pixel format
Create Video File
Section titled “Create Video File”Use ffmpeg to convert a static image into a loopable video file. Set the parameters based on your primary stream analysis:
ffmpeg -loop 1 -i image.png -c:v libx264 -profile:v high -level 40 -s 1920x1080 -r 25 -pix_fmt yuv420p -t 10 /opt/ts/backup-h264.tsOptions explained:
-loop 1— loop the input image-i image.png— input image file (PNG, JPEG, or other format)-c:v libx264— video codec (uselibx265for HEVC,mpeg2videofor MPEG-2)-profile:v high— codec profile (matchprofilefrom ffprobe)-level 40— codec level (matchlevelfrom ffprobe)-s 1920x1080— resolution (matchwidthandheightfrom ffprobe)-r 25— frame rate (matchr_frame_ratefrom ffprobe)-pix_fmt yuv420p— pixel format (matchpix_fmtfrom ffprobe)-t 10— duration in seconds/opt/ts/backup-h264.ts— output file in MPEG-TS format
For HEVC streams, change the encoder:
ffmpeg -loop 1 -i image.png -c:v libx265 -s 1920x1080 -r 25 -pix_fmt yuv420p -t 10 /opt/ts/backup-hevc.tsFor MPEG-2 streams:
ffmpeg -loop 1 -i image.png -c:v mpeg2video -b:v 5M -s 1920x1080 -r 25 -pix_fmt yuv420p -t 10 /opt/ts/backup-mpeg2.tsCreate Stream from Video File
Section titled “Create Stream from Video File”Run FFmpeg to loop the video file and output it as a UDP stream:
ffmpeg -stream_loop -1 -re -i /opt/ts/backup-h264.ts -c copy -f mpegts 'udp://127.0.0.1:15001?pkt_size=1316'Options explained:
-stream_loop -1— loop the file infinitely-re— read input at native frame rate-i /opt/ts/backup-h264.ts— input video file-c copy— copy streams without re-encoding-f mpegts— output formatpkt_size=1316— UDP packet size for MPEG-TS
Stream from File with Audio
Section titled “Stream from File with Audio”The command above sends a video-only stream. Add sound when you broadcast the file, not when you create it. For example, a client can make a channel from a still image and a radio stream.
The audio source in this example is udp://127.0.0.1:14001. To receive an internet radio station and send it to UDP, see Receiving Radio Streams.
Use this command instead of the one above:
ffmpeg -stream_loop -1 -re -i /opt/ts/backup-h264.ts -i 'udp://127.0.0.1:14001' -map 0:v:0 -map 1:a:0 -c copy -f mpegts 'udp://127.0.0.1:15001?pkt_size=1316'Options explained:
-i 'udp://127.0.0.1:14001'— audio source, for example a radio stream. Use a different port than the output-map 0:v:0— take video from the image file-map 1:a:0— take the first audio stream from the audio source-c copy— copy video and audio without re-encoding
The other options are the same as in the command above.
The output address stays udp://127.0.0.1:15001, so the Astra setup below does not change.
To keep FFmpeg running, use the service below and add the audio input and -map options to ExecStart.
Running FFmpeg as a Service
Section titled “Running FFmpeg as a Service”To keep FFmpeg running continuously, set it up as a systemd service.
Create file /etc/systemd/system/backup-h264.service with the following content:
[Unit]Description=Backup Video Stream from ImageAfter=network-online.targetWants=network-online.target
[Service]Type=simpleExecStart=/usr/bin/ffmpeg \ -hide_banner -loglevel warning -nostats \ -stream_loop -1 \ -re \ -i /opt/ts/backup-h264.ts \ -c copy \ -f mpegts 'udp://127.0.0.1:15001?pkt_size=1316'
Restart=alwaysRestartSec=5
StandardOutput=nullStandardError=journal
[Install]WantedBy=multi-user.targetReplace in this file:
- File Name: use a relevant name instead of
backup-h264.serviceif you have multiple backup streams - Description: change to match your use case
- Input File: replace
/opt/ts/backup-h264.tswith the actual path to your video file - UDP Port: change
15001to the UDP port you want to use. If you have multiple backup streams, use different ports.
After creating the service file, enable and start the service:
systemctl enable backup-h264systemctl start backup-h264Configure Astra
Section titled “Configure Astra”In the channel settings, add a second input source with the UDP address:
udp://127.0.0.1:15001Astra will automatically switch to this backup stream when the primary source fails.