您的位置:首页 > 编程语言 > C语言/C++

C++中使用MediaInfo库获取视频信息

2014-08-27 21:48 393 查看
MediaInfo 用来分析视频和音频文件的编码和内容信息,是一款是自由软件 (免费使用、免费获得源代码)。

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

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

1.将下载下来的MediaInfo.dll拷贝到项目里面

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

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

[cpp] view
plaincopy

#include "MediaInfoDLL.h" //Dynamicly-loaded library (.dll or .so)

using namespace MediaInfoDLL;

4.使用的时候声明一个MediaInfo对象就可以了

例如,获得视频的宽和高,用Get():

[cpp] view
plaincopy

MediaInfo MI;

CString width,height;

MI.Open("test.flv");

width = MI.Get(stream_t::Stream_Video,0,"Width").c_str();

height = MI.Get(stream_t::Stream_Video,0,"Height").c_str();

MI.Close();

这里需要注意的是:width,height都是字符串,使用的时候需要转换

获得视频的完整信息,用Inform():

[cpp] view
plaincopy

MediaInfo MI;

CString all;

MI.Open("test.flv");

MI.Option("Complete");

all= MI.Inform().c_str();

MI.Close();

下载地址:http://download.csdn.net/detail/leixiaohua1020/6371889

General

Complete name (CompleteName) : cuc_ieschool.flv

Format : Flash Video

File size : 912 KiB

Duration : 34s 133ms

Overall bit rate : 219 Kbps

Tagging application : iku

Video

Format : AVC

Format/Info : Advanced Video Codec

Format profile : Main@L3.1

Format settings, CABAC : Yes

Format settings, ReFrames : 3 frames

Codec ID : 7

Duration : 34s 0ms

Bit rate : 179 Kbps

Nominal bit rate : 208 Kbps

Width : 512 pixels

Height : 288 pixels

Display aspect ratio : 16:9

Frame rate mode : Constant

Frame rate :15.000 fps

Color space : YUV

Chroma subsampling : 4:2:0

Bit depth : 8 bits

Scan type : Progressive

Bits/(Pixel*Frame) : 0.081

Stream size : 769 KiB (84%)

Writing library : x264 core 54

Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / ana

lyse=0x1:0x131 / me=hex / subme=6 / brdo=0 / mixed_ref=1 / me_range=16 / chroma_

me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / chroma_qp_offset=0 / slic

es=4 / nr=0 / decimate=1 / mbaff=0 / bframes=3 / b_pyramid=0 / b_adapt=1 / b_bia

s=0 / direct=1 / wpredb=1 / bime=0 / keyint=90 / keyint_min=25 / scenecut=40 / r

c=abr / bitrate=208 / ratetol=0.1 / rceq='blurCplx^(1-qComp)' / qcomp=0.60 / qpm

in=10 / qpmax=51 / qpstep=4 / ip_ratio=1.40 / pb_ratio=1.30

Audio

Format : AAC

Format/Info : Advanced Audio Codec

Format profile : HE-AAC / LC

Codec ID : 10

Duration : 34s 133ms

Bit rate : 30.2 Kbps

Channel(s) : 2 channels

Channel positions : Front: L R

Sampling rate : 44.1 KHz / 22.05 KHz

Compression mode : Lossy

Stream size : 137 KiB (15%)

如果字段是多个单词的例如 Complete name应该改成(CompleteName)---中间没有空格,单词首字母是大写

MI.Get(stream_t::Stream_Video,0,"Width").c_str();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: