AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

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

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

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

Postby Kamilk1991 » Sat May 18, 2019 5:43 pm

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.
Last edited by Kamilk1991 on Mon May 20, 2019 9:31 pm, edited 1 time in total.
Kamilk1991
 
Posts: 4
Joined: Sat May 18, 2019 5:41 pm

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

Postby andrew.kirillov » Mon May 20, 2019 7:34 am

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.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

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

Postby Kamilk1991 » Mon May 20, 2019 8:44 am

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
Kamilk1991
 
Posts: 4
Joined: Sat May 18, 2019 5:41 pm

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

Postby andrew.kirillov » Mon May 20, 2019 10:02 am

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.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

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

Postby Kamilk1991 » Mon May 20, 2019 6:23 pm

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
Kamilk1991
 
Posts: 4
Joined: Sat May 18, 2019 5:41 pm

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

Postby Kamilk1991 » Mon May 20, 2019 7:08 pm

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!
Kamilk1991
 
Posts: 4
Joined: Sat May 18, 2019 5:41 pm




Return to AForge.NET Framework