VLC Pause freeze

This forum is about all development around libVLC.
mystery123sk
New Cone
New Cone
Posts: 8
Joined: 30 May 2020 07:47

VLC Pause freeze

Postby mystery123sk » 01 Jun 2020 11:03

I have a custom renderer to render the video to Bitmap. The problem is, when I use pause function with seek (PauseAt in code), the video stops working after a few PauseAt calls. The CurrenBitmap returns always the same image - same image is rendered by VLC. It happens after several calls of PauseAt. The PauseAt calls VLC's mediaPlayer.Position = perc and mediaPlayer.SetPause(true).

After I use Play again, the video resumes without problem (and I can use the PauseAt several times again).

Is there a recommended way to use Pause in VLC to seek the video randomly?

I also noticed, the freeze happens a lot faster, when I set the mediaPlayer.Position to 0).

Here is my code (using C#):

Code: Select all

unsafe class VideoFileRenderer { public BitmapSource CurrenBitmap => bsg.RenderBitmapSource(); public bool Open(string filename) { mediaPlayer = new MediaPlayer(VLCHandler.LibVLC); //videoView.MediaPlayer = mediaPlayer; media = new Media(VLCHandler.LibVLC, filename, FromType.FromPath, "input-repeat=1000000"); media.Parse().Wait(); UInt32 width = 0; UInt32 height = 0; UInt32 pitch = 0; foreach (var track in media.Tracks) { if (track.TrackType != TrackType.Video) continue; width = track.Data.Video.Width; height = track.Data.Video.Height; //TODO: align to 4 bytes pitch = width * 4; originalWidth = (int)width; originalHeight = (int)height; originalStride = (int)pitch; bsg.Init(originalWidth, originalHeight); memory = Marshal.AllocHGlobal((int)(height * pitch)); } mediaPlayer.SetVideoFormat("RV32", width, height, pitch); mediaPlayer.SetVideoCallbacks(LockCB, UnlockCb, DisplayCb); //mediaPlayer.EnableHardwareDecoding = true; mediaPlayer.PositionChanged += OnPositionChanged; mediaPlayer.SeekableChanged += OnSeekableChanged; mediaPlayer.EndReached += OnEndReached; mediaPlayer.Pause(); mediaPlayer.Position = -0.05f; Trace.WriteLine("Opened: " + filename); //Thread.Sleep(1000); return true; } private void OnEndReached(object sender, EventArgs e) { Trace.WriteLine("OnEndReached"); ThreadPool.QueueUserWorkItem(_ => { mediaPlayer.Stop(); var ret = mediaPlayer.Play(); }); } public void PauseAt(float perc) { //Trace.WriteLine("Set new pos = " + perc.ToString()); mediaPlayer.Position = perc; mediaPlayer.Play(); mediaPlayer.SetPause(true); //Thread.Sleep(10); } private void OnSeekableChanged(object sender, MediaPlayerSeekableChangedEventArgs e) { Trace.WriteLine("OnSeekableChanged:" + e.Seekable.ToString()); } private void OnPositionChanged(object sender, MediaPlayerPositionChangedEventArgs e) { //Trace.WriteLine("New pos:" + e.Position.ToString()); } public bool Play() { if (media == null) return false; mediaPlayer.SetRate(1.0f); if (!mediaPlayer.Play(media)) return false; mediaPlayer.Position = 0.5f; Trace.WriteLine("Play triggered"); return true; } public IntPtr LockCB(IntPtr opaque, IntPtr planes) { //Trace.Write("L"); Marshal.WriteIntPtr(planes, memory); return IntPtr.Zero; } public void UnlockCb(IntPtr opaque, IntPtr picture, IntPtr planes) { //Trace.Write("U"); } public void DisplayCb(IntPtr opaque, IntPtr picture) { //Trace.Write("D"); byte* pMem = (byte*)memory.ToPointer(); for (int y = 0; y < bsg.Height; y++) { int fromY = originalHeight * y / bsg.Height; for (int x = 0; x < bsg.Width; x++) { int fromX = originalWidth * x / bsg.Width; int originalOffset = fromY * originalStride + 4 * fromX; int offset = y * bsg.RawStride + 4 * x; bsg.RawImage[offset + 0] = pMem[originalOffset + 0]; bsg.RawImage[offset + 1] = pMem[originalOffset + 1]; bsg.RawImage[offset + 2] = pMem[originalOffset + 2]; bsg.RawImage[offset + 3] = pMem[originalOffset + 3]; } } //currenBitmap = bsg.RenderBitmapSource(); } Media media; MediaPlayer mediaPlayer; IntPtr memory; int originalWidth = 0; int originalHeight = 0; int originalStride = 0; BitmapSourceGenerator bsg = new BitmapSourceGenerator(); //BitmapSource currenBitmap; }
I'm using LibVLCSharp 3.4.5.0 and LibVLC 3.0.10.

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: VLC Pause freeze

Postby mfkl » 01 Jun 2020 12:29

Hi,

Please share full code in a git repo. Also some options might help for your use case here https://wiki.videolan.org/VLC_command-line_help
https://mfkl.github.io

mystery123sk
New Cone
New Cone
Posts: 8
Joined: 30 May 2020 07:47

Re: VLC Pause freeze

Postby mystery123sk » 01 Jun 2020 14:02

I made a repository, where you can use the scrollbar - after you drag the scrollbar for a few seconds, the preview seek will stop (video will generate the same picture all the time).

https://github.com/mystery123sk/VLCRenderToBitmap

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: VLC Pause freeze

Postby mfkl » 01 Jun 2020 17:57

Can you share your logs please?
https://mfkl.github.io

mystery123sk
New Cone
New Cone
Posts: 8
Joined: 30 May 2020 07:47

Re: VLC Pause freeze

Postby mystery123sk » 02 Jun 2020 08:43

I've added it here: https://github.com/mystery123sk/VLCRenderToBitmap/tree/master/PauseFreezeLog

I've played with the scrollbar for about 10 seconds and then it freezes.

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: VLC Pause freeze

Postby mfkl » 03 Jun 2020 10:07

logs mention --input-fast-seek so maybe try that but I doubt that's it.

Try having a look at existing code that uses this API to help troubleshooting your code, like https://code.videolan.org/mfkl/libvlcsharp-samples/-/blob/master/PreviewThumbnailExtractor.Skia/Program.cs or Vlc.DotNet WPF control.
https://mfkl.github.io

mystery123sk
New Cone
New Cone
Posts: 8
Joined: 30 May 2020 07:47

Re: VLC Pause freeze

Postby mystery123sk » 03 Jun 2020 11:30

The existing code won't help me much, since it extracts the images from start of the file to the end. The problem appears when randomly seeking the file. It looks like I should wait for something once I seek the file to random position - because when I try the seek the file in VLC player, it seeks a lot slower than my application (let's vlclib breath for a moment after seek?).

It's a really pity the documentation and examples for vlclib are few levels below poor. It's a great lib, but to get real help is almost impossible.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 21 guests