run command that gets error thought python

185 views Asked by At

Wassup.
I have shell command.

ffmpeg -list_devices true -f dshow -i dummy -hide_banner

When i run that command i get output data(see text bellow)

[dshow @ 00000281450fbdc0] DirectShow video devices (some may be both video and audio devices)
[dshow @ 00000281450fbdc0]  "HD WebCam"
[dshow @ 00000281450fbdc0]     Alternative name "@device_pnp_\\?\usb#vid_0408&pid_a060&mi_00#6&391c16c1&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
[dshow @ 00000281450fbdc0] DirectShow audio devices

[dshow @ 00000281450fbdc0]  "Microphone (Realtek High Definition Audio)"
[dshow @ 00000281450fbdc0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{4727F33A-DE04-4706-8312-03696FACC791}"
[dshow @ 00000281450fbdc0]  "Stereo mix (Realtek High Definition Audio)"
[dshow @ 00000281450fbdc0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{534A8FBC-6C02-4384-B51C-D0363BB7F8FD}"
[dshow @ 00000281450fbdc0]  "Microphone (Avsoft Virtual Audio Device)"
[dshow @ 00000281450fbdc0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{5CE20B48-361E-4B96-B113-B3E02BA448EC}"
dummy: Immediate exit requested

I have to get list of all audio devices. And i don't want to parse that string, i will be hard. How can i get list of all audio devices using ffmpeg-python module? Thank u.

UPD: i have decided to parse that string. But when i type:

command = subprocess.check_output('ffmpeg -list_devices true -f dshow -i dummy -hide_banner', shell=True)

i get this error:

subprocess.CalledProcessError: Command 'ffmpeg -list_devices true -f dshow -i dummy -hide_banner' returned non-zero exit status 1.


How can i call that command and put its result into my variable "command"?

1

There are 1 answers

1
Nikto On
command = subprocess.run('ffmpeg -list_devices true -f dshow -i dummy -hide_banner', shell=True, stderr=subprocess.PIPE, text=True, encoding='utf-8')
print(command.stderr)