'I', 'Y', 'U', 'V' exception

asked 2016-09-09 01:52:36 -0500

Mikl gravatar image

updated 2016-09-09 01:57:11 -0500

Hello, I am recording video using IYUV codec. It is present in my system, because i can see it when using -1 for FOURCC

image description

But first time i want to record frame i have an exception

image description

This is happening only at first frame and only when i run it in Visual Studio (2015). If i press "Continue" everything is going well. After this recording is going without any problems. If i run application outside of Visual Studio nothing visible is happening.

I don`t think, what it is normal behavior. Can you help me please, what i am doing wrong and how to fix it.

I am using binaries, compiled myself in VS2015 from opencv-3.1.0 source. Maybe i need to configure "cmake" or VS project in special way?

source code

unsigned char* frame;//rgb raw data
int width = 800;
int height= 400;

Size frameSize(width, height);
VideoWriter recorder(name.toStdString(), CV_FOURCC('I', 'Y', 'U', 'V'), 20, frameSize, true);
Mat _frame(frameSize, CV_8UC3);

_frame.data = frame;
_recorder.write(_frame); <-line of exception

_recorder.release();

UPDATE

The same is happening during playback, using VideoCapture

edit retag flag offensive close merge delete

Comments

1

That is probably because the first frame is grabbed somehow and is not correct yet. Simply said, most software solves this by skipping the first few frames then start to record.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-09 05:58:31 -0500 )edit

@StevenPuttemans Frame is correct. So, you advice is "ignore it"?

Mikl gravatar imageMikl ( 2016-09-09 09:04:55 -0500 )edit

I'm agree StevenPuttemans. After this please read your prev post http://answers.opencv.org/question/10...

  • this is NOT safe _frame.data = frame;
  • this is correct Mat _frame(frameSize,CV_8UC3,(void*)frame); //build a Mat over user allocated data

Finally use Mat over user allocated data with care if producer process can change the memory while any OpenCV process is changing too or it's doing any stuff

pklab gravatar imagepklab ( 2016-09-09 11:07:21 -0500 )edit

@pklab The reason i started this question, you was not able to help me in my previous one.It is simplified version. Only one question.But i see you doing the same. I am asking about shape, you answering about color. :) I have exception on first frame because of "this is NOT safe@"? And i do not agree with StevenPuttemans. I was expected to have answer "ignore it" from JavaScript programmer, but not from c++. Sorry.

Mikl gravatar imageMikl ( 2016-09-12 01:46:30 -0500 )edit
1

@Mikl I did not say you need to ignore it. But it is a fact that hardware producers tend to place in the manual that the first 1-3 frames are actually initialisation frames, and can thus contain rubbish. That is why people tend to throw away the first few frames in a robust setup ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-12 03:50:44 -0500 )edit

@StevenPuttemans You mean throw away because of content, but not wrong data format? It this case you are right. Sorry for misunderstanding. It can be garbage on a screen on first frames. Not really worries me now. I need to start recording at least something first.

Mikl gravatar imageMikl ( 2016-09-12 05:16:03 -0500 )edit