Ffmpeg Rist Zmq
Context: $ARGUMENTS
Quick start
- Send RIST contribution (caller): → Step 3,
advproto.py rist-send - Receive RIST as a listener: → Step 3,
advproto.py rist-listen - Control a running filter graph via ZMQ: → Step 3,
advproto.py zmq-serve+zmq-send - Protect RTP with prompeg FEC: → Step 3,
advproto.py rtp-fec - Push to an icecast radio: → Step 3,
advproto.py icecast - UDP multicast MPEG-TS: → Step 3,
advproto.py multicast - Check build support (librist / libzmq / libshout):
advproto.py check
When to use
- Studio-to-studio or camera-to-cloud contribution that needs ARQ retransmission, bonded paths, and sub-second latency (RIST).
- You want to re-tune a
drawtext,volume,crop, or any filter while ffmpeg is live without re-launching — ZMQ filter control. - Legacy MPEG-TS over RTP links where packet loss is normal — add prompeg Reed-Solomon FEC.
- Streaming MP3/Opus/Vorbis to an Icecast/Shoutcast radio source.
- One-to-many LAN distribution via IP multicast.
If you just need HLS, DASH, RTMP, SRT, or RTSP — use ffmpeg-streaming. If you need WebRTC (WHIP) — use ffmpeg-whip.
Step 1 — Pick the protocol
| Need | Protocol | URL scheme |
|---|---|---|
| Reliable contribution over lossy WAN, ARQ | RIST | rist://host:port |
| Multi-path bonded contribution | RIST main-profile | rist://host:port?peers=... |
| Re-tune filter params at runtime | ZMQ filter | filter zmq=bind_address=tcp://*:5555 |
| Raw video/audio with FEC over RTP | prompeg + rtp_mpegts | rtp://host:port + -fec prompeg=l=5:d=5 |
| Radio source to Icecast2 | icecast | icecast://user:pass@host:port/mount |
| LAN one-to-many | UDP multicast | udp://239.0.0.1:1234?pkt_size=1316 |
RIST has two profiles:
- Simple profile (0) — GRE over UDP, basic ARQ, no auth/encryption. Works with any Simple receiver.
- Main profile (1) — tunnels over GRE with DTLS encryption, CNAME identification, auth. Use for Internet-exposed links.
Verify ffmpeg has the right libs:
ffmpeg -hide_banner -buildconf | grep -E "librist|libzmq|libshout"
If a lib is missing, recompile or use a build that enables it (--enable-librist, --enable-libzmq, --enable-libshout). Or run advproto.py check.
Step 2 — Configure caller vs listener
RIST and UDP both support caller (initiates) and listener (waits) roles.
RIST caller (sender) — most common, sends to a known receiver:
ffmpeg -re -i in.mp4 -c:v libx264 -tune zerolatency -b:v 5M \
-c:a aac -b:a 128k -f mpegts \
"rist://receiver.ip:1234?buffer_size=1000&cname=studio-a"
RIST listener (receiver bind) — pass @ to bind, no host:
ffplay "rist://@:1234?buffer_size=500"
or capture to file:
ffmpeg -i "rist://@:1234?buffer_size=500" -c copy out.ts
RIST main-profile with auth/encryption:
"rist://host:1234?profile=main&secret=hunter2&encryption_type=1&cname=session1"
encryption_type=1 = AES-128, =2 = AES-256 (librist-dependent).
RIST multi-path (bonded) — add secondary peers:
"rist://receiver1.ip:1234?peers=1000@receiver2.ip:2345"
Both paths carry the same stream; losses on one path are recovered from the other.
ZMQ — always listener on the ffmpeg side (server waits for control). Pick a bind_address:
tcp://*:5555= bind all interfaces (fine on localhost, firewall it otherwise).tcp://127.0.0.1:5555= localhost only (safest).tcp://10.0.0.5:5555= specific NIC.
Icecast is always caller. URL carries source user + password:
icecast://source:password@icecast.example.com:8000/stream
UDP multicast — sender sets group address; all receivers join the group:
"udp://239.0.0.1:1234?pkt_size=1316"
Step 3 — Encode + send
RIST contribution (H.264 + AAC, 5 Mb/s)
ffmpeg -re -i in.mp4 \
-c:v libx264 -preset veryfast -tune zerolatency -b:v 5M -maxrate 5M -bufsize 5M \
-x264-params "nal-hrd=cbr:force-cfr=1" -g 60 -keyint_min 60 \
-c:a aac -b:a 128k -ar 48000 \
-f mpegts "rist://receiver.ip:1234?buffer_size=1000&cname=session1"
Use -tune zerolatency + CBR for stable bitrate over the RIST pipe.
RIST listener → file
ffmpeg -i "rist://@:1234?buffer_size=500" -c copy archive.ts
ZMQ runtime filter control (server side)
Attach zmq to whichever filter you want to retune. The zmq filter itself doesn't touch pixels — it just opens a control port:
ffmpeg -re -i in.mp4 \
-filter_complex "[0:v]drawtext=text='hello':x=10:y=10:fontcolor=white,zmq=bind_address=tcp\\\\://*\\\\:5555[out]" \
-map "[out]" -map 0:a -c:v libx264 -c:a aac out.mp4
Note the escaped colon/slash inside -filter_complex. If you prefer, put zmq at the end of the chain without its own label.
ZMQ runtime filter control (client side)
Send commands with python -m zmq or the tools/zmqshell.py that ships with the ffmpeg source tree. Command format is whitespace-separated: <filter_instance> <param> <value>:
python3 -c "import zmq, sys; s=zmq.Context().socket(zmq.REQ); s.connect('tcp://localhost:5555'); s.send_string('Parsed_drawtext_0 text world'); print(s.recv())"
Or use advproto.py zmq-send --addr tcp://localhost:5555 --command "Parsed_drawtext_0 text world".
Find the instance name by reading ffmpeg's stderr — the first drawtext in a graph is Parsed_drawtext_0, the second is Parsed_drawtext_1, etc.
prompeg FEC on RTP-MPEGTS
ffmpeg -re -i in.mp4 -c:v libx264 -c:a aac \
-f rtp_mpegts -fec prompeg=l=5:d=5 "rtp://dst.ip:5000"
l = FEC columns, d = FEC rows. Group = L×D packets + (L + D) parity. Higher L/D → more recoverable loss, more overhead. Typical: l=5:d=5 (~40% overhead), l=8:d=4 (broadcast default).
Icecast audio push
ffmpeg -re -i music.mp3 -c:a libmp3lame -b:a 128k \
-content_type audio/mpeg \
-ice_name "My Radio" -ice_description "24/7 lofi" \
-ice_genre "Electronic" -ice_public 1 \
-f mp3 "icecast://source:hunter2@icecast.example.com:8000/stream"
For Ogg Vorbis: -c:a libvorbis -content_type audio/ogg -f ogg.
UDP multicast MPEG-TS
Sender:
ffmpeg -re -i in.mp4 -c copy -f mpegts "udp://239.0.0.1:1234?pkt_size=1316&ttl=2"
Receiver:
ffplay "udp://@239.0.0.1:1234?fifo_size=1000000&overrun_nonfatal=1"
Multi-output RTP (separate video + audio) with SDP
RTP carries one elementary stream per port, so you must emit an SDP:
ffmpeg -re -i in.mp4 \
-map 0:v -c:v libx264 -an -f rtp "rtp://dst.ip:5004" \
-map 0:a -c:a aac -vn -f rtp "rtp://dst.ip:5006" \
-sdp_file stream.sdp
Then on the receiver: ffplay -protocol_whitelist file,udp,rtp stream.sdp.
Step 4 — Verify + debug
- Build check:
ffmpeg -buildconf | grep -E "librist|libzmq|libshout"oradvproto.py check. - Protocol list:
ffmpeg -protocols | grep -E "rist|zmq|icecast|rtp". - RIST stats: add
-stats_period 1and watchfps=/bitrate=/drop=in ffmpeg's stderr. A healthy RIST link has zero dropped packets after warmup. - ZMQ control round-trip: the server replies
0 Successon good commands, non-zero with an error string on bad ones. If you seeBad Message, check whitespace separation (not=). - prompeg RTT sanity: prompeg is purely transmit-side FEC; there's no ACK. Confirm the receiver reports fewer continuity errors with it than without.
- Icecast verify: open
http://icecast.example.com:8000/status.xsl— your mount should appear with current listeners. - Multicast reachability:
ffplay udp://@239.0.0.1:1234on the same LAN. If nothing — router/switch IGMP snooping is blocking.
Available scripts
scripts/advproto.py— subcommands:check,rist-send,rist-listen,zmq-serve,zmq-send,rtp-fec,icecast,multicast.--dry-runprints the exact ffmpeg command without running. Stdlib only.
Workflow
# Check ffmpeg was built with the needed libraries:
uv run ${CLAUDE_SKILL_DIR}/scripts/advproto.py check
# RIST send:
uv run ${CLAUDE_SKILL_DIR}/scripts/advproto.py rist-send \
--input in.mp4 --url "rist://receiver.ip:1234?buffer_size=1000&cname=s1" \
--bitrate 5M
# ZMQ serve (run in background) + send command:
uv run ${CLAUDE_SKILL_DIR}/scripts/advproto.py zmq-serve \
--input in.mp4 --output out.mp4 \
--filter-expr "drawtext=text='hello':x=10:y=10:fontcolor=white" \
--bind-addr "tcp://*:5555" &
uv run ${CLAUDE_SKILL_DIR}/scripts/advproto.py zmq-send \
--addr tcp://localhost:5555 --command "Parsed_drawtext_0 text world"