MpegFlowBlogBack to home
← Recipes·RTMP push streaming·tooling

Push live RTMP stream with FFmpeg to YouTube, Twitch, or custom origins

Stream live video to RTMP destinations — YouTube Live, Twitch, custom origins. Encoder settings, reconnection patterns, and tuning that prevents buffer underruns.

ByMpegFlow Engineering Team·FFmpeg recipe
·3 variants·May 9, 2026

When to use this

You push RTMP for live streaming to platform-managed destinations (YouTube Live, Twitch, Facebook Live, LinkedIn Live), custom RTMP origins (Wowza, your own nginx-rtmp), or distribution to multi-platform fanout services (Restream, StreamYard). RTMP is the legacy live ingest protocol — TCP-based, broad compatibility, but lossy on packet drops. The encoder configuration matters: settings tuned for VOD produce visible artifacts and buffer underruns when streamed live.

Command variants

Push file to RTMP destination
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -tune zerolatency -b:v 3500k -maxrate 3500k -bufsize 7000k \
  -c:a aac -b:a 128k \
  -f flv \
  rtmp://a.rtmp.youtube.com/live2/STREAM-KEY

-re reads input at native framerate (otherwise FFmpeg pushes as fast as it can decode, breaking RTMP timing). YouTube Live ingest URL pattern shown.

Push live capture (camera/screen)
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0:0" \
  -c:v libx264 -preset veryfast -tune zerolatency -b:v 3500k -maxrate 3500k -bufsize 7000k -g 60 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv \
  rtmp://live.twitch.tv/app/STREAM-KEY

macOS avfoundation capture. Linux equivalent is -f v4l2 -i /dev/video0 + -f alsa -i default. -g 60 = keyframe every 2s for HLS playback.

Multi-destination fanout via tee
ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -tune zerolatency -b:v 3500k -maxrate 3500k -bufsize 7000k \
  -c:a aac -b:a 128k \
  -f tee "[f=flv]rtmp://youtube/live2/KEY1|[f=flv]rtmp://twitch/app/KEY2"

Single encode, two RTMP destinations. tee muxer fans out — useful but less flexible than per-destination retry.

What each parameter does

  • -re

    Read input at native framerate. Required for streaming file content; without it, FFmpeg sends as fast as decode allows, breaking RTMP delivery timing.

  • -tune zerolatency

    Disables b-frames and lookahead. Required for live: without it, FFmpeg buffers ~20+ frames before emitting, adding 700ms of encoder latency.

  • -b:v / -maxrate / -bufsize

    Constant-bitrate-like encoding. Live streams need predictable bitrate; CRF mode produces variable bitrate that breaks RTMP delivery. Set bufsize = 2× maxrate.

  • -g 60

    Keyframe every 60 frames (2s at 30fps). Aligns with HLS segment boundaries on the destination side.

  • -f flv

    FLV container format. RTMP's native container — required for RTMP destinations.

What this outputs

A live RTMP stream pushed to the destination. Quality depends on encoder settings and network bandwidth. Typical bitrates: 720p30 = 2-3.5 Mbps, 1080p30 = 3-6 Mbps, 1080p60 = 5-9 Mbps.

Pitfalls

  1. Forgetting -re when streaming file content: FFmpeg pushes faster than real-time, breaking RTMP delivery timing. The destination receives bursts and players buffer/stall.
  2. Forgetting -tune zerolatency: encoder buffers 20+ frames adding 700ms of latency. Visible to viewers, especially on platforms with chat interaction.
  3. CRF mode breaks RTMP: variable bitrate confuses delivery. Always use -b:v + -maxrate + -bufsize for live streams.
  4. GOP not aligned with destination expectations: YouTube/Twitch expect 2-second keyframe intervals (-g 60 at 30fps). Wrong values produce visible artifacts on rendition switches.
  5. No reconnection logic: if RTMP connection drops, FFmpeg exits. For production reliability, wrap FFmpeg in a process manager (systemd, supervisord, K8s pod with restartPolicy) that respawns on exit.
  6. RTMP destination requires specific SSL handling: rtmps:// for encrypted (most modern platforms), rtmp:// for plaintext. Wrong scheme = connection refused.

At production scale

RTMP streaming is encoder-bound and constant-throughput. A single live stream consumes one encoder unit (one CPU core for libx264 veryfast at 720p, less for NVENC). Scaling to N streams = N encoder pools. For production live operations, run FFmpeg in containers managed by K8s with HPA on pod count; each pod handles one stream. The live ingest + low-latency packaging architecture covers the production-grade alternative.

How MpegFlow handles this

MpegFlow models RTMP push as a dedicated DAG stage — different streams can have different destinations, retry logic, and encoder settings. The audit log records bytes-per-second pushed, connection status, and reconnection events.

Topics
  • FFmpeg
  • rtmp
  • live
  • streaming
  • tooling
See also
  • Architecture
    Live Ingest Low Latency Packaging
  • Recipe
    Multi Output Encoding
Running this at scale?

Get the orchestration layer for free.

The rtmp push streaming command above is the easy part. The queue, retries, audit trail, encoder-version pinning, and multi-tenant security around it are what every video team rebuilds from scratch. We did the rebuild — design partners run it free during beta.

Apply More recipes
© 2026 MpegFlow, Inc. · Trust & complianceAll systems nominal·StatusPrivacy