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 void* (*CvCreateFileCapture_Plugin)( const char* filename );
47 typedef void* (*CvCreateCameraCapture_Plugin)( int index );
48 typedef int (*CvGrabFrame_Plugin)( void* capture_handle );
49 typedef IplImage* (*CvRetrieveFrame_Plugin)( void* capture_handle, int );
50 typedef int (*CvSetCaptureProperty_Plugin)( void* capture_handle, int prop_id, double value );
51 typedef double (*CvGetCaptureProperty_Plugin)( void* capture_handle, int prop_id );
52 typedef void (*CvReleaseCapture_Plugin)( void** capture_handle );
53 typedef void* (*CvCreateVideoWriter_Plugin)( const char* filename, int fourcc,
54 double fps, CvSize frameSize, int isColor );
55 typedef int (*CvWriteFrame_Plugin)( void* writer_handle, const IplImage* frame );
56 typedef void (*CvReleaseVideoWriter_Plugin)( void** writer );
59 static HMODULE icvFFOpenCV = 0;
60 static CvCreateFileCapture_Plugin icvCreateFileCapture_FFMPEG_p = 0;
61 static CvReleaseCapture_Plugin icvReleaseCapture_FFMPEG_p = 0;
62 static CvGrabFrame_Plugin icvGrabFrame_FFMPEG_p = 0;
63 static CvRetrieveFrame_Plugin icvRetrieveFrame_FFMPEG_p = 0;
64 static CvSetCaptureProperty_Plugin icvSetCaptureProperty_FFMPEG_p = 0;
65 static CvGetCaptureProperty_Plugin icvGetCaptureProperty_FFMPEG_p = 0;
66 static CvCreateVideoWriter_Plugin icvCreateVideoWriter_FFMPEG_p = 0;
67 static CvReleaseVideoWriter_Plugin icvReleaseVideoWriter_FFMPEG_p = 0;
68 static CvWriteFrame_Plugin icvWriteFrame_FFMPEG_p = 0;
73 static int ffmpegInitialized = 0;
74 if( !ffmpegInitialized )
77 #define ffopencv_prefix "lib"
79 #define ffopencv_prefix ""
81 #if defined(_DEBUG) && defined(__MINGW32__)
82 #define ffopencv_suffix_dbg "d"
84 #define ffopencv_suffix_dbg ""
87 #define ffopencv_suffix "_64"
89 #define ffopencv_suffix ""
92 #define ffopencv_name_m2(a,b,c) ffopencv_prefix "opencv_ffmpeg" #a #b #c ffopencv_suffix ffopencv_suffix_dbg ".dll"
93 #define ffopencv_name_m(a,b,c) ffopencv_name_m2(a,b,c)
94 const char* ffopencv_name =
95 ffopencv_name_m(CV_MAJOR_VERSION,CV_MINOR_VERSION,CV_SUBMINOR_VERSION);
97 icvFFOpenCV = LoadLibrary( ffopencv_name );
100 icvCreateFileCapture_FFMPEG_p =
101 (CvCreateFileCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateFileCapture_FFMPEG");
102 icvReleaseCapture_FFMPEG_p =
103 (CvReleaseCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseCapture_FFMPEG");
104 icvGrabFrame_FFMPEG_p =
105 (CvGrabFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvGrabFrame_FFMPEG");
106 icvRetrieveFrame_FFMPEG_p =
107 (CvRetrieveFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvRetrieveFrame_FFMPEG");
108 icvSetCaptureProperty_FFMPEG_p =
109 (CvSetCaptureProperty_Plugin)GetProcAddress(icvFFOpenCV, "cvSetCaptureProperty_FFMPEG");
110 icvGetCaptureProperty_FFMPEG_p =
111 (CvGetCaptureProperty_Plugin)GetProcAddress(icvFFOpenCV, "cvGetCaptureProperty_FFMPEG");
112 icvCreateVideoWriter_FFMPEG_p =
113 (CvCreateVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateVideoWriter_FFMPEG");
114 icvReleaseVideoWriter_FFMPEG_p =
115 (CvReleaseVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseVideoWriter_FFMPEG");
116 icvWriteFrame_FFMPEG_p =
117 (CvWriteFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvWriteFrame_FFMPEG");
119 ffmpegInitialized = 1;
124 class CvCapture_FFMPEG_proxy : public CvCapture
127 CvCapture_FFMPEG_proxy() { ffmpegCapture = 0; }
128 virtual ~CvCapture_FFMPEG_proxy() { close(); }
130 virtual double getProperty(int propId)
132 return ffmpegCapture ? icvGetCaptureProperty_FFMPEG_p(ffmpegCapture, propId) : 0;
134 virtual bool setProperty(int propId, double value)
136 return ffmpegCapture ? icvSetCaptureProperty_FFMPEG_p(ffmpegCapture, propId, value)!=0 : false;
138 virtual bool grabFrame()
140 return ffmpegCapture ? icvGrabFrame_FFMPEG_p(ffmpegCapture)!=0 : false;
142 virtual IplImage* retrieveFrame(int)
144 return ffmpegCapture ? icvRetrieveFrame_FFMPEG_p(ffmpegCapture,0) : 0;
146 virtual bool open( const char* filename )
151 if( !icvCreateFileCapture_FFMPEG_p )
153 ffmpegCapture = icvCreateFileCapture_FFMPEG_p( filename );
154 return ffmpegCapture != 0;
158 if( ffmpegCapture && icvReleaseCapture_FFMPEG_p )
159 icvReleaseCapture_FFMPEG_p( &ffmpegCapture );
160 assert( ffmpegCapture == 0 );
169 CvCapture* cvCreateFileCapture_Win32(const char * filename)
171 CvCapture_FFMPEG_proxy* result = new CvCapture_FFMPEG_proxy;
172 if( result->open( filename ))
175 return cvCreateFileCapture_VFW(filename);
179 class CvVideoWriter_FFMPEG_proxy : public CvVideoWriter
182 CvVideoWriter_FFMPEG_proxy() { ffmpegWriter = 0; }
183 virtual ~CvVideoWriter_FFMPEG_proxy() { close(); }
185 virtual bool writeFrame( const IplImage* image )
187 return ffmpegWriter ? icvWriteFrame_FFMPEG_p(ffmpegWriter, image)!=0 : false;
189 virtual bool open( const char* filename, int fourcc, double fps, CvSize frameSize, bool isColor )
193 if( !icvCreateVideoWriter_FFMPEG_p )
195 ffmpegWriter = icvCreateVideoWriter_FFMPEG_p( filename, fourcc, fps, frameSize, isColor );
196 return ffmpegWriter != 0;
201 if( ffmpegWriter && icvReleaseVideoWriter_FFMPEG_p )
202 icvReleaseVideoWriter_FFMPEG_p( &ffmpegWriter );
203 assert( ffmpegWriter == 0 );
212 CvVideoWriter* cvCreateVideoWriter_Win32( const char* filename, int fourcc,
213 double fps, CvSize frameSize, int isColor )
215 CvVideoWriter_FFMPEG_proxy* result = new CvVideoWriter_FFMPEG_proxy;
217 if( result->open( filename, fourcc, fps, frameSize, isColor != 0 ))
221 return cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, isColor);