How to Broadcast Live Stream using FFMPEG

Are you looking for a no-frills, lightweight tool for broadcast live stream production and other video tasks? If so, FFMPEG may be the software for you.

A powerful and feature-rich tool, FFMPEG isn’t a live streaming app designed for beginners. To help lower the learning curve, this article works to demystify FFMPEG for those new to the software. We’ll cover how to setup and use FFMPEG on both Linux, Mac, and Windows. Then, we’ll cover how to use FFMPEG to broadcast live stream. Finally, we’ll also specifically review how to use the software with our own video streaming solutions.

Now, let’s dive right into a basic description of FFMPEG and its applications for broadcast live stream production.

What is FFMPEG?

In essence, FFMPEG is a command line utility for converting, recording, splicing, editing, playing, encoding, muxing, demuxing, and streaming multimedia files. It can work with audio, images, and video in basically any codec or format used in the past 20 years.

broadcast live streamFFMPEG is also free and open-source. Anyone can download the software without any cost. Developers may also be able to integrate FFMPEG into other projects.

“Command line” utility 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?

With FFMPEG, users can do the following:

  • Convert between different file formats and codecs
  • 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

How to Broadcast Live Stream using FFMPEG

To be honest, 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.

Note: FFMPEG is NOT an encoder for beginners looking to broadcast live stream. Beginning users would be better off starting with a free encoder such as OBS Studio. Beginning broadcasters can also consider paid encoding software options, such as Wirecast, vMix, and VidBlasterX.

FFMPEG tools to broadcast live stream

For live video stream applications, FFMPEG provides a variety of options. In particular, FFMPEG can access any video and audio streams that are accessible to your computer. These include webcams, USB microphones, and cameras that connect via capture cards.

broadcast live streamYou can use all of these as inputs for FFMPEG. Then, 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. FFMPEG acts as the live stream encoding software.

One salient application of FFMPEG concerns mixing a complex live production. For live production mixing, 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 stream 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.

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 do recommend that you compile FFMPEG yourself.

Why? This approach allows you to stream RTMP video 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
broadcast live stream

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
$ make

Next, install the library in your system’s root directory.

# DESTDIR=/usr make install

Then, we need to install and manually compile libaacplus. We also need to install other dependencies. At this point, we’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
$ make
$ 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, we’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
$ make

Finally, use this code to install ffmpeg in your system’s root directory:

# make install

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:

xcode-select --install
/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:

broadcast live stream1. First, install librtmp with brew:

brew install librtmp

2. Then, install libx264 with brew:

brew install libx264

3. 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

Windows installation

Windows users can install FFMPEG using pre-built packages at the following link: https://ffmpeg.zeranoe.com/builds/.

How to broadcast live stream to DaCast using FFMPEG

Once you’ve set up FFMPEG, you’re ready to broadcast live stream over DaCast!

Here’s how to connect your FFMPEG installation to your DaCast account:

Step 1
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, then click on “Encoder setup.” Select “Other RTMP encoder” on the left side of the screen.

Step 2
On the right side of the screen, copy these pieces of information: Login, Password, Stream URL, and Stream Names.

Step 3
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 1920x1080 -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"

broadcast live streamWhen 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
  • 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 is that, during the installation process, you need to enter “–enable-fdkaac” 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 buffer size for smoother platyback, replace “-b 900k” with “-buffsize 3000k”.

Finally, 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 key frame interval at 2s.

Interested to learn more?

Here are some further readings for using FFMPEG with DaCast on Linux and Mac.

Conclusion

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.

And if you’re searching for a streaming platform to support your broadcast live stream projects, 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!

YES, SIGN ME UP

Thanks for reading, and good luck with your live broadcasts!

By Max Wilbert.

Leave a Reply

Your email address will not be published. Required fields are marked *