Capture OpenAL Audio with FFmpeg

Capturing audio from an OpenAL source using FFmpeg allows you to record spatialized, in-game, or application-specific audio directly to a file. Because OpenAL outputs sound through your system’s audio subsystem, the most effective way to capture this audio is by routing OpenAL’s output to a virtual loopback device and recording that device with FFmpeg. This guide covers how to set up and execute this capture on both Linux and Windows systems, as well as how to programmatically pipe OpenAL capture buffers directly into FFmpeg.

Method 1: System-Level Capture on Linux (PulseAudio/PipeWire)

On Linux, OpenAL typically outputs to PulseAudio or PipeWire. You can capture this output by recording the “monitor” stream of your audio output device.

1. Identify Your Monitor Source

Open your terminal and run the following command to list your available audio sources:

pactl list sources | grep -E "Name:|Description:"

Look for a source that ends with .monitor (for example, alsa_output.pci-0000_00_1f.3.analog-stereo.monitor).

2. Record with FFmpeg

Once you have the monitor name, use FFmpeg to capture the audio stream using the pulse input device:

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

Replace the -i value with your specific monitor source name.


Method 2: System-Level Capture on Windows (DirectShow)

On Windows, you can capture OpenAL output by using DirectShow to record either “Stereo Mix” or a virtual audio loopback device (like VB-Cable).

1. Enable Stereo Mix

  1. Right-click the speaker icon in your system tray and select Sounds.
  2. Go to the Recording tab.
  3. Right-click an empty space and check Show Disabled Devices.
  4. Right-click Stereo Mix (if available) and select Enable.

2. Identify the Device Name in FFmpeg

Run the following command to list your DirectShow audio devices:

ffmpeg -list_devices true -f dshow -i dummy

3. Record with FFmpeg

Use the exact name of your stereo mix or virtual cable device in the following command:

ffmpeg -f dshow -i audio="Stereo Mix (Realtek High Definition Audio)" output.mp3

Method 3: Programmatic Capture (For Developers)

If you are developing an application using OpenAL and want to capture the audio buffer directly before it reaches the speakers, you can use OpenAL’s extension APIs to capture the PCM data and pipe it to FFmpeg via stdin.

1. OpenAL Capture Initialization

Use alcCaptureOpenDevice in your code to capture the playback mix. Set up a loop to retrieve the raw PCM buffer samples using alcCaptureSamples.

2. Pipe to FFmpeg

Write the raw PCM data directly to standard output (stdout) and pipe the output to FFmpeg in your command line.

Assuming your application outputs raw 16-bit stereo PCM audio at 44.1 kHz, use the following command:

./my_openal_app | ffmpeg -f s16le -ar 44100 -ac 2 -i pipe:0 output.mp3

Command Breakdown: