FFmpeg

How-to Broadcast using FFmpeg with RTMP

FFmpeg is a free open-source software project with command-line tools for handling video, audio, and other multimedia. Depending on your workflow, you may want to broadcast over WebRTC from a file on disk or another Real-time Streaming Protocol (RTSP). FFmpeg enables you to originate the broadcast from a ffmpeg command that forwards the stream over RTMP to the Dolby.io real-time streaming servers for global low-delay distribution.

See the official ffmpeg.org documentation for installation instructions and additional support.

Get your Dolby.io RTMP publish URL

πŸ‘

Getting Started

If you haven't already, begin by following the Getting Started tutorial to create a Dolby.io application and start your first broadcast.

In order to broadcast with RTMP, you will need to have your RTMP publish path and RTMP publish stream name available.

See the RTMP Broadcast Guide for details on how to retrieve these values. They will be referenced as environment variables $RTMP_PUBLISH_PATH and $RTMP_PUBLISH_STREAM_NAME in the examples below.

FFmpeg examples

How-to publish an H.264 RTMP video stream

You will need to substitute the $VIDEO_FILE_PATH, $RTMP_PUBLISH_STREAM_NAME, and $RTMP_PUBLISH_PATH that is appropriate for the shell environment and operating system you are using.

ffmpeg -re -stream_loop -1 -i $VIDEO_FILE_PATH \
  -vcodec libx264 \
  -preset veryfast \
  -bf 0 -g 60 \
  -vb 3000k \
  -vprofile baseline \
  -level 3.0 \
  -acodec aac \
  -ab 96000 -ar 48000 -ac 2 \
  -strict experimental \
  -f flv \
  -rtmp_playpath $RTMP_PUBLISH_STREAM_NAME \
  -rtmp_live live $RTMP_PUBLISH_PATH

A few notes about these recommended settings.

ParameterDescription
-stream_loop -1Loop the video indefinitely
-vcodec libx264H.264 video codec
-vb 3000kVideo Bitrate setting of 3Kbps
-acodec aacAAC audio codec
-ac 2Audio channels for stereo
-ab 96000Audio Bitrate setting of 96Kbps
-ar 48000Audio Sample Rate of 48Kbps
-bf 0Disable bframes
-g 60Group of pictures (GOP) size
-f flvFormat as flash video
-preset veryfastVideo encoding speed to compression ratio preset
-vprofile baseline -level 3.0H.264 profile and level that specifies maximum decoding speed, frame size, and bit rate

You can then watch this stream from a playback viewer.

How-to publish an RTSP video stream

Support for Real-time Streaming Protocol (RTSP) can be done with ffmpeg by changing the input source. All of the other parameters are consistent with streaming a media file from disk.

ffmpeg -re -i rtsp://98.116.xx.xx:5545/axis-media/media.amp \
  -vcodec libx264  \
  -preset veryfast \
  -bf 0 -g 60 \
  -vb 3000k \
  -vprofile baseline \
  -level 3.0 \
  -acodec aac \
  -ab 96000 -ar 48000 -ac 2 \
  -strict experimental \
  -f flv \
  -rtmp_playpath $RTMP_PUBLISH_STREAM_NAME \
  -rtmp_live live $RTMP_PUBLISH_PATH

Troubleshooting

These examples were verified with ffmpeg version 6.0 on MacOS.

> ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)

If you are using a different version or operating system please include these details when reporting any issues.

Stuttering video

If you experience stutter in your streaming video, make sure you are using the options:

-vprofile baseline and -bf 0

You can also modify the -preset to adjust the compression speed to quality ratio.

Learn more

This guide covered broadcasting with ffmpeg. To test and view the stream you can use the dashboard or any of the other playback methods.

Continue exploring other software encoders and solutions you can use for broadcasting your real-time stream.