add VideoCapture / VideoWriter AVFoundation implementation for Mac

pull/7159/head
yoffy 9 years ago committed by Ryan Govostes
parent b3b434e221
commit 767780a4b2
  1. 13
      CMakeLists.txt
  2. 13
      cmake/OpenCVFindLibsVideo.cmake
  3. 3
      cmake/templates/cvconfig.h.in
  4. 4
      modules/videoio/CMakeLists.txt
  5. 57
      modules/videoio/include/opencv2/videoio.hpp
  6. 1
      modules/videoio/include/opencv2/videoio/videoio_c.h
  7. 16
      modules/videoio/src/cap.cpp
  8. 1170
      modules/videoio/src/cap_avfoundation_mac.mm
  9. 4
      modules/videoio/src/precomp.hpp

@ -169,7 +169,8 @@ OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" OFF)
# Optional 3rd party components
# ===================================================
OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O" ON IF IOS)
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS)" ON IF IOS)
OCV_OPTION(WITH_AVFOUNDATION_MAC "Use AVFoundation for Video I/O (Mac)" ON IF (NOT IOS AND APPLE) )
OCV_OPTION(WITH_CARBON "Use Carbon for UI instead of Cocoa" OFF IF APPLE )
OCV_OPTION(WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" ON IF (ARM OR AARCH64) AND NOT IOS AND NOT (CMAKE_VERSION VERSION_LESS "2.8.11"))
OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT CMAKE_CROSSCOMPILING) )
@ -1063,10 +1064,6 @@ if(DEFINED WITH_1394)
status(" DC1394 2.x:" HAVE_DC1394_2 THEN "YES (ver ${ALIASOF_libdc1394-2_VERSION})" ELSE NO)
endif(DEFINED WITH_1394)
if(DEFINED WITH_AVFOUNDATION)
status(" AVFoundation:" WITH_AVFOUNDATION THEN YES ELSE NO)
endif(DEFINED WITH_AVFOUNDATION)
if(DEFINED WITH_FFMPEG)
if(WIN32)
status(" FFMPEG:" WITH_FFMPEG THEN "YES (prebuilt binaries)" ELSE NO)
@ -1112,10 +1109,12 @@ if(DEFINED WITH_GIGEAPI)
status(" GigEVisionSDK:" HAVE_GIGE_API THEN YES ELSE NO)
endif(DEFINED WITH_GIGEAPI)
if(DEFINED WITH_QUICKTIME)
if(DEFINED APPLE)
status(" QuickTime:" HAVE_QUICKTIME THEN YES ELSE NO)
status(" QTKit:" HAVE_QTKIT THEN YES ELSE NO)
endif(DEFINED WITH_QUICKTIME)
status(" AVFoundation:" WITH_AVFOUNDATION THEN YES ELSE NO)
status(" AVFoundationMac:" WITH_AVFOUNDATION_MAC THEN YES ELSE NO)
endif(DEFINED APPLE)
if(DEFINED WITH_UNICAP)
status(" UniCap:" HAVE_UNICAP THEN "YES (ver ${ALIASOF_libunicap_VERSION})" ELSE NO)

@ -302,17 +302,24 @@ if(WIN32)
endif()
endif(WIN32)
# --- Apple AV Foundation ---
# --- Apple AV Foundation (iOS) ---
if(WITH_AVFOUNDATION)
set(HAVE_AVFOUNDATION YES)
endif()
# --- QuickTime ---
# --- Apple AV Foundation (Mac) ---
if(WITH_AVFOUNDATION_MAC)
set(HAVE_AVFOUNDATION_MAC YES)
endif()
# --- QuickTime, Apple AV Foundation (Mac) ---
if (NOT IOS)
if(WITH_QUICKTIME)
set(HAVE_QUICKTIME YES)
elseif(APPLE AND CMAKE_COMPILER_IS_CLANGCXX)
elseif(WITH_QTKIT)
set(HAVE_QTKIT YES)
elseif(APPLE AND CMAKE_COMPILER_IS_CLANGCXX)
set(HAVE_AVFOUNDATION_MAC YES)
endif()
endif()

@ -16,6 +16,9 @@
/* AVFoundation video libraries */
#cmakedefine HAVE_AVFOUNDATION
/* AVFoundation (Mac) video libraries */
#cmakedefine HAVE_AVFOUNDATION_MAC
/* V4L capturing support */
#cmakedefine HAVE_CAMV4L

@ -171,6 +171,10 @@ if(HAVE_AVFOUNDATION)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation.mm)
list(APPEND VIDEOIO_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
endif()
if(HAVE_AVFOUNDATION_MAC)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation_mac.mm)
list(APPEND VIDEOIO_LIBRARIES "-framework Cocoa" "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore")
endif()
if(HAVE_QUICKTIME)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_qt.cpp)

@ -82,34 +82,35 @@ To enable/disable APIs, you have to:
2. rebuild OpenCV itself
*/
enum VideoCaptureAPIs {
CAP_ANY = 0, //!< Auto detect
CAP_VFW = 200, //!< Video For Windows (platform native)
CAP_V4L = 200, //!< V4L/V4L2 capturing support via libv4l
CAP_V4L2 = CAP_V4L, //!< Same as CAP_V4L
CAP_FIREWIRE = 300, //!< IEEE 1394 drivers
CAP_FIREWARE = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_IEEE1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_DC1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_CMU1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_QT = 500, //!< QuickTime
CAP_UNICAP = 600, //!< Unicap drivers
CAP_DSHOW = 700, //!< DirectShow (via videoInput)
CAP_PVAPI = 800, //!< PvAPI, Prosilica GigE SDK
CAP_OPENNI = 900, //!< OpenNI (for Kinect)
CAP_OPENNI_ASUS = 910, //!< OpenNI (for Asus Xtion)
CAP_ANDROID = 1000, //!< Android - not used
CAP_XIAPI = 1100, //!< XIMEA Camera API
CAP_AVFOUNDATION = 1200, //!< AVFoundation framework for iOS (OS X Lion will have the same API)
CAP_GIGANETIX = 1300, //!< Smartek Giganetix GigEVisionSDK
CAP_MSMF = 1400, //!< Microsoft Media Foundation (via videoInput)
CAP_WINRT = 1410, //!< Microsoft Windows Runtime using Media Foundation
CAP_INTELPERC = 1500, //!< Intel Perceptual Computing SDK
CAP_OPENNI2 = 1600, //!< OpenNI2 (for Kinect)
CAP_OPENNI2_ASUS = 1610, //!< OpenNI2 (for Asus Xtion and Occipital Structure sensors)
CAP_GPHOTO2 = 1700, //!< gPhoto2 connection
CAP_GSTREAMER = 1800, //!< GStreamer
CAP_FFMPEG = 1900, //!< FFMPEG
CAP_IMAGES = 2000 //!< OpenCV Image Sequence (e.g. img_%02d.jpg)
CAP_ANY = 0, //!< Auto detect
CAP_VFW = 200, //!< Video For Windows (platform native)
CAP_V4L = 200, //!< V4L/V4L2 capturing support via libv4l
CAP_V4L2 = CAP_V4L, //!< Same as CAP_V4L
CAP_FIREWIRE = 300, //!< IEEE 1394 drivers
CAP_FIREWARE = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_IEEE1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_DC1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_CMU1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE
CAP_QT = 500, //!< QuickTime
CAP_UNICAP = 600, //!< Unicap drivers
CAP_DSHOW = 700, //!< DirectShow (via videoInput)
CAP_PVAPI = 800, //!< PvAPI, Prosilica GigE SDK
CAP_OPENNI = 900, //!< OpenNI (for Kinect)
CAP_OPENNI_ASUS = 910, //!< OpenNI (for Asus Xtion)
CAP_ANDROID = 1000, //!< Android - not used
CAP_XIAPI = 1100, //!< XIMEA Camera API
CAP_AVFOUNDATION = 1200, //!< AVFoundation framework for iOS
CAP_AVFOUNDATION_MAC = 1210, //!< AVFoundation framework for macOS
CAP_GIGANETIX = 1300, //!< Smartek Giganetix GigEVisionSDK
CAP_MSMF = 1400, //!< Microsoft Media Foundation (via videoInput)
CAP_WINRT = 1410, //!< Microsoft Windows Runtime using Media Foundation
CAP_INTELPERC = 1500, //!< Intel Perceptual Computing SDK
CAP_OPENNI2 = 1600, //!< OpenNI2 (for Kinect)
CAP_OPENNI2_ASUS = 1610, //!< OpenNI2 (for Asus Xtion and Occipital Structure sensors)
CAP_GPHOTO2 = 1700, //!< gPhoto2 connection
CAP_GSTREAMER = 1800, //!< GStreamer
CAP_FFMPEG = 1900, //!< FFMPEG
CAP_IMAGES = 2000 //!< OpenCV Image Sequence (e.g. img_%02d.jpg)
};
//! generic properties (based on DC1394 properties)

