accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET

Home Page:http://accord-framework.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using Accord.Video.FFMPEG to receive RTSP stream

miker1423 opened this issue · comments

  • question
  • bug report
  • feature request

Issue description
I'm trying to use the Accord.Video.FFMPEG to receive video from a RTSP source, with the VideoFileSource class, but when I try to replace the image from a picturebox in winforms with every frame that I receive in the NewFram event, it throws an ArgumentException. The code is the following:

    public partial class Form1 : Form
    {
        private VideoFileSource source;

        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            source = new VideoFileSource(urlBox.Text);
            source.NewFrame += Source_NewFrame;
            source.Start();
        }

        private void Source_NewFrame(object sender, Accord.Video.NewFrameEventArgs eventArgs)
        {
            ChangeFrame(eventArgs.Frame);
        }

        private void ChangeFrame(Bitmap bitmap) 
        {
            if (imageBox.InvokeRequired)
            {
                imageBox.BeginInvoke(new InvokeDelegate(ChangeFrame), bitmap);
                return;
            }

            try
            {
                imageBox.Image = bitmap; 
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        private delegate void InvokeDelegate(Bitmap image);
    }