Skip to content

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.

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.).

Use ffprobe to analyze your primary stream:

Terminal window
ffprobe -hide_banner -v error -show_streams -show_format udp://239.255.1.1:1234

Look for these important parameters in the output:

  • codec_name — video codec: h264, hevc, or mpeg2video
  • width and height — video resolution, for example 1920 and 1080
  • r_frame_rate — frame rate, for example 25/1 means 25 fps
  • pix_fmt — pixel format, typically yuv420p
  • profile — codec profile, for example high for H.264
  • level — codec level, for example 40 means level 4.0

For a smooth switch between primary and backup sources, your backup video must match:

  • Video codec
  • Frame rate
  • Resolution
  • Pixel format

Use ffmpeg to convert a static image into a loopable video file. Set the parameters based on your primary stream analysis:

Terminal window
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.ts

Options explained:

  • -loop 1 — loop the input image
  • -i image.png — input image file (PNG, JPEG, or other format)
  • -c:v libx264 — video codec (use libx265 for HEVC, mpeg2video for MPEG-2)
  • -profile:v high — codec profile (match profile from ffprobe)
  • -level 40 — codec level (match level from ffprobe)
  • -s 1920x1080 — resolution (match width and height from ffprobe)
  • -r 25 — frame rate (match r_frame_rate from ffprobe)
  • -pix_fmt yuv420p — pixel format (match pix_fmt from ffprobe)
  • -t 10 — duration in seconds
  • /opt/ts/backup-h264.ts — output file in MPEG-TS format

For HEVC streams, change the encoder:

Terminal window
ffmpeg -loop 1 -i image.png -c:v libx265 -s 1920x1080 -r 25 -pix_fmt yuv420p -t 10 /opt/ts/backup-hevc.ts

For MPEG-2 streams:

Terminal window
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.ts

Run FFmpeg to loop the video file and output it as a UDP stream:

Terminal window
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 format
  • pkt_size=1316 — UDP packet size for MPEG-TS

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 Image
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/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=always
RestartSec=5
StandardOutput=null
StandardError=journal
[Install]
WantedBy=multi-user.target

Replace in this file:

  • File Name: use a relevant name instead of backup-h264.service if you have multiple backup streams
  • Description: change to match your use case
  • Input File: replace /opt/ts/backup-h264.ts with the actual path to your video file
  • UDP Port: change 15001 to 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:

Terminal window
systemctl enable backup-h264
systemctl start backup-h264

In the channel settings, add a second input source with the UDP address:

udp://127.0.0.1:15001

Astra will automatically switch to this backup stream when the primary source fails.