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.
44 static int ffmpeg_initialized = 0;
45 static CvCaptureFromFile icvCaptureFromFile_FFMPEG_p = 0;
46 static CvCreateVideoWriter icvCreateVideoWriter_FFMPEG_p = 0;
47 static CvWriteFrame icvWriteFrame_FFMPEG_p = 0;
48 static CvReleaseVideoWriter icvReleaseVideoWriter_FFMPEG_p = 0;
49 static HMODULE ffopencv = 0;
54 if( !ffmpeg_initialized )
57 #define ffopencv_suffix_dbg "d"
59 #define ffopencv_suffix_dbg ""
62 #define ffopencv_suffix "_64"
64 #define ffopencv_suffix ""
67 #define ffopencv_name_m2(a,b,c) "ffopencv" #a #b #c ffopencv_suffix ffopencv_suffix_dbg ".dll"
68 #define ffopencv_name_m(a,b,c) ffopencv_name_m2(a,b,c)
69 const char* ffopencv_name =
70 ffopencv_name_m(CV_MAJOR_VERSION,CV_MINOR_VERSION,CV_SUBMINOR_VERSION);
72 ffopencv = LoadLibrary( ffopencv_name );
75 icvCaptureFromFile_FFMPEG_p =
76 (CvCaptureFromFile)GetProcAddress(ffopencv, "cvCaptureFromFile_FFMPEG");
77 icvCreateVideoWriter_FFMPEG_p =
78 (CvCreateVideoWriter)GetProcAddress(ffopencv, "cvCreateVideoWriter_FFMPEG");
79 icvWriteFrame_FFMPEG_p =
80 (CvWriteFrame)GetProcAddress(ffopencv, "cvWriteFrame_FFMPEG");
81 icvReleaseVideoWriter_FFMPEG_p =
82 (CvReleaseVideoWriter)GetProcAddress(ffopencv, "cvReleaseVideoWriter_FFMPEG");
85 ffmpeg_initialized = 1;
89 CvCapture * cvCaptureFromFile_Win32 (const char * filename)
91 CvCapture* result = 0;
95 if( icvCaptureFromFile_FFMPEG_p )
96 result = icvCaptureFromFile_FFMPEG_p(filename);
99 result = cvCaptureFromFile_VFW(filename);
105 CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
106 double fps, CvSize frameSize, int is_color )
108 CvVideoWriter* result = 0;
112 // as video writer does not have virtual functions, we should be
113 // careful and do not mix FFMPEG & VFW. Therefore, use only one of the interfaces
114 if( icvCreateVideoWriter_FFMPEG_p )
115 result = icvCreateVideoWriter_FFMPEG_p(filename, fourcc, fps, frameSize, is_color);
117 result = cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color);
122 CV_IMPL int cvWriteFrame( CvVideoWriter* writer, const IplImage* image )
126 if( icvCreateVideoWriter_FFMPEG_p && icvWriteFrame_FFMPEG_p )
127 result = icvWriteFrame_FFMPEG_p( writer, image );
129 result = cvWriteFrame_VFW( writer, image );
134 CV_IMPL void cvReleaseVideoWriter( CvVideoWriter** writer )
136 if( icvCreateVideoWriter_FFMPEG_p && icvReleaseVideoWriter_FFMPEG_p )
137 icvReleaseVideoWriter_FFMPEG_p( writer );
139 cvReleaseVideoWriter_VFW( writer );