Page 1 of 1

Some video's dont run from lib but do work in player

Posted: 14 Mar 2019 12:31
by nocoffee
Hi,
Recently I have used LibVLCsharp to put a Mediaplayer on a simple c# application to stream video URL's.
As 'libvlc' I used a downloaded copy (minus the application exe's and skins) I already had installed on my system - in this case a recent 3.0.7 nightly.

Streaming an RTSP camera and the big buck bunny example (https://www.w3schools.com/html/mov_bbb.mp4) works great.
However some video's don't work - in particular a YouTube video or live stream.
The odd thing is, in the standalone VLC player it works but using the exact same software as library it doesn't. So I wonder what the difference could be ?

Example trying to play: https://www.youtube.com/watch?v=foyufD52aog
Works in standalone player. Doesn't work in the c# app.

Where the VLC player at some point logs :

Code: Select all

main debug: `https://www.youtube.com/watch?v=foyufD52aog' successfully opened
instead I captured the following from the player in my c# app. These do not occur in the messages of the VLC player:

Code: Select all

http debug: in DATA (0x00) frame of zu bytes, flags 0x3ff9, stream 0 Call Stack: at MyVideoStreamer.VideoStreamer._libVLC_Log(Object sender, LogEventArgs e) in C:\Users\nocoffee\Desktop\ViewApps\VideoStreamer\VideoStreamer.xaml.cs:line 125 at LibVLCSharp.Shared.LibVLC.<>c__DisplayClass41_0.<OnLogInternal>b__0() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() at System.Threading.Tasks.Task.ExecutionContextCallback(Object obj) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution) at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() http debug: in DATA (0x00) frame of zu bytes, flags 0x4000, stream 0 Call Stack: at MyVideoStreamer.VideoStreamer._libVLC_Log(Object sender, LogEventArgs e) in C:\Users\nocoffee\Desktop\ViewApps\VideoStreamer\VideoStreamer.xaml.cs:line 125 at LibVLCSharp.Shared.LibVLC.<>c__DisplayClass41_0.<OnLogInternal>b__0() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() at System.Threading.Tasks.Task.ExecutionContextCallback(Object obj) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution) at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
The lib seems to be able to open the initial stream and the youtube lua logs the metadata correctly (Name, ArtURL, Description, etc) but the actual video content doesn't get streamed.
Any idea what the difference could be? Thanks,

Re: Some video's dont run from lib but do work in player

Posted: 14 Mar 2019 14:56
by mfkl
Hi,

A few things.
As 'libvlc' I used a downloaded copy (minus the application exe's and skins) I already had installed on my system - in this case a recent 3.0.7 nightly.
This is NOT the recommended way of installing libvlc. See https://code.videolan.org/videolan/LibV ... stallation and https://code.videolan.org/videolan/libvlc-nuget for more info. Bundling libvlc in your app like you did will cause you issues long term.

Logging is a Work in Progress. It currently kinda works, but on Windows only. See the why and what we will do about it here: https://github.com/videolan/libvlcsharp/pull/15. So if the Log event blows up for you, don't use it.

Second, without your code it's hard for me to tell what's wrong. To play a youtube video, use code like this:

Code: Select all

Core.Initialize(); var libVLC = new LibVLC("--verbose=2"); var media = new Media(libVLC, "https://www.youtube.com/watch?v=foyufD52aog", FromType.FromLocation); await media.Parse(MediaParseOptions.ParseNetwork); var mp = new MediaPlayer(media.SubItems.First()); mp.Play();

Re: Some video's dont run from lib but do work in player

Posted: 15 Mar 2019 10:20
by nocoffee
Cool, Thanks for the feedback!
I changed it to the NuGet package as per recommendation.

The trick with the youtube video seemed to be in the media.Parse() and usage of the media.SubItems. I was just using the mediaplayer.Play(new Media(...)) which didn't work for youtube.
As the MRL can be a variety of different sources, such as an MP4 over http or camera stream over RTSP, the SubItems are not always populated. I there a recommended way to handle all the different types of content?
Additionally, the code change works for youtube video's but doesn't work for youtube live streams (produces an error). Is this known behavior or does it need yet another way of handling?

Another thing I was wondering:
After the "EndReached" event the video stops, fires the "Stopped" event and then stays on the last frame of the video. Issuing a Play() again in that state doesn't work but seems to need a Stop() first.
However when I do this from the event handler the app freezes up (probably due to threading issues). Is there a recommended way to put the player in proper stopped state after EndReached?

Thanks for this awesome library!

Re: Some video's dont run from lib but do work in player

Posted: 16 Mar 2019 18:16
by mfkl
I there a recommended way to handle all the different types of content?
Not that I know of. You will need to check subitems for youtube videos and local network shares navigation, at least.
Additionally, the code change works for youtube video's but doesn't work for youtube live streams (produces an error). Is this known behavior or does it need yet another way of handling?
I'm not aware of this. Please share the error/logs and the stream. Open an issue at https://code.videolan.org/videolan/LibVLCSharp for this please.
when I do this from the event handler the app freezes up (probably due to threading issues).
Known limitation https://forum.videolan.org/viewtopic.php?t=106174. We may be able to fix this limitation from within libvlcsharp though. I'll open an issue for that.
Is there a recommended way to put the player in proper stopped state after EndReached?
Just call stop from another thread, I guess?

Re: Some video's dont run from lib but do work in player

Posted: 16 Mar 2019 21:12
by mfkl
VLC deskop doesn't work with youtube live streams either

Code: Select all

lua error: Couldn't extract youtube video URL, please check for updates to this script
Patch welcome