bozbez / win-capture-audio

An OBS plugin that allows capture of independant application audio streams on Windows, in a similar fashion to OBS's game capture and Discord's application streaming.
GNU General Public License v2.0
3.73k stars 203 forks source link

Doesn't capture the audio if the process doesn't have a window #249

Open darkhog opened 1 year ago

darkhog commented 1 year ago

So I am building my own songrequest system, because there is none for Kick and I am using a wampserver as a way to interface Botrix with my computer. I have set up my wampapache service so that it can actually interact with my desktop using my local account and start processes. That part works fine. It starts mpv and plays youtube video (made a short script allowing playback of any video url).

However what doesn't happen, is for the Application Audio Capture sources that are set to capture mpv.exe (and which do it under normal circumstances, e.g. when using yewtube, a command line YT downloader/player, based on mps-youtube, externally to start up mpv. Also while music is playing there is some weird "unknown" process in the list, which I believe is actually mpv, however adding it doesn't do anything.

The built-in speaker capture from OBS (default one) is working fine and captures audio from processes started by the webserver.

//edit: Steps (likely) to reproduce the issue on Windows:

  1. First install Python 3.10 with PIP (pip is needed to install yewtube). Make sure both pip and python are in the %PATH%.
  2. Install yewtube via PIP by following instructions on https://github.com/mps-youtube/yewtube
  3. PIP may complain that some directory is not in %PATH%. Add the directory PIP mentions to PATH.
  4. Download mpv for windows from https://mpv.io/ and unzip it in a convenient place that's easy to type in. I put mine in c:\mpv, but yours may be different.
  5. Start yewtube by typing in yt.
  6. Use the command set player (path where you have unzipped mpv to)\mpv.exe. It is important so yewtube can actually play stuff.
  7. Check if you did everything correctly by grabbing any YT URL, and executing yt playurl (YT URL) command. MPV should open and play it. At that point, you can add it to the Application Audio Capture source and it will capture audio from it.
  8. Download and install wampserver from https://www.wampserver.com/en/
  9. Actually run the server so it can install and set up services properly.
  10. Go to the services tab of the task manager (run it beforehand of course), right click any spot on the list and click "Open services" or similar (don't have English Windows).
  11. Right click "wampapache64" (or wampapache, if you got somehow a 32bit wampserver), and click Properties.
  12. Go to the second tab
  13. Click "This account" radio button (the second one) and enter your current username (in NT format, so you may be better off to click "browse", "advanced" and "search now" (or "find now", not sure as again, I don't have English Windows), then selecting your user name from the list. Make sure to enter your password as well (if any).
  14. Click okay.
  15. Restart wampapache64 service.

Now for the hard part. You need to make a php file in the www folder of WAMP, that would play any YT url you pass to it. Let's call it music.php.

Code:

<?php
    function BGexec($cmd) {
        shell_exec("start /B ". $cmd);
    }

    $uri = $_GET["url"];
    echo (htmlspecialchars($uri));
    BGexec("yt playurl " . $uri);

?>

Again, put it in the www directory so it can be accessed via the server. Then got to localhost/music?url=YTurl where YTurl is the YT url, including https part (you can use the same one you have used previously to test if you set up yewtube correctly).

If you have done the steps correctly, the audio will play, however it won't be captured by the plugin. The MPV window will also not be visible, nor will have a taskbar button.

I am unsure if the issue is caused by the app not having a window and being a windowless process, or due to the peculiar way I execute it. Either way, it should be fixed.