Stream Desktop Audio with FFmpeg and JACK
This article provides a step-by-step guide on how to capture and stream your desktop audio using FFmpeg and the JACK Audio Connection Kit. You will learn how to verify your FFmpeg installation, launch the JACK server, construct the correct FFmpeg command to capture the audio feed, and route your system’s sound outputs into the stream.
Prerequisites
Before starting, ensure you have the following installed on your
system: * JACK Audio Connection Kit (JACK1 or JACK2) *
FFmpeg compiled with JACK support (enable this by
checking for libjack support)
To verify that your version of FFmpeg supports JACK, run the following command in your terminal:
ffmpeg -devicesLook for jack in the list of demuxers under the
“Devices” section.
Step 1: Start the JACK Server
You must have an active JACK server running before launching FFmpeg. You can start the server using a GUI control tool like QjackCtl, or via the command line:
jackd -d alsa(Note: Adjust the driver from alsa to
dummy or coreaudio depending on your operating
system and hardware).
Step 2: Run the FFmpeg Capture Command
To capture audio from the JACK server, you tell FFmpeg to use the
jack input device format.
Run the following command to capture the incoming audio and stream it to an RTMP destination (or save it to a local file):
ffmpeg -f jack -i ffmpeg_stream -c:a aac -b:a 192k -f flv rtmp://your-streaming-server/live/streamCommand Breakdown:
-f jack: Specifies the input format as the JACK Audio Connection Kit.-i ffmpeg_stream: Sets the name of the JACK client that FFmpeg will create. FFmpeg will register input ports namedffmpeg_stream:input_1andffmpeg_stream:input_2.-c:a aac: Encodes the audio using the AAC codec.-b:a 192k: Sets the audio bitrate to 192 kbps.-f flv rtmp://...: Directs the output to your RTMP streaming server (replace with a local file path likeoutput.mp3if you want to record locally instead).
Step 3: Route Desktop Audio to FFmpeg
Once FFmpeg is running, it will idle until it receives an audio signal. By default, JACK does not automatically connect your audio sources to new clients. You must route your desktop or application audio into the FFmpeg client ports.
Option A: Using the Command Line
Use the jack_connect utility to link your system’s
playback ports (the desktop audio output) to the FFmpeg input ports:
jack_connect system:playback_1 ffmpeg_stream:input_1
jack_connect system:playback_2 ffmpeg_stream:input_2Option B: Using QjackCtl (GUI)
- Open the QjackCtl interface.
- Click on the Graph or Connect button.
- Locate your desktop audio source (often labeled
systemor your specific media player/browser client) on the left side (readable ports). - Locate
ffmpeg_streamon the right side (writable ports). - Click and drag lines to connect the left channels to
input_1and the right channels toinput_2.
Once connected, any audio playing on your desktop will be routed through JACK, captured by FFmpeg, and streamed to your destination.