Created
February 6, 2022 12:14
-
-
Save mouseos/2df453f58b1c3a4b3a1f52e23a460610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from subprocess import Popen | |
import re | |
import sys | |
#ffmpegとpythonを使ってオーディオデバイス一覧を取得します。Windowsでしか動作しません。 | |
#ffmpegを同じディレクトリに置くか、パスを通すかしてください。 | |
#コマンド実行 | |
def cmdline(command): | |
process = subprocess.Popen( | |
args=command, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
shell=True | |
) | |
return process.communicate() | |
device_cmd = (cmdline('ffmpeg -list_devices true -f dshow -i dummy')[1].decode()) #ffmpegを呼び出し結果取得 | |
#ext_devices = | |
#dshowが含まれる行を抽出 | |
d1 = "" | |
for line in device_cmd.split('\n'): | |
if ("dshow" in line): | |
d1 = d1 + "\n" + (line) | |
#余計な文字を削除 | |
d2 = re.sub(r"\[dshow.*\] \"|\" \(.*|.* \(video\)","" , d1) #デバイス一覧を生成 | |
#dshowが含まれる行を削除 | |
d3 = "" | |
for line in d2.split('\n'): | |
if ("dshow" not in line): | |
d3 = d3 + "\n" + (line) | |
#一覧を表示 | |
print(d3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment