您的位置:首页 > 运维架构

opencv如何对视频进行编解码

2014-03-11 13:58 316 查看
 VideoCapture captRefrnc(“Megamind.avi")

                    ||

                    \/

/*cap.cpp文件*/

CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)

{

    CvCapture * result = 0;

    if (! result)/*首先调用FFMPEG解码*/

        result = cvCreateFileCapture_FFMPEG_proxy (filename);

#ifdef HAVE_XINE

    if (! result)

        result = cvCreateFileCapture_XINE (filename);

#endif

#ifdef HAVE_GSTREAMER

    if (! result)

        result = cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename);

#endif

#ifdef HAVE_QUICKTIME

    if (! result)

        result = cvCreateFileCapture_QT (filename);

#endif

#ifdef HAVE_AVFOUNDATION

    if (! result)

        result = cvCreateFileCapture_AVFoundation (filename);

#endif

#ifdef HAVE_OPENNI

    if (! result)

        result = cvCreateFileCapture_OpenNI (filename);

#endif

    if (! result)

        result = cvCreateFileCapture_Images (filename);

    return result;

}

其中:当用FFMPEG解码时:   result = cvCreateFileCapture_FFMPEG_proxy (filename);

                                                                       ||

                                                                       \/

static void icvInitFFMPEG(void)

{

    static int ffmpegInitialized = 0;

    if( !ffmpegInitialized )

    {

    #if defined WIN32 || defined _WIN32

        const char* module_name = "opencv_ffmpeg"

            CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)

        #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__)

            "_64"

        #endif

            ".dll";

/*显示的是module_name = "opencv_ffmpeg243.dll"*/

        static HMODULE icvFFOpenCV = LoadLibrary( module_name );/*装入opencv_ffmpeg243.dll库*/

        if( icvFFOpenCV )

        {

            icvCreateFileCapture_FFMPEG_p =

                (CvCreateFileCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateFileCapture_FFMPEG");/*定位到库的函数,下同!*/

            icvReleaseCapture_FFMPEG_p =

                (CvReleaseCapture_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseCapture_FFMPEG");

            icvGrabFrame_FFMPEG_p =

                (CvGrabFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvGrabFrame_FFMPEG");

            icvRetrieveFrame_FFMPEG_p =

                (CvRetrieveFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvRetrieveFrame_FFMPEG");

            icvSetCaptureProperty_FFMPEG_p =

                (CvSetCaptureProperty_Plugin)GetProcAddress(icvFFOpenCV, "cvSetCaptureProperty_FFMPEG");

            icvGetCaptureProperty_FFMPEG_p =

                (CvGetCaptureProperty_Plugin)GetProcAddress(icvFFOpenCV, "cvGetCaptureProperty_FFMPEG");

            icvCreateVideoWriter_FFMPEG_p =

                (CvCreateVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvCreateVideoWriter_FFMPEG");

            icvReleaseVideoWriter_FFMPEG_p =

                (CvReleaseVideoWriter_Plugin)GetProcAddress(icvFFOpenCV, "cvReleaseVideoWriter_FFMPEG");

            icvWriteFrame_FFMPEG_p =

                (CvWriteFrame_Plugin)GetProcAddress(icvFFOpenCV, "cvWriteFrame_FFMPEG");

总结:说明opencv用ffmpeg对视频编解码,用opencv_ffmpeg243.dll库的,而不是静态链接。如果用这个库编解码视频,必须拷贝这个dll。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: