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

来源:互联网 发布:太祖书法 知乎 编辑:程序博客网 时间:2024/06/06 09:04

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

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

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


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

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

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

[cpp] view plaincopy
  1. #include "MediaInfoDLL.h" //Dynamicly-loaded library (.dll or .so)  
  2. using namespace MediaInfoDLL;  
4.使用的时候声明一个MediaInfo对象就可以了

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

[cpp] view plaincopy
  1. MediaInfo MI;  
  2. CString width,height;  
  3. MI.Open("test.flv");  
  4. width = MI.Get(stream_t::Stream_Video,0,"Width").c_str();  
  5. height = MI.Get(stream_t::Stream_Video,0,"Height").c_str();  
  6. MI.Close();  

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

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

[cpp] view plaincopy
  1. MediaInfo MI;  
  2. CString all;  
  3. MI.Open("test.flv");  
  4. MI.Option("Complete");  
  5. all= MI.Inform().c_str();  
  6. 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();



0 0
原创粉丝点击