FFmpeg RTMP Streaming: Publish, Reconnect & Verify | Callaba
FFmpeg can publish a file, device or live input to an RTMP server, but a command that stays running is only half the workflow. The input must be paced correctly, selected tracks must fit the RTMP/FLV destination contract, the publish URL and stream identity must be protected, and the receiving server must prove bitrate and decode. Decide between stream copy and transcoding from evidence, not habit.
An RTMP publish crosses source, encode, session and receiver gates
Callaba already provides the RTMP receiving side
Callaba RTMP Server creates a stable ingest listener with a port, player buffer, active state and optional stream-key or IP access rules. Its operator workflow exposes current and recent publisher or receiver activity, bitrate, region and peer IP. The feed can then enter Restream, Recording or Web Player. This is an existing managed RTMP ingest path; Callaba does not expose an arbitrary FFmpeg shell or guarantee every external FFmpeg build.
| Publishing job | Existing Callaba path | Proof |
|---|---|---|
| Create a receiver | Configure RTMP Server listener and the narrow required access rule | The intended publisher appears on the expected port and stream identity |
| Inspect contribution | Read live statistics and short-lived history, exporting data when longer retention is needed | Bitrate, connection state, peer and decoded downstream tracks match the event |
| Use the feed | Connect the server to Restream, Recording or Web Player | Each consumer proves its own output; ingest health is not viewer readiness |
The adjacent improvement is a copyable, redacted publisher test generated from a server's exact endpoint and access policy, followed by one correlated first-packet timeline. The managed RTMP receiver and telemetry are already real product capabilities.
Confirm the local build and RTMP protocol support
Run ffmpeg -version, ffmpeg -protocols and the relevant muxer help on the publishing host. The official FFmpeg protocol documentation describes native RTMP, RTMPS and related variants. Package builds and external libraries can change available behavior.
Freeze the version with the service definition. A successful laptop test is not evidence for a minimal container that lacks the same encoder, TLS trust store or protocol build options.
Publish a compatible file at real-time pace
ffmpeg -re -i input.mp4 \
-map 0:v:0 -map 0:a? -c copy \
-f flv "$RTMP_OUTPUT"
-re paces a file input near its native rate so it behaves like a live contribution instead of sending as fast as possible. Do not use it blindly for an already live source. The copy path is valid only when the destination and FLV muxer accept the input codecs and timing.
Keep the full output URL and stream secret outside shared command text. A runbook can show a redacted host, application and safe source alias while the service injects the actual value through its protected configuration.
Transcode when the server contract requires new media
ffmpeg -i "$LIVE_INPUT" \
-map 0:v:0 -map 0:a? \
-c:v libx264 -preset veryfast -pix_fmt yuv420p -g 60 \
-c:a aac -f flv "$RTMP_OUTPUT"
This is a shape, not a universal production preset. Frame rate determines whether -g 60 represents the intended keyframe interval; bitrate, profile, resolution and audio settings must come from the receiving contract. Measure quality and encode speed on representative content.
If the source already supplies acceptable H.264 and AAC, stream copy may be preferable. If only audio is incompatible, copy video and transcode audio. State the choice per track so a later operator can explain resource use and quality changes.
RTMPS protects the publish hop when correctly validated
FFmpeg documents RTMPS as RTMP over a secure SSL/TLS connection. Confirm that the receiving endpoint supports it, validate hostname and certificate trust, and maintain certificate expiry monitoring. Do not weaken verification to make a test pass.
RTMPS protects the connection between this publisher and server. A downstream restream, recording or viewer has its own transport and access policy. Never turn one protected ingest hop into an unsupported end-to-end encryption claim.
Reconnect policy must avoid duplicates and restart storms
FFmpeg protocol options and source demuxers expose different timeout and reconnect controls. Select only options supported by the exact build and input. Wrap the process with bounded backoff, an attempt ceiling and clear exit evidence. Authentication denial should not trigger an aggressive loop.
Decide what happens if the old connection remains half-open when a replacement publisher starts. The RTMP server's stream-key policy should reject or deterministically replace duplicates according to the event runbook, and operators should see which peer is active.
Example: a file publish ends before operators can validate it
A test file is sent without real-time pacing, so FFmpeg pushes it rapidly and disconnects while the server records only a brief bitrate spike. The first comparison is input duration, wall-clock process time and server connection history. If ten minutes of content were delivered in seconds, the root cause is the file-source pacing boundary—not unstable RTMP networking. Repeat with deliberate pacing and a known observation window.
Read server telemetry before declaring success
The FFmpeg progress line reports local frame, speed and muxing behavior. It cannot prove the server accepted the intended stream identity or that a downstream consumer decodes it. Use RTMP Server statistics to verify the active connection and current bitrate, then inspect the selected consumer.
Short-lived history is useful for immediate diagnosis but is not a durable monitoring archive. Export safe measurements when incident retention requires it, avoiding publication secrets and unnecessary peer data.
Commission publisher and receiver together
- Freeze the endpoint contract. Record RTMP or RTMPS, port, application, stream identity and access owner without copying secrets.
- Probe the input. Verify tracks, codecs, timestamps and whether the source already runs in real time.
- Choose copy or transcode. Validate FLV and server compatibility per track.
- Publish a bounded test. Compare FFmpeg progress with Callaba connection and bitrate evidence.
- Exercise failures. Use a denied key, receiver restart, network interruption and duplicate publisher under controlled conditions.
- Verify the consumer. Connect the feed through Restream, Recording or Web Player and test that separate output.
FFmpeg RTMP FAQ
Why use -re for a file input?
It paces file reading near the input rate for a live-style test. It is not normally added to an input that already arrives in real time.
Can FFmpeg copy tracks into RTMP without encoding?
Yes when the input codecs and timing are compatible with the FLV/RTMP destination. Probe the source and verify the receiver before relying on stream copy.
Does RTMPS secure viewers too?
No. It protects the publisher-to-server hop when correctly validated. Recording, restream and viewer delivery each have separate transport and access boundaries.
How do I know the RTMP publish is accepted?
Compare FFmpeg progress with server-side publisher identity, connection and bitrate telemetry, then prove the downstream output that will actually be used.