C++使用mediainfo

MediaInfo 用来分析视频和音频文件的编码和内容信息,是一款是自由软件 (免费使用、免费获得源代码)。

我在项目软件中集成了它的DLL,发现真的是非常好用!

下面简单记录一下它的使用方法。

(系统开发平台是VC2010)

1.将下载下来的MediaInfo.dll拷贝到可执行文件夹下

链接:https://pan.baidu.com/s/1pUwP0FNM2Xln7G_m73oetQ
提取码:1fab

2.拷贝MediaInfoDLL.h到项目目录

3.CPP文件中添加头文件和命名空间

#include <iostream>
#include <String>
#include "MediaInfoDLL.h"
using namespace MediaInfoDLL;
using namespace std;

int main(int argc, char** argv)
{
    MediaInfo MI;             //创建对象
    MI.Open(__T("D:/pr_material/11.mp4")); //打开一个音频或者视频文件,参数类型不是const char*,是个String类型,需要用__T字符集转换一下
    //D:/pr_material/video动感炫丽酒吧夜场VJ_1.mp4
    String toDisplay_CompleteInfo;
    String toDisPlay_Duration;
    String toDisPlay_AudioFormat;
    String toDisPlay_BitRate;

    MI.Option(__T("Complete")); //获取媒体的完全信息
    toDisplay_CompleteInfo = MI.Inform();

    wcout << toDisplay_CompleteInfo << endl;

    toDisPlay_Duration = MI.Get(stream_t::Stream_Video, 0, __T("Duration"));//获取视频的时长信息
    toDisPlay_AudioFormat = MI.Get(stream_t::Stream_Video, 0, __T("Format"));  //获取视频格式
    toDisPlay_BitRate = MI.Get(stream_t::Stream_Video, 0, __T("BitRate")); //获取视频码率

    wcout << toDisPlay_Duration << endl;
    wcout << toDisPlay_AudioFormat << endl;
    wcout << toDisPlay_BitRate << endl;

    MI.Close();  //关闭文件

    system("pause");
    return 0;
}

MediaInfo MI;
String width,height;
MI.Open("D:/pr_material/11.mp4"); 
width
= MI.Get(stream_t::Stream_Video,0,__T("Width")).c_str();
height = MI.Get(stream_t::Stream_Video,0,__T("Height")).c_str(); MI.Close();

width:720
height:1280

 

参考:https://blog.csdn.net/leixiaohua1020/article/details/11902195

posted @ 2021-08-29 23:29  为红颜  阅读(365)  评论(0编辑  收藏  举报