AVFoundation on Mac: fixed frame count and unsupported format handling

pull/13685/head
Maksim Shabunin 6 years ago
parent dcdbaef348
commit 9c4eb20221
  1. 18
      modules/videoio/src/cap_avfoundation_mac.mm
  2. 29
      modules/videoio/test/test_video_io.cpp

@ -793,9 +793,7 @@ bool CvCaptureFile::setupReadingAt(CMTime position) {
mFrameTimestamp = position; mFrameTimestamp = position;
mFrameNum = round((mFrameTimestamp.value * mAssetTrack.nominalFrameRate) / double(mFrameTimestamp.timescale)); mFrameNum = round((mFrameTimestamp.value * mAssetTrack.nominalFrameRate) / double(mFrameTimestamp.timescale));
[mAssetReader addOutput: mTrackOutput]; [mAssetReader addOutput: mTrackOutput];
[mAssetReader startReading]; return [mAssetReader startReading];
return true;
} }
int CvCaptureFile::didStart() { int CvCaptureFile::didStart() {
@ -1013,7 +1011,7 @@ double CvCaptureFile::getProperty(int property_id) const{
case CV_CAP_PROP_POS_MSEC: case CV_CAP_PROP_POS_MSEC:
return mFrameTimestamp.value * 1000.0 / mFrameTimestamp.timescale; return mFrameTimestamp.value * 1000.0 / mFrameTimestamp.timescale;
case CV_CAP_PROP_POS_FRAMES: case CV_CAP_PROP_POS_FRAMES:
return mFrameNum; return mAssetTrack.nominalFrameRate > 0 ? mFrameNum : 0;
case CV_CAP_PROP_POS_AVI_RATIO: case CV_CAP_PROP_POS_AVI_RATIO:
t = [mAsset duration]; t = [mAsset duration];
return (mFrameTimestamp.value * t.timescale) / double(mFrameTimestamp.timescale * t.value); return (mFrameTimestamp.value * t.timescale) / double(mFrameTimestamp.timescale * t.value);
@ -1049,18 +1047,15 @@ bool CvCaptureFile::setProperty(int property_id, double value) {
case CV_CAP_PROP_POS_MSEC: case CV_CAP_PROP_POS_MSEC:
t = mAsset.duration; t = mAsset.duration;
t.value = value * t.timescale / 1000; t.value = value * t.timescale / 1000;
setupReadingAt(t); retval = setupReadingAt(t);
retval = true;
break; break;
case CV_CAP_PROP_POS_FRAMES: case CV_CAP_PROP_POS_FRAMES:
setupReadingAt(CMTimeMake(value, mAssetTrack.nominalFrameRate)); retval = mAssetTrack.nominalFrameRate > 0 ? setupReadingAt(CMTimeMake(value, mAssetTrack.nominalFrameRate)) : false;
retval = true;
break; break;
case CV_CAP_PROP_POS_AVI_RATIO: case CV_CAP_PROP_POS_AVI_RATIO:
t = mAsset.duration; t = mAsset.duration;
t.value = round(t.value * value); t.value = round(t.value * value);
setupReadingAt(t); retval = setupReadingAt(t);
retval = true;
break; break;
case CV_CAP_PROP_MODE: case CV_CAP_PROP_MODE:
int mode; int mode;
@ -1074,8 +1069,7 @@ bool CvCaptureFile::setProperty(int property_id, double value) {
case CV_CAP_MODE_GRAY: case CV_CAP_MODE_GRAY:
case CV_CAP_MODE_YUYV: case CV_CAP_MODE_YUYV:
mMode = mode; mMode = mode;
setupReadingAt(mFrameTimestamp); retval = setupReadingAt(mFrameTimestamp);
retval = true;
break; break;
default: default:
fprintf(stderr, "VIDEOIO ERROR: AVF Mac: Unsupported mode: %d\n", mode); fprintf(stderr, "VIDEOIO ERROR: AVF Mac: Unsupported mode: %d\n", mode);

@ -307,10 +307,9 @@ static const VideoCaptureAPIs backend_params[] = {
CAP_QT, CAP_QT,
#endif #endif
// TODO: Broken? #ifdef HAVE_AVFOUNDATION
//#ifdef HAVE_AVFOUNDATION CAP_AVFOUNDATION,
// CAP_AVFOUNDATION, #endif
//#endif
#ifdef HAVE_MSMF #ifdef HAVE_MSMF
CAP_MSMF, CAP_MSMF,
@ -413,18 +412,16 @@ static Ext_Fourcc_PSNR synthetic_params[] = {
makeParam("mkv", "MJPG", 30.f, CAP_QT), makeParam("mkv", "MJPG", 30.f, CAP_QT),
#endif #endif
// TODO: Broken? #ifdef HAVE_AVFOUNDATION
//#ifdef HAVE_AVFOUNDATION makeParam("mov", "H264", 30.f, CAP_AVFOUNDATION),
// makeParam("mov", "mp4v", 30.f, CAP_AVFOUNDATION), makeParam("mov", "MJPG", 30.f, CAP_AVFOUNDATION),
// makeParam("avi", "XVID", 30.f, CAP_AVFOUNDATION), makeParam("mp4", "H264", 30.f, CAP_AVFOUNDATION),
// makeParam("avi", "MPEG", 30.f, CAP_AVFOUNDATION), makeParam("mp4", "MJPG", 30.f, CAP_AVFOUNDATION),
// makeParam("avi", "IYUV", 30.f, CAP_AVFOUNDATION), makeParam("m4v", "H264", 30.f, CAP_AVFOUNDATION),
// makeParam("avi", "MJPG", 30.f, CAP_AVFOUNDATION), makeParam("m4v", "MJPG", 30.f, CAP_AVFOUNDATION),
makeParam("3gp", "H264", 30.f, CAP_AVFOUNDATION),
// makeParam("mkv", "XVID", 30.f, CAP_AVFOUNDATION), makeParam("3gp", "MJPG", 30.f, CAP_AVFOUNDATION),
// makeParam("mkv", "MPEG", 30.f, CAP_AVFOUNDATION), #endif
// makeParam("mkv", "MJPG", 30.f, CAP_AVFOUNDATION),
//#endif
#ifdef HAVE_FFMPEG #ifdef HAVE_FFMPEG
makeParam("avi", "XVID", 30.f, CAP_FFMPEG), makeParam("avi", "XVID", 30.f, CAP_FFMPEG),

Loading…
Cancel
Save