Skip to content

Instantly share code, notes, and snippets.

@mouseos
Created February 7, 2022 05:54
Show Gist options
  • Save mouseos/6e231118939b525423bc99bd6ccfe905 to your computer and use it in GitHub Desktop.
Save mouseos/6e231118939b525423bc99bd6ccfe905 to your computer and use it in GitHub Desktop.
import subprocess
import re
import sys
from subprocess import Popen
import PySimpleGUI as sg
sg.theme('SystemDefault') #テーマを設定
#ffmpegとpythonを使ってオーディオデバイス一覧を取得しpysimpleguiで表示します。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):
if ("(video)" not in line):
if (len(d1) == 0): #余計な改行が入らないようにする
d1 = d1 + (line)
else:
d1 = d1 + "\n" + (line)
#余計な文字を削除
d2 = re.sub(r"\[dshow.*\] \"|\" \(.*","" , d1) #デバイス一覧を生成
#dshowが含まれる行を削除
d3 = ""
for line in d2.split('\n'):
if ("dshow" not in line):
if (len(d3) == 0): #余計な改行が入らないようにする
d3 = d3 + (line)
else:
d3 = d3 + "\n" + (line)
#一覧を表示
#print(d3)
d4 = d3.split("\n") #改行で区切って配列に入れる
print(d3)
values = d4
layout = [[sg.Combo(values, default_value="入力デバイス", size=(80,1)) ]]
window = sg.Window('サンプル', layout)
# イベントループ
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
window.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment