Merge pull request #8920 from sovrasov:video_vriter_ext

pull/8942/head
Maksim Shabunin 8 years ago
commit 1f4067112f
  1. 21
      modules/videoio/include/opencv2/videoio.hpp
  2. 3
      modules/videoio/include/opencv2/videoio/videoio_c.h
  3. 98
      modules/videoio/src/cap.cpp
  4. 4
      modules/videoio/src/precomp.hpp

@ -114,7 +114,8 @@ enum VideoCaptureAPIs {
CAP_GSTREAMER = 1800, //!< GStreamer CAP_GSTREAMER = 1800, //!< GStreamer
CAP_FFMPEG = 1900, //!< Open and record video file or stream using the FFMPEG library CAP_FFMPEG = 1900, //!< Open and record video file or stream using the FFMPEG library
CAP_IMAGES = 2000, //!< OpenCV Image Sequence (e.g. img_%02d.jpg) CAP_IMAGES = 2000, //!< OpenCV Image Sequence (e.g. img_%02d.jpg)
CAP_ARAVIS = 2100 //!< Aravis SDK CAP_ARAVIS = 2100, //!< Aravis SDK
CAP_OCV_MJPEG = 2200 //!< Built-in MotionJPEG codec
}; };
/** @brief %VideoCapture generic properties identifier. /** @brief %VideoCapture generic properties identifier.
@ -849,6 +850,13 @@ public:
CV_WRAP VideoWriter(const String& filename, int fourcc, double fps, CV_WRAP VideoWriter(const String& filename, int fourcc, double fps,
Size frameSize, bool isColor = true); Size frameSize, bool isColor = true);
/** @overload
The `apiPreference` parameter allows to specify API backends to use. Can be used to enforce a specific reader implementation
if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_GSTREAMER.
*/
CV_WRAP VideoWriter(int apiPreference, const String& filename, int fourcc, double fps,
Size frameSize, bool isColor = true);
/** @brief Default destructor /** @brief Default destructor
The method first calls VideoWriter::release to close the already opened file. The method first calls VideoWriter::release to close the already opened file.
@ -866,6 +874,17 @@ public:
CV_WRAP virtual bool open(const String& filename, int fourcc, double fps, CV_WRAP virtual bool open(const String& filename, int fourcc, double fps,
Size frameSize, bool isColor = true); Size frameSize, bool isColor = true);
/** @brief Initializes or reinitializes video writer.
The method opens video writer. Parameters are the same as in the constructor
VideoWriter::VideoWriter.
@return `true` if video writer has been successfully initialized
The method first calls VideoWriter::release to close the already opened file.
*/
CV_WRAP bool open(int apiPreference, const String& filename, int fourcc, double fps,
Size frameSize, bool isColor = true);
/** @brief Returns true if video writer has been successfully initialized. /** @brief Returns true if video writer has been successfully initialized.
*/ */
CV_WRAP virtual bool isOpened() const; CV_WRAP virtual bool isOpened() const;

