1

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"?

  • I also interested – Nikto Oct 02 '20 at 14:33
  • 1
    FFmpeg is open-source, you modify `dshow_cycle_devices` in `libavdevice/dshow.c` to output whatever structured format you want or add your own function. – aergistal Oct 02 '20 at 15:14
  • @aergistal, 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 got 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"? – kali_xyyali Oct 03 '20 at 09:23
  • I would like to suggest u this(https://stackoverflow.com/questions/24849998/how-to-catch-exception-output-from-python-subprocess-check-output). But i have made some tests and it didn't work for ur command – Nikto Oct 03 '20 at 12:22
  • 1
    @kali_xyyali It's normal for the command to fail since it's using a dummy input, just pipe `stderr`. – aergistal Oct 03 '20 at 13:18
  • I don't know how can i do that. I have seen behaviour like that in the first time – kali_xyyali Oct 03 '20 at 14:10
  • It's for notification – kali_xyyali Oct 03 '20 at 14:11

1 Answers1

0
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)
Nikto
  • 212
  • 3
  • 13
  • 3
    Could you maybe write a short description to see, what was the problem / what you changed, to make it a bit easier for people, who find your post if they search for a solution? – jottbe Oct 03 '20 at 15:38