videoio(macosx): fix array access exception in AVFoundation
authorAlexander Alekhin <alexander.alekhin@intel.com>
Sat, 24 Jun 2017 08:07:57 +0000 (11:07 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Sat, 24 Jun 2017 08:07:57 +0000 (11:07 +0300)
modules/videoio/src/cap_avfoundation_mac.mm

index 07aac1a..0ef461c 100644 (file)
@@ -694,7 +694,15 @@ CvCaptureFile::CvCaptureFile(const char* filename) {
         return;
     }
 
-    mAssetTrack = [[mAsset tracksWithMediaType: AVMediaTypeVideo][0] retain];
+    NSArray *tracks = [mAsset tracksWithMediaType:AVMediaTypeVideo];
+    if ([tracks count] == 0) {
+        fprintf(stderr, "OpenCV: Couldn't read video stream from file \"%s\"\n", filename);
+        [localpool drain];
+        started = 0;
+        return;
+    }
+
+    mAssetTrack = [tracks[0] retain];
 
     if ( ! setupReadingAt(kCMTimeZero) ) {
         fprintf(stderr, "OpenCV: Couldn't read movie file \"%s\"\n", filename);