[FFmpeg-user] Reliable audio capture method on windows ? (stereo mix does not exist on most computers)

Joe Smithy ffmpeg-user at domn.net
Tue Nov 8 08:17:28 EET 2022


Hi,

I need a way to capture output audio that works reliably on most computers
without having to know anything about the state of said computer.

Searching for ffmpeg how to capture desktop audio only returns variants of

-f dshow -i audio="Stereo Mix (Realtek High Definition Audio)"


However, none of the computers I have in the house have any form of "stereo
mix" recording device

Yes,I did try all of these fixes

https://www.wintips.org/how-to-enable-stereo-mix-if-not-showing-as-recording-device-in-windows-11-10/
https://www.hitechwork.com/how-to-restore-missing-stereo-mix-on-windows-10/
https://answers.microsoft.com/en-us/windows/forum/all/stereo-mix-missing-in-windows-10-did-they-remove/abd60f1a-1ad2-4928-a7a2-b723d84bc5bc
https://answers.microsoft.com/en-us/windows/forum/all/stereo-mix-not-showing/2b706268-7887-42ec-9064-9418d16e99a8
https://thedroidguy.com/how-to-restore-missing-stereo-mix-on-windows-10-1147145
https://appuals.com/how-to-restore-missing-stereo-mix-on-windows-10/

None of them work, stereo mix is a sound card driver feature that only
exists on some cards and only some drivers. Most random computers you come
across will not have this so giving the user a ffmpeg command string almost
always fails.

As far as I can tell, ffmpeg has no current way of desktop audio capture on
windows

If it existed, I think it would be described here
https://ffmpeg.org/ffmpeg-all.html#toc-Audio-Sources ?

But audio capture is possible without 3rd party applications or drivers on
windows. OBS proves it, it can capture on all of my computers without any
prior setting up

There seems to be two systems which OBS uses, one that can capture all
system output audio and one that can capture audio on a per application
basis.

I'm not sure what the API is for the whole desktop (presumably an older
API), but the for the per-application capture, it is using the
ActivateAudioInterfaceAsync
<https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-activateaudiointerfaceasync>
API, which has been back ported to later versions of windows 10.

I have done some poking around in the ffmpeg code and found these clues to
how they are doing it.


obs forum post by audio capture dev
https://obsproject.com/forum/threads/audiosource-sortaudio.11355/#post-63438


audio related obs files
https://github.com/obsproject/obs-studio
https://github.com/obsproject/obs-studio/blob/master/libobs/media-io/audio-io.h
https://github.com/obsproject/obs-studio/blob/master/libobs/media-io/audio-io.c
https://github.com/obsproject/obs-studio/blob/master/libobs/obs-audio.c
https://github.com/obsproject/obs-studio/blob/master/libobs/obs-audio-controls.c
https://github.com/obsproject/obs-studio/blob/master/libobs/audio-monitoring/osx/coreaudio-enum-devices.c
https://github.com/obsproject/obs-studio/blob/master/plugins/coreaudio-encoder/encoder.cpp

win-capture-audio
https://github.com/bozbez/win-capture-audio
ActivateAudioInterfaceAsync with AUDIOCLIENT_PROCESS_LOOPBACK_PARAMS
https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-activateaudiointerfaceasync
https://docs.microsoft.com/en-us/windows/win32/api/audioclientactivationparams/ns-audioclientactivationparams-audioclient_process_loopback_params
https://github.com/bozbez/win-capture-audio/blob/main/src/audio-capture.hpp
https://github.com/bozbez/win-capture-audio/blob/main/src/audio-capture.cpp


More information about the ffmpeg-user mailing list