Getting audio from LibVLC

This forum is about all development around libVLC.
SilentSin
New Cone
New Cone
Posts: 3
Joined: 18 Mar 2016 05:34

Getting audio from LibVLC

Postby SilentSin » 18 Mar 2016 06:13

I'm using ffmpeg to stream video and audio from a WebCam over a network then using a modified version of Hyper VLC (a C# wrapper around LibVLC) to get it into Unity. After a bit of work I've managed to get the video working well, but HyperVLC doesn't handle audio so I'm trying to add it myself and I can't figure out how to get the audio data out of LibVLC.

I initialise the audio similar to the video using libvlc_audio_set_format and libvlc_audio_set_callbacks, giving it OnPlayAudio(void* data, void* samples, uint count, long pts) as the play callback. But I can't figure out how to use the parameters that method gives me. "data" is always null, and I've tried marshalling "samples" into a float array, but it only gives exponentially small values and NaNs.

I need to get the audio as a float array (with all values between 0 and 1 I believe) to give to Unity. Any help would be greatly appreciated.

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Getting audio from LibVLC

Postby Rémi Denis-Courmont » 18 Mar 2016 20:49

I believe this is documented in the LibVLC Doxygen. IIRC, <data> is your opaque data pointer, which you set in the format callback. I'm not sure floating point is implemented yet there (though VLC supports it internally).
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

SilentSin
New Cone
New Cone
Posts: 3
Joined: 18 Mar 2016 05:34

Re: Getting audio from LibVLC

Postby SilentSin » 18 Mar 2016 23:05

Thanks for your response.

Is this what you mean by the LibVLC Doxygen? Or is there a different section I should be looking at?

Can you please explain or point me to somewhere that explains what an opaque data pointer actually is?

If it doesn't come in as floats, should I marshal it as bytes or ints then scale them down into the 0-1 range floats Unity needs?

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Getting audio from LibVLC

Postby Rémi Denis-Courmont » 19 Mar 2016 02:17

Gee, the opaque data is what you make it. LibVLC does not know or care what it is.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

SilentSin
New Cone
New Cone
Posts: 3
Joined: 18 Mar 2016 05:34

Re: Getting audio from LibVLC

Postby SilentSin » 19 Mar 2016 03:15

That doesn't make sense. Either the parameter is completely useless or it is actually used in some way. If I pass in a pointer to a float[], it can't possibly be used in the same way as if I were to pass in a pointer to a single int or a string or something else entirely.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Getting audio from LibVLC

Postby Jean-Baptiste Kempf » 28 Jun 2016 09:51

opaque is used for your usage, so you get it in the callback.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 24 guests