@ -124,7 +124,8 @@ enum
CV_CAP_FFMPEG = 1900, // FFMPEG CV_CAP_FFMPEG = 1900, // FFMPEG
CV_CAP_IMAGES = 2000, // OpenCV Image Sequence (e.g. img_%02d.jpg) CV_CAP_IMAGES = 2000, // OpenCV Image Sequence (e.g. img_%02d.jpg)
CV_CAP_ARAVIS = 2100 // Aravis GigE SDK CV_CAP_ARAVIS = 2100, // Aravis GigE SDK
CV_CAP_OCV_MJPEG = 2200 // Built-in MotionJPEG codec
}; };
/** @brief start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) /** @brief start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*)

@ -371,47 +371,59 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc, CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
double fps, CvSize frameSize, int is_color ) double fps, CvSize frameSize, int is_color )
{ {
// If none of the writers is used return cvCreateVideoWriterWithPreference(CV_CAP_ANY, filename, fourcc, fps, frameSize, is_color);
// these statements suppress 'unused parameter' warnings. }
CvVideoWriter* cvCreateVideoWriterWithPreference(int apiPreference, const char* filename, int fourcc,
double fps, CvSize frameSize, int is_color )
{
CV_UNUSED(frameSize); CV_UNUSED(frameSize);
CV_UNUSED(is_color); CV_UNUSED(is_color);
//CV_FUNCNAME( "cvCreateVideoWriter" );
CvVideoWriter *result = 0; CvVideoWriter *result = 0;
if(!fourcc || !fps) if(!fourcc || !fps)
TRY_OPEN(result, cvCreateVideoWriter_Images(filename)) TRY_OPEN(result, cvCreateVideoWriter_Images(filename))
#ifdef HAVE_FFMPEG switch(apiPreference)
TRY_OPEN(result, cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color)) {
#endif default:
//exit if the specified API is unavaliable
#ifdef HAVE_VFW if (apiPreference != CV_CAP_ANY) break;
TRY_OPEN(result, cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color)) #ifdef HAVE_FFMPEG
#endif case CV_CAP_FFMPEG:
TRY_OPEN(result, cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color))
#ifdef HAVE_MSMF if (apiPreference != CV_CAP_ANY) break;
TRY_OPEN(result, cvCreateVideoWriter_MSMF(filename, fourcc, fps, frameSize, is_color)) #endif
#endif #ifdef HAVE_VFW
case CV_CAP_VFW:
/* #ifdef HAVE_XINE TRY_OPEN(result, cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color))
TRY_OPEN(result, cvCreateVideoWriter_XINE(filename, fourcc, fps, frameSize, is_color)) if (apiPreference != CV_CAP_ANY) break;
#endif #endif
*/ #ifdef HAVE_MSMF
#ifdef HAVE_AVFOUNDATION case CV_CAP_MSMF:
TRY_OPEN(result, cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color)) TRY_OPEN(result, cvCreateVideoWriter_MSMF(filename, fourcc, fps, frameSize, is_color))
#endif if (apiPreference != CV_CAP_ANY) break;
#endif
#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT) #ifdef HAVE_AVFOUNDATION
TRY_OPEN(result, cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color)) case CV_CAP_AVFOUNDATION:
#endif TRY_OPEN(result, cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color))
if (apiPreference != CV_CAP_ANY) break;
#ifdef HAVE_GSTREAMER #endif
TRY_OPEN(result, cvCreateVideoWriter_GStreamer(filename, fourcc, fps, frameSize, is_color)) #if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT)
#endif case(CV_CAP_QT):
TRY_OPEN(result, cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color))
TRY_OPEN(result, cvCreateVideoWriter_Images(filename)) if (apiPreference != CV_CAP_ANY) break;
#endif
#ifdef HAVE_GSTREAMER
case CV_CAP_GSTREAMER:
TRY_OPEN(result, cvCreateVideoWriter_GStreamer (filename, fourcc, fps, frameSize, is_color))
if (apiPreference != CV_CAP_ANY) break;
#endif
case CV_CAP_IMAGES:
TRY_OPEN(result, cvCreateVideoWriter_Images(filename))
if (apiPreference != CV_CAP_ANY) break;
}
return result; return result;
} }
@ -543,10 +555,11 @@ static Ptr<IVideoCapture> IVideoCapture_create(const String& filename)
return Ptr<IVideoCapture>(); return Ptr<IVideoCapture>();
} }
static Ptr<IVideoWriter> IVideoWriter_create(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor) static Ptr<IVideoWriter> IVideoWriter_create(int apiPreference, const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
{ {
Ptr<IVideoWriter> iwriter; Ptr<IVideoWriter> iwriter;
if( _fourcc == CV_FOURCC('M', 'J', 'P', 'G') ) if( (apiPreference == CAP_OCV_MJPEG || apiPreference == CAP_ANY)
&& _fourcc == CV_FOURCC('M', 'J', 'P', 'G') )
iwriter = createMotionJpegWriter(filename, fps, frameSize, isColor); iwriter = createMotionJpegWriter(filename, fps, frameSize, isColor);
return iwriter; return iwriter;
} }
@ -725,6 +738,12 @@ VideoWriter::VideoWriter(const String& filename, int _fourcc, double fps, Size f
open(filename, _fourcc, fps, frameSize, isColor); open(filename, _fourcc, fps, frameSize, isColor);
} }
VideoWriter::VideoWriter(int apiPreference, const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
{
open(apiPreference, filename, _fourcc, fps, frameSize, isColor);
}
void VideoWriter::release() void VideoWriter::release()
{ {
iwriter.release(); iwriter.release();
@ -737,14 +756,19 @@ VideoWriter::~VideoWriter()
} }
bool VideoWriter::open(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor) bool VideoWriter::open(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
{
return open(CAP_ANY, filename, _fourcc, fps, frameSize, isColor);
}
bool VideoWriter::open(int apiPreference, const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
{ {
CV_INSTRUMENT_REGION() CV_INSTRUMENT_REGION()
if (isOpened()) release(); if (isOpened()) release();
iwriter = IVideoWriter_create(filename, _fourcc, fps, frameSize, isColor); iwriter = IVideoWriter_create(apiPreference, filename, _fourcc, fps, frameSize, isColor);
if (!iwriter.empty()) if (!iwriter.empty())
return true; return true;
writer.reset(cvCreateVideoWriter(filename.c_str(), _fourcc, fps, frameSize, isColor)); writer.reset(cvCreateVideoWriterWithPreference(apiPreference, filename.c_str(), _fourcc, fps, frameSize, isColor));
return isOpened(); return isOpened();
} }

@ -163,6 +163,10 @@ CvCapture * cvCreateCameraCapture_Unicap (const int index);
CvCapture * cvCreateCameraCapture_PvAPI (const int index); CvCapture * cvCreateCameraCapture_PvAPI (const int index);
CvVideoWriter* cvCreateVideoWriter_GStreamer( const char* filename, int fourcc, CvVideoWriter* cvCreateVideoWriter_GStreamer( const char* filename, int fourcc,
double fps, CvSize frameSize, int is_color ); double fps, CvSize frameSize, int is_color );
CvVideoWriter* cvCreateVideoWriterWithPreference(int api, const char* filename, int fourcc,
double fps, CvSize frame_size,
int is_color CV_DEFAULT(1));
namespace cv namespace cv
{ {

Loading…
Cancel
Save