devkanro / Meta.Vlc

Meta.Vlc is a LibVlc wrapper for WPF.
Do What The F*ck You Want To Public License
275 stars 85 forks source link

VlcPlayer.FPS and VlcPlayer.Time returns 0 - On URI media (remote sources/streaming) #130

Closed jerotire closed 8 years ago

jerotire commented 8 years ago

The VlcPlayer.FPS object property is always 0 (Zero). Even when media is playing. Also tried accessing from VlcPlayer.VlcMediaPlayer.Fps, same result. Same applies to VlcPlayer.Time.

Using a local AVI file, the properties VlcPlayer.FPS and VlcPlayer.Time work fine:

MediaPlayer.LoadMedia("C:\\rassegna2.avi");
MediaPlayer.Play();

Using a remote source, then the properties VlcPlayer.FPS and VlcPlayer.Time return 0.

MediaPlayer.LoadMedia(new Uri("http://video49.lhr02.hls.ttvnw.net/hls110/nomanis_21607304544_462002911/chunked/index-live.m3u8?token=id=9002030069541420964,bid=21607304544,exp=1464777219,node=video49-1.lhr02.hls.justin.tv,nname=video49.lhr02,fmt=chunked&sig=7fe080ed616165de16167ef6bfb2b292f97f5e80"));
MediaPlayer.Play();

Below is the context I am attempting to use it in:

Streaming (remote) media from TwitchTV and Youtube.

private void MediaPlayer_PositionChanged(object sender, EventArgs e)
{
    // Do not attempt anything if disposing
    if (!isDisposing)
    {
        if (MediaPlayer.State == Meta.Vlc.Interop.Media.MediaState.Playing)
        {
            // Ensure we have a source before querying stats..
            if (MediaPlayer.VideoSource != null)
            {
               lblTime.Dispatcher.Invoke(new Action(() => lblTime.Content = String.Format("{0}", MediaPlayer.Time)));
               lblFPSCounter.Dispatcher.Invoke(new Action(() => lblFPSCounter.Content = String.Format("{0}", MediaPlayer.FPS)));
               lblResolution.Dispatcher.Invoke(new Action(() => lblResolution.Content = String.Format("{0} x {1}", MediaPlayer.VideoSource.PixelWidth, MediaPlayer.VideoSource.PixelHeight)));
            }

            // Video controls hide after mouse inactivity..
            if (swVideoControlTimer.IsRunning)
            {
                if (swVideoControlTimer.ElapsedMilliseconds > 2000)
                {
                    swVideoControlTimer.Stop();
                    swVideoControlTimer.Reset();
                    VideoControls.Visibility = Visibility.Hidden;
                }
            }
        }
        else
        {
            // Nothing playing.. Set label to "-"
            lblFPSCounter.Dispatcher.Invoke(new Action(() => lblFPSCounter.Content = "-"));
            lblResolution.Dispatcher.Invoke(new Action(() => lblResolution.Content = "-"));
        }
    }
}

Also, is it possible to get the number of Dropped Frames or Total Frames?

devkanro commented 8 years ago

No idea with it, if you use VLC to watch it, the time and FPS may be 0 too....

jerotire commented 8 years ago

Hey thanks for the response.

I can confirm that is NOT the case when using VLC Media Player (except for the Time - I can solve that with a Stopwatch instance or something client side). I can confirm that it works using Vlc.DotNet.

Here is a screenshot demonstrating information available (which I wish I could access too): untitled

If not already implemented, could you implement some if this data shown in the screenshots? For instance, a Codec property and Statistics property?

devkanro commented 8 years ago

Ummm, yes, you can get those information with VlcPlayer.VlcMediaPlayer.Media.GetTracks(); the FrameRateNum and FrameRateDen property, you can get FPS with FrameRateNum/FrameRateDen.

jerotire commented 8 years ago

Thanks for your response.

I am still getting 0 for FrameRateNum and FrameRateDen for remote sources.

This is what I have so far:

foreach(Meta.Vlc.MediaTrack track in MediaPlayer.VlcMediaPlayer.Media.GetTracks())
{
    if (track is Meta.Vlc.VideoTrack)
    {
        Meta.Vlc.VideoTrack t = (Meta.Vlc.VideoTrack)track;
        Console.WriteLine( "{0} {1} {2}", t.FrameRateNum, t.FrameRateDen, t.Id);
    }
}

outputs (URI/Stream):

0 0 1
0 0 1
0 0 1
0 0 1
...

output (Local AVI):

25 1 0
25 1 0
25 1 0
25 1 0
...
devkanro commented 8 years ago

Ummm, maybe it is a issue of LibVlc, you can ask developer of VLC in Development around libVLC

jerotire commented 8 years ago

After many conversations, it turns out that it was something up with libvlc. I downloaded the latest SOURCE version of VLC Media Player and just extracted the DLLs and plugins folder. Issue is resolved.

For those who have a similar issue, latest sources can be downloaded here: ftp://ftp.videolan.org/pub/videolan/vlc/

And just take the files mentioned below and use them in your libvlc folder in your project:

./axvlc.dll
./libvlc.dll
./libvlccore.dll
./npvlc.dll
./plugins