Live video can be streamed over the internet using FFmpeg by encoding and packaging content into formats compatible with RTMP, HLS, or MPEG-DASH. RTMP is used to push a live feed to a media server, while HLS and DASH are used for delivering adaptive streams to end users. FFmpeg can handle real-time encoding, segment generation, and manifest creation for both HLS and DASH.

RTMP requires minimal setup and is used with servers like Nginx or Wowza. HLS and DASH require segmenting the stream into .ts or .mp4 chunks with corresponding playlists. Each protocol demands precise FFmpeg flags to ensure compatibility and performance.

Prerequisites

  • FFmpeg installed (version 4.0 or later recommended)
  • Valid video/audio input source (file, camera, or screen capture)
  • Server endpoints for RTMP, HLS, or DASH streaming

Streaming via RTMP (Real-Time Messaging Protocol)

RTMP is widely used for live streaming to platforms like YouTube, Twitch, and Facebook Live. FFmpeg allows you to push video streams to an RTMP server.

Stream Video to an RTMP Server

This command encodes the video using H.264 for video and AAC for audio and streams it to an RTMP server. The??-f flv specifies the FLV format commonly used for RTMP streaming.

code
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f flv rtmp://yourserver/live/stream

Live Stream with Low Latency

This command uses the ultrafast preset and zero-latency tuning for low-latency live streaming, which is critical for real-time broadcasting scenarios like gaming or live events.

code
ffmpeg -i input.mp4 -c:v libx264 -preset ultrafast -tune zerolatency -c:a aac -f flv rtmp://yourserver/live/stream
Live  stream

Streaming via HLS (HTTP Live Streaming)

HLS is an adaptive bitrate streaming protocol that breaks the video into small chunks (segments) and serves them via HTTP. It is commonly used for delivering video content on the web.

Create an HLS Stream

This command encodes the video to H.264 and AAC, then generates HLS segments (.ts files) and creates a playlist (playlist.m3u8). The -hls_time 10 option creates 10-second segments, and -hls_list_size 5 limits the playlist to the latest 5 segments.

code
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f hls -hls_time 10 -hls_list_size 5 -hls_segment_filename "segment_%03d.ts" playlist.m3u8

Stream with Multiple Quality Levels

This command generates multiple bitrate streams for adaptive bitrate streaming. Three different bitrates are specified for quality levels: 3000k, 1500k, and 800k. The master playlist references all quality levels.

code
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f hls -hls_time 10 -hls_list_size 10 -hls_segment_filename "segment_%03d.ts" \
-b:v:0 3000k -b:v:1 1500k -b:v:2 800k \
-master_pl_name master.m3u8 playlist.m3u8

Streaming via DASH (Dynamic Adaptive Streaming over HTTP)

DASH is another adaptive bitrate streaming protocol, similar to HLS, but with support for MP4 containers and more flexible adaptive streaming.

Create a DASH Stream

This command encodes the video to H.264 and AAC, splits it into 10-second segments, and creates a DASH manifest that references the segments.

code
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f hls -hls_time 10 -hls_list_size 5 -hls_segment_filename "segment_%03d.ts" playlist.m3u8

Multi-Bitrate DASH Streaming

This command sets up multi-bitrate DASH streaming, where three different bitrate streams (3000k, 1500k, 800k) are created for adaptive streaming. The -adaptation_sets option links video and audio streams.

code
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f dash -segment_time 10 -dash_segment_filename "segment_$Number$.m4s" \
-b:v:0 3000k -b:v:1 1500k -b:v:2 800k \
-adaptation_sets "id=0,streams=v id=1,streams=a" manifest.mpd

What"s Next?

Need a smooth live streaming experience? Use Cincopa to easily handle RTMP, HLS, and DASH streaming. Automate video encoding, segmenting, and adaptive bitrate streaming with Cincopa"s simple API. Manage your video content efficiently and ensure high-quality playback on any device. Get started with Cincopa to improve your live streaming setup today!