FFmpeg Live Streaming – What Professional Broadcasters Need to Know
Table of Contents
Many professional broadcasters use live streaming software in addition to their online video platforms. Live streaming software typically provides tools for encoding, transcoding, adding on-screen effects, and more.
If you are looking for a no-frills, lightweight tool for broadcast live stream production and other video tasks, FFmpeg may be the software for you.
This feature-rich tool is primarily designed for advanced broadcasters. To help lower the learning curve, we’ve put together this guide to break down some of the code and functions available on FFmpeg.
We’ll cover how to set up FFmpeg on Linux, Mac, and Windows, and how to use FFmpeg to broadcast live streams. We’ll also provide a brief walkthrough on how to use the software with our own video streaming solution.
Let’s get right into the basics of FFmpeg live streaming and its useful tools.
Table of Contents:
- What is FFmpeg?
- What Can You Do With FFmpeg?
- FFmpeg Live Streaming Tools
- How to Download and Setup FFmpeg
- How to Live Stream Using FFmpeg and Dacast
What is FFmpeg?
In essence, FFmpeg is a program for converting, recording, splicing, editing, playing, encoding, muxing, demuxing, and streaming multimedia files. It works with audio, images, and video in basically any codec or format used in the past 20 years.
FFmpeg is free and open-source, meaning anyone can download the software without any cost. Developers may also be able to integrate FFmpeg into other projects.
This program is a command-line utility, which means that FFmpeg isn’t built around a GUI or a Graphical User Interface. Instead, it’s an application that accepts commands via “command-line interfaces” (CLI).
If you’ve ever used a Unix-based computer such as Linux or macOS, you may have used the “terminal” application. On Windows, MS-DOS and the more modern “Powershell” provide a command-line interface.
Power users, system administrators, developers, and others working with complex code generally prefer a CLI. Often, system administration tools are only available via CLI. Scripting, automation, and other advanced tasks are often easier via CLI. Thus, FFmpeg serves this audience by providing multimedia tools from the command line.
What Can You Do With FFmpeg?
FFmpeg has a wide range of capabilities for live streaming. With FFmpeg, users can do the following:
- Convert between different file formats and codecs (i.e. encoding)
- Adjust bitrate (both audio and video)
- Adjust volume, remove audio and/or merge an audio file with a video file
- Remap a mono audio source to stereo channels
- Crop, scale or rotate a video file
- Recording input from a webcam or other video source
- Broadcast live stream a video feed
When it comes to multimedia, there isn’t much that FFmpeg can’t do.
If you’ve used image editing, video editing or audio editing software, you’ve probably used FFmpeg before. Given its free and open-source nature, many other GUI (Graphical User Interface) applications use FFmpeg to provide backend processing.
It is important to emphasize that FFmpeg is NOT an encoder for beginners looking to broadcast live streams. New broadcasters would be better off starting with a free encoder such as OBS Studio. They could also consider investing in paid encoding software options, such as Wirecast, vMix, and VidBlasterX.
FFmpeg Live Streaming Tools
As far as live video stream software goes, FFmpeg provides a relatively wide variety of tools. FFmpeg supports many video and audio inputs that are accessible to your computer. These include webcams, USB microphones, and cameras that connect via capture cards.
Additionally, you can specify an output as an RTMP stream aimed at your video streaming platform. FFmpeg will accept your login information to allow you to stream to this destination. This provides a simple command-line interface live streaming functionality. In this case, FFmpeg acts as the live encoding software.
One important application of FFmpeg concerns mixing a complex live production. For this function, you may want to have one powerful computer dedicated to capturing feeds from various cameras.
An engineer stationed at this camera then mixes video content in real-time. Then, the engineer can output a feed to another computer running FFmpeg. This computer, in turn, can broadcast live streams as the final result.
This setup effectively divides the processing load between multiple machines.
How to Download and Setup FFmpeg
The easiest way to get started with FFmpeg is to download it from the website directly. The installation will look different depending on what operating system you use.
Here is a brief walkthrough for setting up FFmpeg on Linux, macOS, and Windows.
1. Linux Installation:
The FFmpeg website has Linux packages for Debian, Ubuntu, Fedora, and Red Hat Enterprise Linux. Many other distros should be able to easily install FFmpeg using their location variation of the install command. For example:
sudo apt-get install ffmpeg
However, we recommend compiling FFmpeg yourself because this approach allows you to stream RTMP videos via the librtmp library. To do so, we’ll use Ubuntu as our example distro.
To start, run the following commands:
$ sudo apt-get update
$ sudo apt-get install build-essential git libssl-dev
Then, retrieve the librtmp source code on the official git repository.
$ git clone git://git.ffmpeg.org/rtmpdump
Next, browse to the local repository’s folder. Once there, run the compilation process.
$ cd rtmpdump
$ cd librtmp
Next, install the library in your system’s root directory.
# DESTDIR=/usr make install
Then, you need to install and manually compile libaacplus. You also need to install other dependencies. At this point, you’ll run the following commands:
$ sudo apt-get install libfftw3-dev pkg-config autoconf automake libtool unzip
$ wget https://tipok.org.ua/downloads/media/aacplus/libaacplus/libaacplus-2.0.2.tar.gz
$ tar -xzf libaacplus-2.0.2.tar.gz
$ cd libaacplus-2.0.2
$ ./autogen.sh –enable-shared –enable-static
$ sudo make install
$ sudo ldconfig
# apt-get install yasm libfaac-dev libfdk-aac-dev libfreetype6-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libopenjpeg-dev libopus-dev libschroedinger-dev libspeex-dev libtheora-dev libvo-aacenc-dev libvorbis-dev libvpx-dev libx264-dev libxvidcore-dev
Now, you’ll retrieve the ffmpeg source code from the official git repository:
$ git clone https://github.com/FFmpeg/FFmpeg.git
Browse to the local repository’s folder, then run the compilation process:
$ cd FFmpeg
$ ./configure –enable-gpl –enable-version3 –enable-nonfree –enable-postproc –enable-libaacplus –enable-libfaac –enable-libfdk-aac –enable-libfreetype –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libopenjpeg –enable-openssl –enable-libopus –enable-libschroedinger –enable-libspeex –enable-libtheora –enable-libvo-aacenc –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libxvid –prefix=/usr/local –enable-librtmp
Finally, use this code to install ffmpeg in your system’s root directory:
# make install
2. macOS Installation
As with Linux, we recommend macOS users compile a custom build of FFmpeg. You can do so with the help of the Brew package manager.
You’ll also need to install Command Line tools. To set up these dependencies, use the following commands in the “Terminal” application, then follow any prompts that may appear:
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
Once you’ve setup Command Line tools and Brew, you’re ready to install FFmpeg.
Use the following commands in your terminal:
First, install librtmp with brew:
brew install librtmp
Then, install libx264 with brew:
brew install libx264
Next, install libfdk-aac with brew:
brew install fdk-aac
Finally, install FFmpeg with all the specific libraries:
brew install ffmpeg –enable-libfdk-aac –with-x264 –with-rtmpdump
3. Windows Installation:
Windows users can install FFmpeg using pre-built packages on the “Builds” page of the FFmpeg website.
How to Live Stream Using FFmpeg and Dacast
Once you’ve set up FFmpeg, you’re ready to broadcast a live stream over Dacast. We offer secure video upload and many other features to make streaming live accessible to all kinds of broadcasters.
Let’s take a look at the three steps for using FFmpeg to live stream via Dacast.
First, you need to gather the encoder setup information from your Dacast account.
In a web browser, visit the Dacast website and log in to your account. Click on (or create) the live channel you wish to stream on, then click on “Encoder setup.”
Select “Other RTMP encoder” on the left side of the screen.
On the right side of the screen, copy down these pieces of information: Login, Password, Stream URL, and Stream Names.
Next, copy the following command into a text editor or directly into your CLI:
$ ffmpeg -re -f lavfi -i testsrc -c:v libx264 -b:v 1600k -preset ultrafast -b 900k -c:a libfdk_aac -b:a 128k -s 1920×1080 -x264opts keyint=50 -g 25 -pix_fmt yuv420p -f flv “rtmp://p.ep246802.i.akamaientrypoint.net/EntryPoint flashver=FMLE/3.020(compatible;20FMSc/1.0) live=true pubUser=123456 pubPasswd=789123 playpath=dclive_1_1@246802”
When you execute this command, you will begin an x264 live stream at 480p resolution (downscaled from 1080p HD) at 1600 kbps bitrate, with a 900kb buffer.
You’ll need to replace the “rtmp://…” text with your own Stream URL link, set “pubUser” to your login, “pubPasswd” to your password, and “playpath” to your Stream Name.
Important Notes about FFmpeg Live Streaming
- You should also replace “-f lavfi -i testsrc” with “-i” then the source of your own camera feed or other program feed (-i /your_source_path). Otherwise, you will not have your live stream but only the test screen.
- A recurring typo in fdk aac usage during the installation process, you need to enter “–enable-fdk–aac” but when you use it in the command it is “-c:a libfdk_aac”
- For better quality, you can change the “preset” flag to “fast” rather than “ultrafast.”
- If you want low latency, you can add the flag “-tune zerolatency” directly after the preset flag. Both of these commands require additional processing power.
- To increase the buffer size for smoother playback, replace “-b 900k” with “-buffsize 3000k.”
- Make sure you’re using the best settings for you. These include setting video and audio bitrates according to your internet connection, resolutions consistent with those bitrates, and keyframe interval at 2s.
That’s all there is to it! We know that live streaming with FFMPEG can be confusing, especially for newcomers. However, there’s no denying that this powerful piece of software is highly useful in the right situation and with the right knowledge. We hope that this article has provided you with the tools and the confidence to use FFMPEG to broadcast live stream.
For regular tips on live streaming and exclusive offers, we invite you to join our LinkedIn group.
Are you searching for a live streaming and video hosting platform to support your broadcast live stream projects? If so, why not give Dacast a try? We offer a 30-day free trial (no credit card required), and we’d love to get you set up to test out all our features today!
Thanks for reading, and good luck with your live broadcasts!
By Max Wilbert.
Stay up to date with our latest features and product releases