生活随笔
收集整理的這篇文章主要介紹了
MediaInfo在VS2019下的编译和使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 準備工作
- MediaInfo編譯
- MediaInfo的使用
- 相關資源下載
準備工作
下載源碼 下載地址
MediaInfo編譯
將下載好的壓縮包進行解壓,用VS打開MediaInfoLib.sln,生成解決方案(我選擇的是Release版本,64位)
此時出現報錯
打開Visual Studio Installer,點擊修改,勾選最新版本的SDK,進行更新。
更新完畢,重新打開項目,點擊項目→重定解決方案,選擇剛才下載的Windows SDK
點擊生成→重新生成解決方案,成功
現在vs項目目錄下會出現編譯好的MediaInfo.dll和MediaInfo.lib文件
在Source/MediaInfoDLL目錄下找到需要引入到我們自己項目中的MediaInfoDLL.h文件
MediaInfo的使用
我的需求是在Qt項目中使用MediaInfo,看了不少文章,在vs項目中都是直接include頭文件,添加lib和dll,再聲明命名空間就可以使用MediaInfo類,但我直接在Qt里面這樣做會報錯,具體什么原因沒有找到,但參考某位大佬的博文,對MediaInfo類進行封裝,就可以正常使用了。
首先,先把MediaInfo.dll添加到應用程序所在的路徑下(這個路徑具體是哪里因個人設定而異),
其次,將MediaInfo.lib放到你想放的位置,然后在.pro文件中用LIBS +=語句引入,這里我還是將lib文件放到應用程序所在的目錄
最后,將MediaInfoDLL.h文件放到你想要的位置,并在.pro文件中引入這個文件或者這個文件所在的文件夾,這里我用INCLUDEPATH += 語句將MediaInfoDLL.h所在的目錄引入,那么這個目錄下的所有.h文件都會被包含進來
做完這些工作,還需要實現一個MediaInfoHelper類來對MediaInfo進行封裝才能使用,以下的代碼是參考這位大佬的 原文指路
#ifndef MEDIAINFOHELPER_H
#define MEDIAINFOHELPER_H#define _UNICODE #include "MediaInfoDLL.h"#ifdef MEDIAINFO_LIBRARY
#include "MediaInfo/MediaInfo.h"
#define MediaInfoNameSpace MediaInfoLib;
#else
#define MediaInfoNameSpace MediaInfoDLL;
#endif
#include <iostream>
#include <iomanip>
using namespace MediaInfoNameSpace
#ifdef __MINGW32__
#ifdef _UNICODE
#define _itot _itow
#else
#define _itot itoa
#endif
#endif #include <QString>
class HMediaInfoHelper
{struct HMediaInfo{int width
; int height
; int duration
; double frameRate
; double bitRate
; QString completeInfo
; HMediaInfo(){width
= 0;height
= 0;duration
= 0;frameRate
= 0.0;bitRate
= 0.0;}};
public:HMediaInfoHelper();HMediaInfo
GetMediaInfo(QString mediaFile
,int mediaType
= -1);
};#endif
#include "MediaInfoHelper.h"HMediaInfoHelper::HMediaInfoHelper()
{}HMediaInfoHelper
::HMediaInfo
HMediaInfoHelper::GetMediaInfo(QString mediaFile
, int mediaType
)
{HMediaInfo res
;MediaInfo MI
;auto temp
= mediaFile
.toStdWString();auto desFile
= temp
.c_str();MI
.Open(desFile
);MI
.Option(__T("Complete"), __T("1"));stream_t streamType
= Stream_General
;if (mediaType
== 0) {streamType
= Stream_Image
;} else if (mediaType
== 1) {streamType
= Stream_Video
;}else if(mediaType
== 2){streamType
= Stream_Audio
;} else {streamType
= Stream_General
;}auto comp
= QString::fromStdWString((std
::basic_string
<wchar_t>)MI
.Inform()); auto wid
= QString::fromStdWString((std
::basic_string
<wchar_t>)MI
.Get(streamType
, 0, __T("Width"))).toInt();auto hei
= QString::fromStdWString((std
::basic_string
<wchar_t>)MI
.Get(streamType
, 0, __T("Height"))).toInt();auto dur
= QString::fromStdWString((std
::basic_string
<wchar_t>)MI
.Get(streamType
, 0, __T("Duration"))).toInt();auto frameRate
= QString::fromStdWString((std
::basic_string
<wchar_t>)MI
.Get(streamType
, 0, __T("FrameRate"))).toDouble();auto bitRate
= QString::fromStdWString((std
::basic_string
<wchar_t>)MI
.Get(streamType
, 0, __T("BitRate"))).toDouble();MI
.Close();res
.completeInfo
= comp
;res
.width
= wid
;res
.height
= hei
;res
.duration
= dur
;res
.frameRate
= frameRate
;res
.bitRate
= bitRate
;return res
;
}
在需要使用MediaInfo功能的地方引入MediaInfoHelper頭文件,聲明HMediaInfoHelper對象即可
#include "MediaInfoHelper.h"
void main()
{HMediaInfoHelper helper
;auto info
= helper
.GetMediaInfo("D:/11111.mp4",1); return;
}
相關資源下載
【P.S】編譯環境為windows 10 VS2019,版本為64位Release
編譯好的dll、lib、h文件
【參考文章】
MediaInfo庫的編譯 使用
MediaInfo庫的使用
Qt使用MediaInfo庫獲取媒體文件分辨率時長等信息方法示例
總結
以上是生活随笔為你收集整理的MediaInfo在VS2019下的编译和使用的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。