From 677680d82d7646ab97f1bfacfcab8dceeb54fa69 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 1 Jun 2012 08:55:16 +0000 Subject: [PATCH] reverted the original VideoCapture::read() code; moved frame index check to where it should belong: ffmpeg wrapper; applied patch by Rob Reilink (ticket #1971) --- modules/highgui/src/cap.cpp | 11 ++--------- modules/highgui/src/cap_ffmpeg_impl.hpp | 4 ++++ modules/highgui/src/cap_qtkit.mm | 4 +++- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index 6c2cd9a..8dc25f3 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -494,15 +494,8 @@ bool VideoCapture::retrieve(Mat& image, int channel) bool VideoCapture::read(Mat& image) { - double frame_pos = get(CV_CAP_PROP_POS_FRAMES); - double frame_count = get(CV_CAP_PROP_FRAME_COUNT); - if (frame_pos < frame_count || frame_pos < 0 || frame_count < 0) - { - if(grab()) - retrieve(image); - else - image.release(); - } + if(grab()) + retrieve(image); else image.release(); return !image.empty(); diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index f7bf25d..025cb89 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -438,6 +438,10 @@ bool CvCapture_FFMPEG::grabFrame() const int max_number_of_attempts = 1 << 16; if( !ic || !video_st ) return false; + + if( ic->streams[video_stream]->nb_frames > 0 && + frame_number > ic->streams[video_stream]->nb_frames ) + return false; av_free_packet (&packet); diff --git a/modules/highgui/src/cap_qtkit.mm b/modules/highgui/src/cap_qtkit.mm index 6efe4bd..ff5d408 100644 --- a/modules/highgui/src/cap_qtkit.mm +++ b/modules/highgui/src/cap_qtkit.mm @@ -316,7 +316,9 @@ int CvCaptureCAM::startCaptureDevice(int cameraNum) { capture = [[CaptureDelegate alloc] init]; QTCaptureDevice *device; - NSArray* devices = [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo]; + NSArray* devices = [[[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo] + arrayByAddingObjectsFromArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeMuxed]] retain]; + if ([devices count] == 0) { cout << "QTKit didn't find any attached Video Input Devices!" << endl; [localpool drain]; -- 2.7.4