Trouble Retrieving Real-Time Input Bitrate from RTSP Streams in WinForms App Using Vlc.DotNet Player

29 Views Asked by At

I'm currently working on a WinForms application that plays multiple RTSP streams from IP cameras, with one stream per camera. I'm utilizing the Vlc.DotNet player to display these streams. While the application is functioning as intended, I've encountered an issue when attempting to retrieve the input bitrate or incoming data from the statistics – it consistently returns 0.

When I run the VLC application using a network stream for the same source and navigate to: Tools > Media Information > Statistics > Input/Read I do see the values I'm seeking.

Here is my InitVlcComponent method:

        private void InitVlcComponent()
        {
            vlcControl = new VlcControl();
            vlcControl.BeginInit();
            var dir = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
            vlcControl.VlcLibDirectory = dir;
            vlcControl.VlcMediaplayerOptions = new[] { "-vv", "--network-caching=500", "--sout-transcode-vb=<integer>" };

            vlcControl.EndInit();

            vlcPanel.Controls.Add(vlcControl);
            vlcControl.Dock = DockStyle.Fill;

            vlcControl.Play(GetCameraUriFromSettings());
        }

To retrieve the bitrate, I've implemented the following:

private async Task UpdateLabelsAsync(object sender, EventArgs e)
{
    if (vlcControl == null) return;

    if (vlcControl.IsPlaying)
    {
        var media = vlcControl.VlcMediaPlayer.Media;
        if (media != null)
        {
            var inputBitrate = media.Statistics.InputBitrate;
            this.Invoke((MethodInvoker)delegate {
                bitrateLabel.Text = inputBitrate + "";
            });
        }
    }
}

I have also set up a timer to periodically call the UpdateLabelsAsync method.

If you have any insights into what might be causing the bitrate to consistently return 0 or suggestions for an alternative method to play the streams, I would greatly appreciate your input.

Thank you in advance!

0

There are 0 best solutions below