1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
46 typedef CvCapture* (*CvCreateFileCapture_Plugin)( const char* filename );
47 typedef CvCapture* (*CvCreateCameraCapture_Plugin)( int index );
48 typedef void (*CvReleaseCapture_Plugin)( CvCapture** capture );
49 typedef CvVideoWriter* (*CvCreateVideoWriter_Plugin)( const char* filename, int fourcc,
50 double fps, CvSize frameSize, int isColor );
51 typedef void (*CvReleaseVideoWriter_Plugin)( CvVideoWriter** writer );
54 static HMODULE icvFFOpenCV = 0;
55 static CvCreateFileCapture_Plugin icvCreateFileCapture_FFMPEG_p = 0;
56 static CvReleaseCapture_Plugin icvReleaseCapture_FFMPEG_p = 0;
57 static CvCreateVideoWriter_Plugin icvCreateVideoWriter_FFMPEG_p = 0;
58 static CvReleaseVideoWriter_Plugin icvReleaseVideoWriter_FFMPEG_p = 0;
64 static int ffmpegInitialized = 0;
65 if( !ffmpegInitialized )
68 //#define ffopencv_suffix_dbg "d"
69 #define ffopencv_suffix_dbg ""
71 #define ffopencv_suffix_dbg ""
74 #define ffopencv_suffix "_64"
76 #define ffopencv_suffix ""
79 #define ffopencv_name_m2(a,b,c) "ffopencv" #a #b #c ffopencv_suffix ffopencv_suffix_dbg ".dll"
80 #define ffopencv_name_m(a,b,c) ffopencv_name_m2(a,b,c)
81 const char* ffopencv_name =
82 ffopencv_name_m(CV_MAJOR_VERSION,CV_MINOR_VERSION,CV_SUBMINOR_VERSION);
84 icvFFOpenCV = LoadLibrary( ffopencv_name );
87 icvCreateFileCapture_FFMPEG_p =
88 (CvCreateFileCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateFileCapture_FFMPEG");
89 icvCreateVideoWriter_FFMPEG_p =
90 (CvCreateVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateVideoWriter_FFMPEG");
91 icvReleaseCapture_FFMPEG_p =
92 (CvReleaseCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseCapture_FFMPEG");
93 icvReleaseVideoWriter_FFMPEG_p =
94 (CvReleaseVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseVideoWriter_FFMPEG");
96 ffmpegInitialized = 1;
101 class CvCapture_FFMPEG_proxy : public CvCapture
104 CvCapture_FFMPEG_proxy() { ffmpegCapture = 0; }
105 virtual ~CvCapture_FFMPEG_proxy() { close(); }
107 virtual double getProperty(int propId)
109 return ffmpegCapture ? ffmpegCapture->getProperty(propId) : 0;
111 virtual bool setProperty(int propId, double value)
113 return ffmpegCapture ? ffmpegCapture->setProperty(propId, value) : false;
115 virtual bool grabFrame()
117 return ffmpegCapture ? ffmpegCapture->grabFrame() : false;
119 virtual IplImage* retrieveFrame()
121 return ffmpegCapture ? ffmpegCapture->retrieveFrame() : 0;
123 virtual bool open( const char* filename )
128 if( !icvCreateFileCapture_FFMPEG_p )
130 ffmpegCapture = icvCreateFileCapture_FFMPEG_p( filename );
131 return ffmpegCapture != 0;
135 if( ffmpegCapture && icvReleaseCapture_FFMPEG_p )
136 icvReleaseCapture_FFMPEG_p( &ffmpegCapture );
137 assert( ffmpegCapture == 0 );
142 CvCapture* ffmpegCapture;
146 CvCapture* cvCreateFileCapture_Win32(const char * filename)
148 CvCapture_FFMPEG_proxy* result = new CvCapture_FFMPEG_proxy;
149 if( result->open( filename ))
152 return cvCreateFileCapture_VFW(filename);
156 class CvVideoWriter_FFMPEG_proxy : public CvVideoWriter
159 CvVideoWriter_FFMPEG_proxy() { ffmpegWriter = 0; }
160 virtual ~CvVideoWriter_FFMPEG_proxy() { close(); }
162 virtual bool writeFrame( const IplImage* image )
164 return ffmpegWriter ? ffmpegWriter->writeFrame(image) : false;
166 virtual bool open( const char* filename, int fourcc, double fps, CvSize frameSize, bool isColor )
170 if( !icvCreateVideoWriter_FFMPEG_p )
172 ffmpegWriter = icvCreateVideoWriter_FFMPEG_p( filename, fourcc, fps, frameSize, isColor );
173 return ffmpegWriter != 0;
178 if( ffmpegWriter && icvReleaseVideoWriter_FFMPEG_p )
179 icvReleaseVideoWriter_FFMPEG_p( &ffmpegWriter );
180 assert( ffmpegWriter == 0 );
185 CvVideoWriter* ffmpegWriter;
189 CvVideoWriter* cvCreateVideoWriter_Win32( const char* filename, int fourcc,
190 double fps, CvSize frameSize, int isColor )
192 CvVideoWriter_FFMPEG_proxy* result = new CvVideoWriter_FFMPEG_proxy;
194 if( result->open( filename, fourcc, fps, frameSize, isColor != 0 ))
198 return cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, isColor);