Redirect Web Browser Audio to FFmpeg

Capturing and routing audio from a web browser into FFmpeg allows you to record, transcode, or stream online audio feeds in real-time. Because web browsers do not natively output audio directly to command-line tools, this process requires setting up a virtual audio loopback device. This article provides a straightforward guide on how to configure virtual audio routing and run the correct FFmpeg commands on Windows, macOS, and Linux.

Step 1: Set Up a Virtual Audio Device

To bridge the browser and FFmpeg, you must route the browser’s audio output into a virtual input device that FFmpeg can read.


Step 2: Identify the Audio Device Name

FFmpeg needs the exact name of your virtual device to capture the stream.

On Windows (DirectShow)

Run the following command to list available input devices:

ffmpeg -list_devices true -f dshow -i dummy

Look for the virtual audio device in the alternative name list (e.g., "Virtual Cable" or "CABLE Output").

On macOS (AVFoundation)

Run this command to list audio devices:

ffmpeg -f avfoundation -list_devices true -i ""

Identify the index number or name associated with “BlackHole”.

On Linux (PulseAudio)

Find the monitor source of your current playback device:

pactl list sources short | grep monitor

Copy the name of the monitor device (e.g., alsa_output.pci-0000_00_1f.3.analog-stereo.monitor).


Step 3: Run the FFmpeg Command

Once the routing is configured and you have the device name, you can launch FFmpeg to capture and process the browser stream.

Windows Command

Using the dshow format, replace "CABLE Output" with the exact name of your virtual device:

ffmpeg -f dshow -i audio="CABLE Output" output.mp3

macOS Command

Using the avfoundation format, replace 1 with the device index of BlackHole:

ffmpeg -f avfoundation -i ":1" output.mp3

Linux Command

Using the pulse format, target the monitor source you identified in Step 2:

ffmpeg -f pulse -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor output.mp3

Step 4: Stream and Process

Now, simply open your web browser, play the desired audio stream, and FFmpeg will capture the audio in real-time. You can modify the output parameters of the FFmpeg command to stream the audio to an RTMP server, encode it into different formats (like AAC, FLAC, or OGG), or apply real-time audio filters.