2013年3月29日 星期五

在 Windows XP Visual Studio 2010 安裝使用 FFmpeg 函數庫

Windows XP Visual Studio 2010 安裝使用 FFmpeg 函數庫:

由於 OpenCV 主要是針對圖像處理,在使用 WebCam 上的視頻編碼和解碼上有不足,特別在 M-JPEG Motion-JPEG)上,所以要試驗另外一個視頻庫 FFmpegFast Forward MPEG),FFmpeg 是一個基於 LGPL GPL 許可下免費軟件,FFmpeg 是完整及跨平台的錄製,轉換和串流音頻和視頻庫,主要用他來處理視頻內容,而且 M-JPEG over HTTP 是非常簡單實現,基本上祇要通知客戶端使用一個特殊的 mime-type 內容類型的 multipart/x-mixed-replace;boundary= informs,並發送一系列的分隔的 JPEG 文件,客戶端保持連接開啓,便可以不停地發送圖像。


FFmpeg 視頻庫組件: 
Libavcodec - 包含了所有 FFmpeg 的音頻/視頻編碼器和解碼器。 
Libav - 包含音頻/視頻容器格式的分路器和 muxers 的。 
Libavutil - 其中包含常見的不同部位的 ffmpeg 的例程。 
Libpostproc - 包含視頻後期處理例程。
Libswscale - 包含視頻圖像縮放程序。 
Libavfilter - 代替 vhook 它允許被修改或檢查視頻的解碼器和編碼器之間。 

FFmpeg 安裝:
1. 下載 OpenCV 2.4 檔案
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.0/OpenCV-2.4.0.exe/download
2. 打開 C:\OpenCV2.4\opencv \CMakeLists.txt,加入 set(HAVE_FFMPEG 1)
3. C:\OpenCV2.4\opencv\3rdpaty\include\ffmpeg_\libavformat\avformat.h,加入 #define INT64_C
4. C:\OpenCV2.4\opencv\modules\highgui\src\cap_ffmpeg_impl.hpp,加入 #define snprintf _snprintf
5. 下載 FFmpeg 檔案,然後將 FFmpeg 檔案解壓放在 C:\FFMPEG
http://ffmpeg.zeranoe.com/builds/win32/dev/ffmpeg-20130329-git-551f683-win32-dev.7z


6. C/C++/C# 專案(Project)專案 → 屬性 → VC++目錄 → Include目錄(Additional Include Directories),加入C:\FFMPEG
專案 → 屬性→ VC++目錄 → Include目錄 → 編輯
7. C/C++/C# 專案(Project)專案→屬性→連結器→一般→其他程式庫目錄
Linker>General>Additional Library Dependencies),加入 C:\FFMPEG

連結器 → 輸入→ 其他相依性 → 編輯
8. C/C++/C# 專案(Project)專案→屬性→連結器→輸入→其他相依性
Linker>Input>Additional Dependencies),加入 avformat.lib, avscale.lib, avcore.lib

連結器 → 輸入→ 其他相依性 → 編輯
9. Visual Studio 2010 中建立 VC++ Win32 主控台應用程式,編寫 FFmpeg_webcam.cpp 程式。

FFmpeg_webcam.cpp 程式:
// opencv_webcam.cpp : 定義主控台應用程式的進入點。
//
#include "stdafx.h"
#include
#include
#include

int main()
{
    CvCapture *capture;
    IplImage *frame;

    capture=cvCreateCameraCapture(0);
    cvNamedWindow("Webcam",0);

    CvVideoWriter *writer;
    char AviFileName[]="Output.avi";
    int AviForamt = -1;
    int FPS = 25;
    CvSize AviSize = cvSize(640,480);
    int AviColor = 1;
    writer=cvCreateVideoWriter(AviFileName,AviForamt,FPS,AviSize,AviColor);

    int i=0;
    while(true)
    {
        frame = cvQueryFrame(capture);
        cvWriteFrame(writer,frame);

        cvShowImage("Webcam",frame);
        printf("%dn",i);

        if(cvWaitKey(20)>0)     break;
        i++;
    }

    cvReleaseCapture(&capture);
    cvReleaseVideoWriter(&writer);
    cvDestroyWindow("Webcam");
}

10. 執行程式顯示 Webcam 攝影圖像(Ctrl-F5
偵錯 啓動但不偵錯(Ctrl+F5
相關網址:
※ 在 Windows XP Visual Studio 2010 安裝 OpenCV 2.4
※ 在 Windows XP Visual Studio 2010 使用 OpenCV 2.4 第一個程式
※ 在 Windows XP Visual Studio 2010 使用 OpenCV 2.4 使用 WebCam
※ 在 Windows XP Visual Studio 2010 安裝使用 FFmpeg 函數庫
※ 在 Windows XP Visual Studio 2010 使用 OpenCV 2.4 使用 WebCam
※ 在 Windows XP Visual Studio 2010 使用 OpenCV 2.4 顯示 IPCam 串流視頻
※ 在 Windows XP Visual Studio 2010 使用 OpenCV 2.4 導入屬性工作表文件檔
※ 在 Windows XP Visual Studio 2010 使用 Windows From OpenCV 2.4 配置
※ 在 OpenCV 2.4 的 IplImage 資料結構
※ OpenCV 2.4 的坎尼圖像邊緣檢測(Canny Edge Detection) – Canny 函數
※ OpenCV 2.4 的霍夫直線偵測轉換 – HoughLines 函數
※ OpenCV 2.4 的霍夫直線偵測轉換 – HoughLinesP 函數
※ OpenCV 2.4 的人臉偵測(Face Detection)– cvHaarDetectObjects 函數
※ OpenCV 2.4 的物件偵測(Object Detection)– cvHoughCircles 函數
※ OpenCV 2.4 的物件追蹤(Object Tracking)– cvMoments 函數

參考網址: 
FFmpeg

2013329 天氣報告
氣溫:20.7 @ 23:00
相對濕度:百分之92%
天氣:微雨

沒有留言:

張貼留言