VideoLan.Interop a .Net libvlc 0.9.x wrapper

This forum is about all development around libVLC.
Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 17 Aug 2009 19:02

Hi Kairos,
As a hobby, I am developing a small application to play, record, split and join video files. This all works using your 0.9 wrapper which is much appreciated. The issue I have right now is with a film strip timeline I have added on to show 100 stills / frames at equally spaced time intervals. The problem is that vlcmediaplayer.video.width and height take much longer to retrieve than vlcmediaplayer.length even though all three are subject to a VlcState.Playing = true test polled for through a timer. The length is returned as soon as play commences but the width and height seems to take up to 6 seconds from the start of play. I tried a Do Until approach wrapped in a Try Catch but I can't seem to avoid a 'read / write to protected memory' error. For the moment, I have put in a 6 second Thread.Sleep in the main UI thread before making the width and height calls to avoid the constant crashes.

Does it make sense to you that the width and height calls should take so long ?

If it does, is there an elegant way to catch the protected memory error so that the Do Until can continue looping until the width and height 'arrive' ?

Appreciate anyone's help.

Septic
New Cone
New Cone
Posts: 3
Joined: 07 Sep 2009 22:33

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Septic » 07 Sep 2009 22:40

[Edit]
Has anybody noticed the Mistake in VlcMediaEnumerator?

Movenext: return (++_index >= _mlist.Count); --> return (++_index < _mlist.Count);


I also have problems with Chapters

libvlc_video_get_chapter_description --> crashes with AccessViolationException - any Idea?

[Originalmessage:]
[Solved: DAMNIT!! I Should really read the whole thread xD
added [return:MarshalAs(UnmangedType.AnsiBStr)] for
libvlc_exception_get_message
libvlc_media_get_meta
libvlc_media_get_mrl
]
Hi,

i have problems calling libvlc_media_get_mrl and libvlc_media_get_meta with the .net wrapper, i always get a AccessViolationException


anybody has a solution?

jmhecker
New Cone
New Cone
Posts: 3
Joined: 12 Sep 2009 19:32

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby jmhecker » 12 Sep 2009 22:18

I am currently working on a small media player (just for fun), and am wondering if there is any way to handle mouse events with this wrapper? Once VlcPlayer takes over the panel control, no mouse events work on that control, so it seems to me that any right-click functionality is lost (for using a custom context menu).

Can anyone offer any ideas/advice?

Below is how I call the wrapper (yes, it is vb.net, but post replies in C# if need be, I use both)


Vlc = New VideoLanClient()
Dim desc As VlcMedia = Vlc.NewMedia("C:\21.avi")
VlcPlayer = Vlc.NewMediaPlayer(Panel1.Handle, desc)
desc.Dispose()
VlcPlayer.Play().


EDIT:

So, I tried to create a custom control, which houses the Panel that the VLC library uses, and added that to my form...I put a context menu onto the custom control (from the parent window, not the custom control itself) hoping it would work...still not working.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 13 Sep 2009 23:14

try to "disable" the panel, or put the panel inside another control, which is disabled.

In my case, i use WPF, so i got the panel is inside a "WindowsFormsHost", which is disabled. Vlc can still work with the panel and display the video inside, but any mouse interaction is ignored by the "WindowsFormsHost" and everything inside. So mouse actions go through the "WindowsFormHost", and reach the window behind and its context menu.

Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 18 Sep 2009 20:11

Hi XilasZ,
Please could you help me out with libvlc_media_get_meta. I am trying out what you suggested and have included the MarshallAs as follows:

[DllImport("libvlc")][return: MarshalAs(UnmanagedType.AnsiBStr)]
internal static extern String libvlc_media_get_meta(etc...);.

However, I still get the protected memory error. What am I doing wrong ?

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 21 Sep 2009 10:10

Maybe the get_meta is not causing the error.

The protected memory error can happen for many many reasons, wrong timing when calling a libvlc function (for instance, don't try to get info on the media while nothing is playing, it fails, and it's normal), a type mismatch between c# and libvlc, wrong pointer arguments for a function (don't use the instance pointer instead the media player pointer, and vice versa), ....

If you are sure that get_meta is causing the error, how and when do you call it ?

Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 22 Sep 2009 18:13

I am actually calling ReadMeta 3 seconds after a particular song has started to play, using <vlcmedia>.ReadMeta(libvlc_meta_t.libvlc_meta_Artist). Here is a summary of the relevant code in VB:

Dim vlcControl As VideoLan.VideoLanClient
vlcControl = New VideoLanClient(".")
Dim aaChannelDesc As VlcMedia = vlcControl.NewMedia(aaIncomingPathFileName)
... add some options and play, then 3 seconds later:

Dim strSongMeta as String = aaChannelDesc.ReadMeta(libvlc_meta_t.libvlc_meta_Title)

The last line above results in a protected memory error on the first line of the ReadMeta sub in vlcMedia.cs which is
string rtn = InteropMethods.libvlc_media_get_meta(p_media, tag, ref p_exception);

Does this throw any light on the problem ? I'm obviously doing something wrong but can't figure out where. I should also mention that I have a similar protected memory problem retrieving vlcmediaplayer.video.width. which I have described about 6 posts above. Maybe they are connected.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 23 Sep 2009 11:33

it should be ok.

I see that you use libvlc 0.9 ? I didn't try to read meta when i was still using 0.9.
Now i'm using libvlc 1.0.1, after upgrading the wrapper myself. maybe read meta doesn't work in libvlc 0.9. Or i fixed something else in the wrapper, but don't know where :P

Take a look at my code if you want, you may found a clue.

noknok
Blank Cone
Blank Cone
Posts: 30
Joined: 08 Sep 2009 23:06

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby noknok » 25 Sep 2009 18:29

I have been using the VideoLan Interop on VLC 1.0.0,1.0.1 and now 1.0.2...

When trying to .DISPOSE on the PLAYER object, AFTER it has ended, the hangds in the COM layer.

This occurs as in the Dispose method of the player, it calls .STOP, no matter the current state.

Not sure how to (a) submit recommended changes to the source (b) report a bug so you can can do the changes.

Shawn

Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 26 Sep 2009 17:40

XilasZ: thanks for your help and for letting me look at your code. It was interesting for me to see that you can obtain the song name by calling ReadMeta after Load and before Play Anyway, I still can't get it work for me on vlc 0.9. As an interim measure, I have obtained what I need using a background instance of Windows Media Player.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 27 Sep 2009 16:56

I have been using the VideoLan Interop on VLC 1.0.0,1.0.1 and now 1.0.2...

When trying to .DISPOSE on the PLAYER object, AFTER it has ended, the hangds in the COM layer.

This occurs as in the Dispose method of the player, it calls .STOP, no matter the current state.
Try to remove the link between libvlc and the display surface before calling dispose.
libvlc is running in its own thread, and might be trying to display something after the display surface has been destroyed.
just call "libvlc_media_player_set_hwnd(p_media_player, IntPtr.Zero, ref p_exception);" before dispose.

noknok
Blank Cone
Blank Cone
Posts: 30
Joined: 08 Sep 2009 23:06

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby noknok » 28 Sep 2009 00:58

Im actually running with no display setup initially as IntPtr.Zero.. It was doing a transcode session.

chinpao
New Cone
New Cone
Posts: 3
Joined: 28 Sep 2009 21:37

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby chinpao » 28 Sep 2009 21:50

Hello, I downloaded version 1.0.0 from http://meedios.svn.sourceforge.net/view ... /VideoLan/
Everything works fine, but when I use the sampleProject VlcMediaListPlayer.Sample the player crashes after playing the first item of the playlist,
I debugged a little bit and found that playing next item is not implemented yet,
so I added to method:
VlcPlayer_StateChanged(object sender, StateChangedEventArgs e)
..
case VlcState.Ended:
//The file ended play the next one
VlcPlayer.Next();
..
and the player hangs again..
I found out that the crash happens when calling
InteropMethods.libvlc_media_list_player_next(p_ml_player, ref p_ex);
in the file VlcMediaListPlayer.cs

Maybe someone can help me, thanks

Sebastian

AJR
New Cone
New Cone
Posts: 1
Joined: 11 Oct 2009 00:54

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby AJR » 11 Oct 2009 00:59

I've compiled the DLL and pointed the VideoLanClient at my VLC directory but every time I run my application I get this error:
"Unable to find an entry point named 'libvlc_media_player_set_hwnd' in DLL 'libvlc'."

Any pointers?

For reference I'm using this code to start the player:

Code: Select all

VideoLan.VideoLanClient client = new VideoLan.VideoLanClient(@"E:\VLC\"); VideoLan.VlcMedia video = client.NewMedia(file_path); VideoLan.VlcMediaPlayer tmp = client.NewMediaPlayer(pnl_video.Handle,video); tmp.Play();
EDIT: I tried 0.9.0 instead of 1.0.0 and it works fine. Don't mind me.

jlg42
New Cone
New Cone
Posts: 1
Joined: 13 Oct 2009 18:24
VLC version: 1.0.0.1
Operating System: Windows
Location: France

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby jlg42 » 13 Oct 2009 18:42

Hello, I downloaded version 1.0.0 and I use VideoLan.Interop-2005_1.0.0.sln projet and VLC 1.0.0.1

I just change this line in the VlcMediaPlayer.Sample project file PlayerUi.cs
Vlc = new VideoLanClient();
by
Vlc = new VideoLanClient("C:\\Program Files\\VideoLAN\\VLC");
to use my actual VLC

I choose to read mp3 file
When play no error but no sound

the wrapper is not compatible with vlc 1.x ?

Maybe someone can help me, thanks

Jeremiah
Blank Cone
Blank Cone
Posts: 53
Joined: 16 Oct 2008 09:31

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Jeremiah » 26 Oct 2009 10:50

hi,all
i got a question.

i use vlc-1.0.2 for C# wrapper.
and use libvlc_media_player_set_hwnd to set the parent of the video.

but it create a new window titled "hardware YUV overlay DirectX output"

[DllImport("libvlc")]
private static extern void libvlc_media_player_set_hwnd(CoreHandle coreHandle, IntPtr hDT, ref ExceptionStruct ex);

IntPtr hdl = this.panel1.Handle;

libvlc_media_player_set_hwnd(coreHandle, hDT, ref ex);

so do anyone know what's the problem?

tido
New Cone
New Cone
Posts: 4
Joined: 28 Oct 2009 23:40

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby tido » 01 Nov 2009 10:24

[...]
i use vlc-1.0.2 for C# wrapper.
and use libvlc_media_player_set_hwnd to set the parent of the video.

but it create a new window titled "hardware YUV overlay DirectX output"
[...]
so do anyone know what's the problem?
I don't use this wrapper, but this works for me.

Code: Select all

libvlc_media_player_set_drawable(this.vlc_mi, this.vlc_window.Handle, ref vlc_e);
vlc_window is just a plain System.Windows.Form

Jeremiah
Blank Cone
Blank Cone
Posts: 53
Joined: 16 Oct 2008 09:31

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Jeremiah » 05 Nov 2009 06:56

[...]
i use vlc-1.0.2 for C# wrapper.
and use libvlc_media_player_set_hwnd to set the parent of the video.

but it create a new window titled "hardware YUV overlay DirectX output"
[...]
so do anyone know what's the problem?
I don't use this wrapper, but this works for me.

Code: Select all

libvlc_media_player_set_drawable(this.vlc_mi, this.vlc_window.Handle, ref vlc_e);
vlc_window is just a plain System.Windows.Form
set_drawable is the same result。

jcvu
New Cone
New Cone
Posts: 2
Joined: 13 Jun 2008 19:47

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby jcvu » 09 Nov 2009 23:10

Hello, I am new here.
I just download the solution from here
http://meedios.svn.sourceforge.net/view ... /VideoLan/
It compiles and plays fine. I notice that when a file is first play, the player displays the file name at the middle bottom for like 5 second. Is there a way for me to change the time as well as changing the text? I want to display the movie clip name, not file name. Also, how do you display text on the player? I tried to use label control but it leaves a white box (or whatever color is ur control if you set backcolor as transparent).

Thanks

JC

faheemnadeem
New Cone
New Cone
Posts: 6
Joined: 01 Dec 2009 10:49

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby faheemnadeem » 01 Dec 2009 11:01

Hi,
I wish to capture an rtsp stream like rtsp://192.168.1.100:554 and record the raw video locally.
Is it possible using the libvlc and this wrapper.

faheemnadeem
New Cone
New Cone
Posts: 6
Joined: 01 Dec 2009 10:49

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby faheemnadeem » 01 Dec 2009 11:03

And secondly is it possible to add text overlay too????

faheemnadeem
New Cone
New Cone
Posts: 6
Joined: 01 Dec 2009 10:49

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby faheemnadeem » 01 Dec 2009 11:36

Hi,
I am unable to run any of the sample applications you have provided...
I even installed 0.9.2 and 1.0.0 versions and nothing seems to be happening whenever i play a file.
Do i have to do something extra, currently i am just playing your sample app and opening a file but nothing happens when i play.
Please help me as i am a noob in this stuff.

Webuser
New Cone
New Cone
Posts: 2
Joined: 28 Dec 2009 14:21

How to set subtitle on stream with VideoLan.Interop .Net lib

Postby Webuser » 04 Jan 2010 09:44

Hi,
Can somebody show me how I can change subtitle on a video stream (file) with subtitles?

Here is my code:

Code: Select all

VideoLan.VideoLanClient Vlc; VideoLan.VlcMediaPlayer VlcPlayer; Vlc = new VideoLanClient(); VlcPlayer = Vlc.NewMediaPlayer(pnlVideo.Handle); private void Play() { VlcMedia desc = Vlc.NewMedia(@"C:\MovieWithAudiosAndSubtitles.ts"); desc.AddOption(":udp-caching=1000"); desc.AddOption(":clock-synchro=1"); desc.AddOption(":video-filter=adjust:deinterlace"); desc.AddOption(":deinterlace-mode=discard"); desc.AddOption(":codec=ffmpeg,none"); desc.AddOption(":drop-late-frames"); desc.AddOption(":high-priority"); desc.AddOption(":no-video-title-show"); VlcPlayer.Load(desc); desc.Dispose(); VlcPlayer.Play(); } private void btnSetAudioAndSubtitle_Click(object sender, EventArgs e) { // Changed language to English VlcPlayer.Audio.Track = 2; // Set audio to 2, english works try { VlcTrack track = VlcPlayer.Subtitles[7706]; // 7706 = Key id of the subtitle VlcPlayer.Subtitles.Current = track; // This will throw exception, but why? It found the track, but will not set it. } catch(Exception ex) { MessageBox.Show(ex.Message); } }
I got exception when change the subtitle. The exception is "Subtitle value out of range".
If I run the application in debug mode, I found 3 subtitles available, but can't find how to set them.

Code: Select all

namespace VideoLan { public abstract class VlcTracks : IEnumerable<VlcTrack> { public VlcTrack Current { get { if (_ReloadTracks) LoadTracks(); lock (Player.player_lock) { int rtn = GetTrackCurrentInternal(); Player.p_ex.CheckException(); return _Tracks[rtn]; } } set { if (_ReloadTracks) LoadTracks(); lock (Player.player_lock) { if (_Tracks.ContainsKey(value.ID)) { SetTrackCurrentInternal(value.ID); Player.p_ex.CheckException(); } } } }
_Tracks.Count = 3
_Tracks:
[0] {[-1, VidoLan.VlcTrack]}
[1] {[7606, VidoLan.VlcTrack]}
[2] {[7706, VidoLan.VlcTrack]}


In VLC media player v1.0.3 I can change the subtitle on the same stream (file) without problems, but I don't know how to do it in VideoLan.Interop .Net wrapper.

Please help me!
Regards Sondre

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 06 Jan 2010 15:23

Thanks to vlc, get and set for video/audio/subtitle tracks don't work the same way.
Sometimes it's the track index, sometimes it's the track id, or a mix.

To set subtitle track, you need to use the track index to change track, and use "-1" to disable subtitles (so yes, its a mix of id and index).

I didn't try the last wrapper (i use my own wrapper based on the wrapper v0.9) so you may have to modify the wrapper :P

Webuser
New Cone
New Cone
Posts: 2
Joined: 28 Dec 2009 14:21

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Webuser » 08 Jan 2010 15:41

Thanks for your response :)

A friend of my helped me, and now I have a solution to my problem :)
To use subtitle in a stream, I can't add option ":codec=ffmpeg,none");". If I removed that I can set subtitle and it will works.
I also found out that subtitle id is not the right value when setting subtitle. Subtitle value must be 0, 1, 2 etc. not 7606 as my subtitle says.

Regards Sondre


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 19 guests