@ -108,6 +108,7 @@ enum
CV_CAP_XIAPI =1100, // XIMEA Camera API
CV_CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API)
CV_CAP_AVFOUNDATION_MAC = 1210, // AVFoundation framework for Mac
CV_CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK

@ -266,6 +266,12 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
if (pref) break;
#endif
#ifdef HAVE_AVFOUNDATION_MAC
case CV_CAP_AVFOUNDATION_MAC:
TRY_OPEN(capture, cvCreateCameraCapture_AVFoundation_Mac(index))
if (pref) break;
#endif
#ifdef HAVE_GIGE_API
case CV_CAP_GIGANETIX:
TRY_OPEN(capture, cvCreateCameraCapture_Giganetix(index))
@ -334,6 +340,12 @@ CV_IMPL CvCapture * cvCreateFileCaptureWithPreference (const char * filename, in
if (apiPreference) break;
#endif
#ifdef HAVE_AVFOUNDATION_MAC
case CV_CAP_AVFOUNDATION_MAC:
TRY_OPEN(result, cvCreateFileCapture_AVFoundation_Mac(filename))
if (apiPreference) break;
#endif
#ifdef HAVE_OPENNI
case CV_CAP_OPENNI:
TRY_OPEN(result, cvCreateFileCapture_OpenNI (filename))
@ -391,6 +403,10 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
TRY_OPEN(result, cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color))
#endif
#ifdef HAVE_AVFOUNDATION_MAC
TRY_OPEN(result, cvCreateVideoWriter_AVFoundation_Mac(filename, fourcc, fps, frameSize, is_color))
#endif
#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT)
TRY_OPEN(result, cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color))
#endif

File diff suppressed because it is too large Load Diff

@ -127,6 +127,7 @@ CvCapture* cvCreateFileCapture_OpenNI( const char* filename );
CvCapture* cvCreateCameraCapture_Android( int index );
CvCapture* cvCreateCameraCapture_XIMEA( int index );
CvCapture* cvCreateCameraCapture_AVFoundation(int index);
CvCapture* cvCreateCameraCapture_AVFoundation_Mac(int index);
CvCapture* cvCreateFileCapture_Images(const char* filename);
CvVideoWriter* cvCreateVideoWriter_Images(const char* filename);
@ -155,6 +156,9 @@ CvVideoWriter* cvCreateVideoWriter_QT ( const char* filename, int fourcc,
CvCapture* cvCreateFileCapture_AVFoundation (const char * filename);
CvVideoWriter* cvCreateVideoWriter_AVFoundation( const char* filename, int fourcc,
double fps, CvSize frameSize, int is_color );
CvCapture* cvCreateFileCapture_AVFoundation_Mac(const char * filename);
CvVideoWriter* cvCreateVideoWriter_AVFoundation_Mac( const char* filename, int fourcc,
double fps, CvSize frameSize, int is_color );
CvCapture * cvCreateCameraCapture_Unicap (const int index);

Loading…
Cancel
Save