Page 1 of 1

IPCam with Unity integration image stutter

PostPosted: Mon Jul 15, 2019 8:09 am
by fxmdev
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

Re: IPCam with Unity integration image stutter

PostPosted: Mon Jul 15, 2019 12:33 pm
by andrew.kirillov
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.

Re: IPCam with Unity integration image stutter

PostPosted: Tue Jul 16, 2019 9:30 am
by fxmdev
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

Re: IPCam with Unity integration image stutter

PostPosted: Tue Jul 16, 2019 9:00 pm
by andrew.kirillov
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.

Re: IPCam with Unity integration image stutter

PostPosted: Thu Jul 18, 2019 3:57 am
by fxmdev
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