Page 1 of 1

[SOLVED] AForge.NET cant connect to my MJPEG stream on RBPi

PostPosted: Sat May 18, 2019 5:43 pm
by Kamilk1991
Hello!

i described my problem on stackoverflow i just paste it.

I have stream in mjpeg urled http://192.*.*.1:8000/stream.mjpg Im trying to receive it with C# App with Aforge.Video namespace.
```
Code: Select all
internal class CameraManager
    {
        private MJPEGStream stream = new MJPEGStream("http://192.*.*.1:8000/stream.mjpg");

        public CameraManager()
        {
            stream.NewFrame += new NewFrameEventHandler(video_NewFrame);
            stream.Start();
            while (true)
            {
                Console.WriteLine(stream.BytesReceived);
            }
        }

        private void video_NewFrame(object sender,
            NewFrameEventArgs eventArgs)
        {
            // get new frame
            Bitmap bitmap = eventArgs.Frame;

            Console.WriteLine(stream.IsRunning);
            Console.WriteLine(bitmap.Height);
            // process the frame
        }

    }

```
I try to receive data, and in future detect faces, motion etc. Now im only receiving "0 bytes".

I used tutorial From http://www.aforgenet.com/framework/features/jpeg_video_streams.html but i can see, that in sample it is "http://<axis_camera_ip>/axis-cgi/jpg/image.cgi". I can see my camera streaming in url http://192.*.*.1:8000/stream.mjpg very clear. I see that my stream has format mjpg in sample .cgi

What should i do to receive pics/bytes from this .mjpg stream and then manage it?

I had errors like:

Code: Select all
The operation has timed out.
The operation was canceled.


And somethink like "This stream not allow timeout"

Im using simply python app to streaming:

https://picamera.readthedocs.io/en/latest/recipes2.html#web-streaming


Edit:

I started receiving errors when added Error Event to my program, its not visible in this sample.

Re: AForge.NET can't connect to my MJPEG stream on RB3.14

PostPosted: Mon May 20, 2019 7:34 am
by andrew.kirillov
Hello,

It may happen that your camera/streamer provides MJPEG stream in slightly different format and so MJPEGStream fails to parse it. I had a chance to work with different IP cameras and some of them bring something of their own to the MJPEG format. I would suggest checking what the streamer sends (just write raw data to some file and see what is there) and debugging with source code of MJPEGStream.

Re: AForge.NET can't connect to my MJPEG stream on RB3.14

PostPosted: Mon May 20, 2019 8:44 am
by Kamilk1991
andrew.kirillov wrote:It may happen that your camera/streamer provides MJPEG stream in slightly different format and so MJPEGStream fails to parse it. I had a chance to work with different IP cameras and some of them bring something of their own to the MJPEG format. I would suggest checking what the streamer sends (just write raw data to some file and see what is there) and debugging with source code of MJPEGStream.


Im using Raspberry Pi Camera. It is not classic ip camera. I have to use it as device connected directly to Raspberry Pi. Stream with code: https://pastebin.com/DZ8vYLHh

Re: AForge.NET can't connect to my MJPEG stream on RB3.14

PostPosted: Mon May 20, 2019 10:02 am
by andrew.kirillov
Well, in this case I think you may need to check what that magic streamer does and if it really provides MJPEG stream. I used cam2web to stream RaspberryPI camera as MJPEG stream - worked well form me.

Re: AForge.NET can't connect to my MJPEG stream on RB3.14

PostPosted: Mon May 20, 2019 6:23 pm
by Kamilk1991
andrew.kirillov wrote:Well, in this case I think you may need to check what that magic streamer does and if it really provides MJPEG stream. I used cam2web to stream RaspberryPI camera as MJPEG stream - worked well form me.


I used Web2Cam from url you gave me.

Code: Select all
        public CameraManager()
        {
            stream.Source = "http://192.168.1.37:8000/camera/mjpeg";
    //        stream.RequestTimeout = 10;
   
            stream.NewFrame += new NewFrameEventHandler(video_NewFrame);
            stream.VideoSourceError += new VideoSourceErrorEventHandler(VideoStream_VideoSourceError);
            stream.Start();


         
         
        }

        public void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap img = (Bitmap)eventArgs.Frame.Clone();
         
        }

        private void VideoStream_VideoSourceError(object sender, AForge.Video.VideoSourceErrorEventArgs eventArgs)
        {
            Console.WriteLine(eventArgs.Description);
        }

And it gives me:
Code: Select all
The operation has timed out.                                                                                            The operation was canceled.                                                                                             The operation has timed out.                                                                                            Timeouts are not supported on this stream.                                                                              The operation has timed out.                                                                                            The operation has timed out.                                                                                            Timeouts are not supported on this stream.                                                                              The operation has timed out.                                                                                            Timeouts are not supported on this stream.


So, could it be problem with Camera? I made this app on .net Core Console App, tried to use FW Console App, but int not supporting System.Drawing.Imaging.


F******k it was a problem. Is AForge.NET not supporting .net Core? :-) Now im receiving frames. I will let you know if all frames are correct, because now im only see that event works good. If it was problem im a freaking noob. :D

Re: AForge.NET can't connect to my MJPEG stream on RB3.14

PostPosted: Mon May 20, 2019 7:08 pm
by Kamilk1991
Image
So problem is solved. I was using a .net CORE Console App instead of .net Framework Console App. As proof you can see very bad quality image of my window.
Thank you for your help!