accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.48k stars 1.99k forks source link

Using Accord.Video.FFMPEG to receive RTSP stream #2220

Open miker1423 opened 3 years ago

miker1423 commented 3 years ago

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);
    }