MundoPeter
MundoPeter

Reputation: 734

Parsing libvlcsharp video loaded from stream not working

I want to play a video (mp4) with libvlcsharp using C# in WinForms.

I load the media using a Stream because the file will be encrypted and I will then manage to decrypt it before loading it in the media object.

I succeeded loading and playing the video, but I am failing to Parse it.

I want to Parse it in order to be able to get information such as Duration, AudioChannels, FrameRate, Width, etc. before playing it.

I call Parse (tried with every combination of options), the IsParsed property changes to True but the ParsedStatus is not Done but Skipped.

If I load the file directly (without using a srtream) it parses ok.

My code:

Stream contentStream = System.IO.File.Open("c:\test\test.mp4" , System.IO.FileMode.Open);
                                                                
Media Video = new Media(utils.GetLibVLC(), new StreamMediaInput(contentStream));

Video.Parse(MediaParseOptions.ParseLocal | MediaParseOptions.ParseNetwork);

while (!Video.IsParsed)  
    System.Threading.Thread.Sleep(50);
                        
if (Video.ParsedStatus == MediaParsedStatus.Done)   //Video.ParsedStatus equals to Skipped
{
    long Duration = Video.Duration;

    foreach (MediaTrack track in Video.Tracks)
    {
        switch (track.TrackType)
        {
            case TrackType.Audio:
                int AudioChannels = (int)track.Data.Audio.Channels;
                int AudioRate = (int)track.Data.Audio.Rate;
                break;
            case TrackType.Video:
                float FrameRate = track.Data.Video.FrameRateNum / track.Data.Video.FrameRateDen;
                int Width = (int)track.Data.Video.Width;
                int Height = (int)track.Data.Video.Height;
                float Ratio = (float)Width / Height;
                break;
        }
    }                            
}

(I know the while is dangerous I will improve it later).

Does anybody know how to parse a video loaded through a stream?

Upvotes: 1

Views: 1741

Answers (2)

Eric
Eric

Reputation: 1

did you try this ?

var parseStatusTask = Task.Run(async () => await Video.Parse(MediaParseOptions.ParseNetwork));
parseStatusTask.Wait();

Upvotes: 0

cube45
cube45

Reputation: 3979

My explanation would be that it is not supported.

I've seen this line of code : https://code.videolan.org/videolan/vlc/-/blob/a4ca0de9e087e6a6a3bb86c585cf29ad5c553576/src/preparser/preparser.c#L362 , which seems to mean that the parsing is skipped if it's not a network nor a file.

You could raise the issue on videolan's bugtracker if you want this feature.

Upvotes: 2

Related Questions