How to use two sound cards with VLC python binding?

This forum is about all development around libVLC.
djdjdj
Blank Cone
Blank Cone
Posts: 15
Joined: 09 Sep 2010 16:42

How to use two sound cards with VLC python binding?

Postby djdjdj » 09 Sep 2010 16:51

I have been trying to use two sound cards (one internal and the other external) for listening and previewing purposes (DJ application). I see Instance.audio_output_list_get(), but don't know what to do with it. This function returns an AudioOutput object. Is it possible to read and play two different audio files to two different sound cards using VLC python binding?

OlivierAubert
Developer
Developer
Posts: 92
Joined: 08 Mar 2007 15:43

Re: How to use two sound cards with VLC python binding?

Postby OlivierAubert » 13 Sep 2010 21:21

There is a MediaPlayer.audio_output_set() method that should work. See
http://www.advene.org/download/python-c ... device_set

djdjdj
Blank Cone
Blank Cone
Posts: 15
Joined: 09 Sep 2010 16:42

Re: How to use two sound cards with VLC python binding?

Postby djdjdj » 17 Sep 2010 22:42

Thanks so much Olivier. Now I know what I can use, but still have difficulty. For example,

i=vlc.Instance()
mp=i.media_player_new()
mp.audio_output_device_set(... <- what parameters should I use?

Its document says
audio_output_device_set(self, psz_audio_output, psz_device_id)
* psz_audio_output - - name of audio output, See libvlc_audio_output_t
* psz_device_id - device

But, I don't know what to put as the name audio output nor as device_id. I tried

i.audio_output_list_get()

and got just <vlc.AudioOutput object at 0x00BA6FB0>, for example.

Where can I find what is "psz_audio_output" and what I have as options for that? The same question for psz_device.

Thanks again.

djdjdj
Blank Cone
Blank Cone
Posts: 15
Joined: 09 Sep 2010 16:42

Re: How to use two sound cards with VLC python binding?

Postby djdjdj » 18 Sep 2010 13:09

I did some more research. I can get the followings.

>i=vlc.Instance()
>mp=i.media_player_new()
>i.audio_output_device_id('waveout', 0)
'wavemapper'
>i.audio_output_device_id('waveout', 1)
'USB Audio CODEC ($ffff,$ffff)
>i.audio_output_device_id('waveout', 2)
'SigmaTel Audio ($1,$64)'

But, the following didn't work.
>mp.audio_output_device_set('waveout', i.audio_output_device_id('waveout', 1))
>mp.audio_output_device_set('waveout', i.audio_output_device_id('waveout', 2))

When each of the two used, music always played through "USB Audio CODEC" which is the default I think.

What can I do?

OlivierAubert
Developer
Developer
Posts: 92
Joined: 08 Mar 2007 15:43

Re: How to use two sound cards with VLC python binding?

Postby OlivierAubert » 20 Sep 2010 15:51

The audio_output_list_get function was not properly wrapped. I have fixed this in the git tree, there is now a Instance.audio_output_enumerate_devices() method.

djdjdj
Blank Cone
Blank Cone
Posts: 15
Joined: 09 Sep 2010 16:42

Re: How to use two sound cards with VLC python binding?

Postby djdjdj » 21 Sep 2010 01:45

Hi Olivier, thanks for your reply and update on the program. I recognize you as the author of vlc.py now. Thanks for this great binding.

I haven't been able to use two sound cards yet. I have tried the following so far.

>i=vlc.Instance()
>mp=i.media_player_new()
>m=i.media_new(filename)
>ed=i.audio_output_enumerace_devices()
>ed
[{'name':'waveout', 'devices':[{'id':wavemapper', 'longname':'Microsoft Soundmapper'}, {'id':'USB Audio CODEC ($ffff,$ffff)', 'longname':'USB Audio CODEC ($ffff,$ffff)'}, {'id':'SigmaTel Audio ($1,$64)', 'longname':'SigmaTel Audio ($1,$64)'}], 'description':'Win32 waveOut extension output'},
{'name':'aout_directx', 'devices':[], 'description':'DirectX audio output'},
{'name':'waveout', 'devices':[{'id':wavemapper', 'longname':'Microsoft Soundmapper'}, {'id':'USB Audio CODEC ($ffff,$ffff)', 'longname':'USB Audio CODEC ($ffff,$ffff)'}, {'id':'SigmaTel Audio ($1,$64)', 'longname':'SigmaTel Audio ($1,$64)'}], 'description':'Win32 waveOut extension output'},
{'name':'portaudio', 'devices':[], 'description':'PORTAUDIO audio output'},
{'name':'dummy', 'devices':[], 'description':'Dummy audio output function'},
{'name':'aout_sdl', 'devices':[], 'description':'Simple DirectMedia Layer audio output'},
{'name':'aout_file', 'devices':[], 'description':'File audio output'},
{'name':'aout_directx', 'devices':[], 'description':'DirectX audio output'}]
>mp.play()
(I hear music from my USB sound card, which is "USB Audio CODEC".)
>ed[0]['name']
'waveout'
>ed[0]['devices']
[{'id':wavemapper', 'longname':'Microsoft Soundmapper'}, {'id':'USB Audio CODEC ($ffff,$ffff)', 'longname':'USB Audio CODEC ($ffff,$ffff)'}, {'id':'SigmaTel Audio ($1,$64)', 'longname':'SigmaTel Audio ($1,$64)'}]
(now I try to play through "SigmaTel Audio ($1,$64)", which is the 3rd device of ed[0].
>mp.audio_output_device_set(ed[0]['name'], ed[0]['devices'][2]['id'])
>mp.play()
(I still hear the music through USB Audio CODEC.)
(I even tested the following.)
>mp.audio_output_device_set('aoe', 'aoe')
>mp.play()
(still the music played through USB Audio CODEC.

My plan is to use two media players, one using SimgaTel Audio and the other using USB Audio CODEC. What can I do to achieve this?

Thanks for your help Olivier.

OlivierAubert
Developer
Developer
Posts: 92
Joined: 08 Mar 2007 15:43

Re: How to use two sound cards with VLC python binding?

Postby OlivierAubert » 21 Sep 2010 15:54

Well, I guess that at this point, it concerns the native libvlc API rather than the python bindings: the MediaPlayer.audio_output_device_set is a direct call to libvlc_audio_output_device_set. You may have more luck by creating a new forum thread or asking on IRC or vlc-devel

djdjdj
Blank Cone
Blank Cone
Posts: 15
Joined: 09 Sep 2010 16:42

Re: How to use two sound cards with VLC python binding?

Postby djdjdj » 21 Sep 2010 17:11

Thanks Olivier. I created a new thread.

cobbletone
New Cone
New Cone
Posts: 3
Joined: 31 Oct 2010 02:20

Re: How to use two sound cards with VLC python binding?

Postby cobbletone » 31 Oct 2010 02:51

An alternative is to create a second vlc instance using the --aout option. This works for me using alsa audio:

Code: Select all

import vlc i0 = vlc.Instance('--aout=alsa', '--alsa-audio-device=front:CARD=Speakers,DEV=0') i1 = vlc.Instance() mrl = 'file:///home/user/folders/sample.mp3' m0 = i0.media_new(mrl) m1 = i1.media_new(mrl) mp0 = m0.player_new_from_media() mp1 = m1.player_new_from_media() mp0.play() mp1.play()

djdjdj
Blank Cone
Blank Cone
Posts: 15
Joined: 09 Sep 2010 16:42

Re: How to use two sound cards with VLC python binding?

Postby djdjdj » 02 Nov 2010 22:30

Thanks cobblestone. That approach looks promising. I couldn't make it work in Windows 7, and I think the reason is that the device names have spaces in my computer. For example,

First audio card's name="Speakers (Realtek High Definition Audio)"
Second audio card's name="Speakers (USB Audio CODEC )"

Do you know how to make it work with audio device names with spaces?

cobbletone
New Cone
New Cone
Posts: 3
Joined: 31 Oct 2010 02:20

Re: How to use two sound cards with VLC python binding?

Postby cobbletone » 06 Nov 2010 03:02

I haven't tried this on Windows. Have you tried with quotes:

Code: Select all

i0 = vlc.Instance('--aout=waveout', '--waveout-audio-device="Speakers (Realtek High Definition Audio)"')
or possibly:

Code: Select all

i0 = vlc.Instance('--aout="Speakers (Realtek High Definition Audio)"')
I also noticed this workaround: use --config= option, and specify a different vlc config file.

cen
New Cone
New Cone
Posts: 9
Joined: 13 Jan 2014 12:17

Re: How to use two sound cards with VLC python binding?

Postby cen » 13 Feb 2014 13:30

I could not get the workaround running under win. But if you first do audio_output_set and then audio_output_device_set it works ander win and linux
mp.audio_output_set(ed[0]['name'])
mp.audio_output_device_set(ed[0]['name'], ed[0]['devices'][2]['id'])


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 37 guests