From 114579c33bd6a11f4870d78bd6dc8922ec93a5fe Mon Sep 17 00:00:00 2001 From: Bo Hu Date: Thu, 24 Oct 2013 12:35:33 -0700 Subject: [PATCH 1/2] Added proper testing of the end of quicktime video files. CvCaptureFile::grabFrame() always returns 1 regardless, which causes dead loop when relying on the return value of VideoCapture::read(). --- modules/highgui/src/cap_qtkit.mm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/highgui/src/cap_qtkit.mm b/modules/highgui/src/cap_qtkit.mm index ef7b42aa4..2867c7230 100644 --- a/modules/highgui/src/cap_qtkit.mm +++ b/modules/highgui/src/cap_qtkit.mm @@ -179,6 +179,7 @@ private: int changedPos; int started; + QTTime endOfMovie; }; @@ -673,6 +674,8 @@ CvCaptureFile::CvCaptureFile(const char* filename) { return; } + [mCaptureSession gotoEnd]; + endOfMovie = [mCaptureSession currentTime]; [mCaptureSession gotoBeginning]; @@ -709,6 +712,11 @@ int CvCaptureFile::didStart() { bool CvCaptureFile::grabFrame() { NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init]; double t1 = getProperty(CV_CAP_PROP_POS_MSEC); + + QTTime curTime; + curTime = [mCaptureSession currentTime]; + bool isEnd=(QTTimeCompare(curTime,endOfMovie) == NSOrderedSame); + [mCaptureSession stepForward]; double t2 = getProperty(CV_CAP_PROP_POS_MSEC); if (t2>t1 && !changedPos) { @@ -718,7 +726,7 @@ bool CvCaptureFile::grabFrame() { } changedPos = 0; [localpool drain]; - return 1; + return !isEnd; } From c88fa27b1d1d71ad8b4b8c0a5630e1577f6c968d Mon Sep 17 00:00:00 2001 From: Bo Hu Date: Tue, 29 Oct 2013 10:35:41 -0700 Subject: [PATCH 2/2] Removed trailing whitespace in cap_qtkit.mm. --- modules/highgui/src/cap_qtkit.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/cap_qtkit.mm b/modules/highgui/src/cap_qtkit.mm index 2867c7230..6b915977f 100644 --- a/modules/highgui/src/cap_qtkit.mm +++ b/modules/highgui/src/cap_qtkit.mm @@ -674,7 +674,7 @@ CvCaptureFile::CvCaptureFile(const char* filename) { return; } - [mCaptureSession gotoEnd]; + [mCaptureSession gotoEnd]; endOfMovie = [mCaptureSession currentTime]; [mCaptureSession gotoBeginning]; @@ -712,7 +712,7 @@ int CvCaptureFile::didStart() { bool CvCaptureFile::grabFrame() { NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init]; double t1 = getProperty(CV_CAP_PROP_POS_MSEC); - + QTTime curTime; curTime = [mCaptureSession currentTime]; bool isEnd=(QTTimeCompare(curTime,endOfMovie) == NSOrderedSame);