|
|
|
@ -41,13 +41,28 @@ |
|
|
|
|
|
|
|
|
|
#include "precomp.hpp" |
|
|
|
|
|
|
|
|
|
#if defined(HAVE_FFMPEG) |
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
|
|
|
|
|
|
|
#if defined HAVE_FFMPEG && !defined _WIN32 |
|
|
|
|
#if !defined(HAVE_FFMPEG_WRAPPER) |
|
|
|
|
#include "cap_ffmpeg_impl.hpp" |
|
|
|
|
|
|
|
|
|
#define icvCreateFileCapture_FFMPEG_p cvCreateFileCapture_FFMPEG |
|
|
|
|
#define icvReleaseCapture_FFMPEG_p cvReleaseCapture_FFMPEG |
|
|
|
|
#define icvGrabFrame_FFMPEG_p cvGrabFrame_FFMPEG |
|
|
|
|
#define icvRetrieveFrame_FFMPEG_p cvRetrieveFrame_FFMPEG |
|
|
|
|
#define icvSetCaptureProperty_FFMPEG_p cvSetCaptureProperty_FFMPEG |
|
|
|
|
#define icvGetCaptureProperty_FFMPEG_p cvGetCaptureProperty_FFMPEG |
|
|
|
|
#define icvCreateVideoWriter_FFMPEG_p cvCreateVideoWriter_FFMPEG |
|
|
|
|
#define icvReleaseVideoWriter_FFMPEG_p cvReleaseVideoWriter_FFMPEG |
|
|
|
|
#define icvWriteFrame_FFMPEG_p cvWriteFrame_FFMPEG |
|
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
|
|
#include "cap_ffmpeg_api.hpp" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
namespace cv { namespace { |
|
|
|
|
|
|
|
|
|
static CvCreateFileCapture_Plugin icvCreateFileCapture_FFMPEG_p = 0; |
|
|
|
|
static CvReleaseCapture_Plugin icvReleaseCapture_FFMPEG_p = 0; |
|
|
|
@ -99,7 +114,7 @@ private: |
|
|
|
|
|
|
|
|
|
icvInitFFMPEG() |
|
|
|
|
{ |
|
|
|
|
#if defined _WIN32 |
|
|
|
|
#if defined _WIN32 |
|
|
|
|
const wchar_t* module_name_ = L"opencv_ffmpeg" |
|
|
|
|
CVAUX_STRW(CV_MAJOR_VERSION) CVAUX_STRW(CV_MINOR_VERSION) CVAUX_STRW(CV_SUBMINOR_VERSION) |
|
|
|
|
#if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__) |
|
|
|
@ -161,7 +176,7 @@ private: |
|
|
|
|
(CvReleaseVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseVideoWriter_FFMPEG"); |
|
|
|
|
icvWriteFrame_FFMPEG_p = |
|
|
|
|
(CvWriteFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvWriteFrame_FFMPEG"); |
|
|
|
|
|
|
|
|
|
# endif // _WIN32
|
|
|
|
|
#if 0 |
|
|
|
|
if( icvCreateFileCapture_FFMPEG_p != 0 && |
|
|
|
|
icvReleaseCapture_FFMPEG_p != 0 && |
|
|
|
@ -181,21 +196,18 @@ private: |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
#elif defined HAVE_FFMPEG |
|
|
|
|
icvCreateFileCapture_FFMPEG_p = (CvCreateFileCapture_Plugin)cvCreateFileCapture_FFMPEG; |
|
|
|
|
icvReleaseCapture_FFMPEG_p = (CvReleaseCapture_Plugin)cvReleaseCapture_FFMPEG; |
|
|
|
|
icvGrabFrame_FFMPEG_p = (CvGrabFrame_Plugin)cvGrabFrame_FFMPEG; |
|
|
|
|
icvRetrieveFrame_FFMPEG_p = (CvRetrieveFrame_Plugin)cvRetrieveFrame_FFMPEG; |
|
|
|
|
icvSetCaptureProperty_FFMPEG_p = (CvSetCaptureProperty_Plugin)cvSetCaptureProperty_FFMPEG; |
|
|
|
|
icvGetCaptureProperty_FFMPEG_p = (CvGetCaptureProperty_Plugin)cvGetCaptureProperty_FFMPEG; |
|
|
|
|
icvCreateVideoWriter_FFMPEG_p = (CvCreateVideoWriter_Plugin)cvCreateVideoWriter_FFMPEG; |
|
|
|
|
icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)cvReleaseVideoWriter_FFMPEG; |
|
|
|
|
icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)cvWriteFrame_FFMPEG; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace
|
|
|
|
|
#endif // HAVE_FFMPEG_WRAPPER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace cv { |
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
class CvCapture_FFMPEG_proxy CV_FINAL : public cv::IVideoCapture |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
@ -228,19 +240,20 @@ public: |
|
|
|
|
} |
|
|
|
|
virtual bool open( const cv::String& filename ) |
|
|
|
|
{ |
|
|
|
|
icvInitFFMPEG::Init(); |
|
|
|
|
close(); |
|
|
|
|
|
|
|
|
|
if( !icvCreateFileCapture_FFMPEG_p ) |
|
|
|
|
return false; |
|
|
|
|
ffmpegCapture = icvCreateFileCapture_FFMPEG_p( filename.c_str() ); |
|
|
|
|
return ffmpegCapture != 0; |
|
|
|
|
} |
|
|
|
|
virtual void close() |
|
|
|
|
{ |
|
|
|
|
if( ffmpegCapture && icvReleaseCapture_FFMPEG_p ) |
|
|
|
|
if (ffmpegCapture |
|
|
|
|
#if defined(HAVE_FFMPEG_WRAPPER) |
|
|
|
|
&& icvReleaseCapture_FFMPEG_p |
|
|
|
|
#endif |
|
|
|
|
) |
|
|
|
|
icvReleaseCapture_FFMPEG_p( &ffmpegCapture ); |
|
|
|
|
assert( ffmpegCapture == 0 ); |
|
|
|
|
CV_Assert(ffmpegCapture == 0); |
|
|
|
|
ffmpegCapture = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -248,18 +261,26 @@ public: |
|
|
|
|
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_FFMPEG; } |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
void* ffmpegCapture; |
|
|
|
|
CvCapture_FFMPEG* ffmpegCapture; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
cv::Ptr<cv::IVideoCapture> cv::cvCreateFileCapture_FFMPEG_proxy(const cv::String& filename) |
|
|
|
|
cv::Ptr<cv::IVideoCapture> cvCreateFileCapture_FFMPEG_proxy(const cv::String& filename) |
|
|
|
|
{ |
|
|
|
|
#if defined(HAVE_FFMPEG_WRAPPER) |
|
|
|
|
icvInitFFMPEG::Init(); |
|
|
|
|
if (!icvCreateFileCapture_FFMPEG_p) |
|
|
|
|
return cv::Ptr<cv::IVideoCapture>(); |
|
|
|
|
#endif |
|
|
|
|
cv::Ptr<CvCapture_FFMPEG_proxy> capture = cv::makePtr<CvCapture_FFMPEG_proxy>(filename); |
|
|
|
|
if (capture && capture->isOpened()) |
|
|
|
|
return capture; |
|
|
|
|
return cv::Ptr<cv::IVideoCapture>(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
class CvVideoWriter_FFMPEG_proxy CV_FINAL : |
|
|
|
|
public cv::IVideoWriter |
|
|
|
|
{ |
|
|
|
@ -278,19 +299,20 @@ public: |
|
|
|
|
} |
|
|
|
|
virtual bool open( const cv::String& filename, int fourcc, double fps, cv::Size frameSize, bool isColor ) |
|
|
|
|
{ |
|
|
|
|
icvInitFFMPEG::Init(); |
|
|
|
|
close(); |
|
|
|
|
if( !icvCreateVideoWriter_FFMPEG_p ) |
|
|
|
|
return false; |
|
|
|
|
ffmpegWriter = icvCreateVideoWriter_FFMPEG_p( filename.c_str(), fourcc, fps, frameSize.width, frameSize.height, isColor ); |
|
|
|
|
return ffmpegWriter != 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
virtual void close() |
|
|
|
|
{ |
|
|
|
|
if( ffmpegWriter && icvReleaseVideoWriter_FFMPEG_p ) |
|
|
|
|
if (ffmpegWriter |
|
|
|
|
#if defined(HAVE_FFMPEG_WRAPPER) |
|
|
|
|
&& icvReleaseVideoWriter_FFMPEG_p |
|
|
|
|
#endif |
|
|
|
|
) |
|
|
|
|
icvReleaseVideoWriter_FFMPEG_p( &ffmpegWriter ); |
|
|
|
|
assert( ffmpegWriter == 0 ); |
|
|
|
|
CV_Assert(ffmpegWriter == 0); |
|
|
|
|
ffmpegWriter = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -299,15 +321,25 @@ public: |
|
|
|
|
virtual bool isOpened() const CV_OVERRIDE { return ffmpegWriter != 0; } |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
void* ffmpegWriter; |
|
|
|
|
CvVideoWriter_FFMPEG* ffmpegWriter; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
cv::Ptr<cv::IVideoWriter> cv::cvCreateVideoWriter_FFMPEG_proxy(const cv::String& filename, int fourcc, |
|
|
|
|
double fps, cv::Size frameSize, int isColor) |
|
|
|
|
cv::Ptr<cv::IVideoWriter> cvCreateVideoWriter_FFMPEG_proxy(const cv::String& filename, int fourcc, |
|
|
|
|
double fps, cv::Size frameSize, int isColor) |
|
|
|
|
{ |
|
|
|
|
#if defined(HAVE_FFMPEG_WRAPPER) |
|
|
|
|
icvInitFFMPEG::Init(); |
|
|
|
|
if (!icvCreateVideoWriter_FFMPEG_p) |
|
|
|
|
return cv::Ptr<cv::IVideoWriter>(); |
|
|
|
|
#endif |
|
|
|
|
cv::Ptr<CvVideoWriter_FFMPEG_proxy> writer = cv::makePtr<CvVideoWriter_FFMPEG_proxy>(filename, fourcc, fps, frameSize, isColor != 0); |
|
|
|
|
if (writer && writer->isOpened()) |
|
|
|
|
return writer; |
|
|
|
|
return cv::Ptr<cv::IVideoWriter>(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
#endif // defined(HAVE_FFMPEG)
|
|
|
|
|