AForge.NET

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

IPCam with Unity integration image stutter

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

IPCam with Unity integration image stutter

Postby fxmdev » Mon Jul 15, 2019 8:09 am

I have a question about Aforge for IPCam (remote). I don't know if this the right place to ask of this, sorry if I'm in wrong place

First off, I already can integrate it with unity (2019.1.7), the problem is the image stream is stuttering like what you can see from the video attachment.

https://i.stack.imgur.com/FNI2j.gif

Here's the script I'm using to get the stream

Code: Select all
private void OnEnable()
{
     transform.eulerAngles = initRot;
     if (mjpegStream != null)
         mjpegStream.Start();
}
// Use this for initialization
void Start () {
     camTexture = new Texture2D(2 , 2);
     // create MJPEG video source
     mjpegStream = new MJPEGStream(camIPAddress);

     // set event handlers
     mjpegStream.NewFrame += new NewFrameEventHandler(StreamImage);
     // start the video source
     mjpegStream.Start();
}
// Update is called once per frame
void Update()
{
     if (dataGet)
     {
         camTexture.LoadImage(jpegstream.ToArray());
             if(screenDisplay.texture != camTexture)
                 screenDisplay.texture = camTexture;
             counter = 0;
             dataGet = false;
     }
}
void StreamImage(object sender, NewFrameEventArgs eventArgs)
{
     jpegstream = eventArgs.Frame;
     dataGet = true;
}


I only change the bitmap to memory stream in the MJPEGStream and give a param dataGet for workaround for the thread

The question is, does anyone know how to make the image to not stutter?

Is it a problem from the stream I'm getting? It works fine if I access normally from web browser
Please note that this happen with different ipcam I got from online too
fxmdev
 
Posts: 3
Joined: Mon Jul 15, 2019 7:29 am

Re: IPCam with Unity integration image stutter

Postby andrew.kirillov » Mon Jul 15, 2019 12:33 pm

Before going into Unity, did you try making it work in a normal WinForm application? You can quickly test it with provided sample application. If it does work in WinForm app, then you may need to look for some Unity related issue.
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: IPCam with Unity integration image stutter

Postby fxmdev » Tue Jul 16, 2019 9:30 am

WinForm mean start from the visual studio?
got error about systemtools not found when open the mono from visual studio (inside the AsyncVideoSource)
For unity I just take the cs without the AsyncVideoSource.cs
fxmdev
 
Posts: 3
Joined: Mon Jul 15, 2019 7:29 am

Re: IPCam with Unity integration image stutter

Postby andrew.kirillov » Tue Jul 16, 2019 9:00 pm

Well, if you don't know how to do WinForm application, try using one of the provided sample applications. There is one for playing JPEG/MJPEG streams.
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: IPCam with Unity integration image stutter

Postby fxmdev » Thu Jul 18, 2019 3:57 am

So, I already test the app. and it work fine with a small delay (2s and sometimes the timestamp become 1 to 2s faster than the web video)
Thank for the help, will try checking the unity side
fxmdev
 
Posts: 3
Joined: Mon Jul 15, 2019 7:29 am




Return to AForge.NET Framework