1.将MediaInfo.dll放入可执行目录。

2.将官网Demo里的MediaInfoDLL.cs放入项目中。(http://mediainfo.sourceforge.net/en/Download/Windows有官方的示例代码,你也可以到讨论区http://sourceforge.net/projects/mediainfo/forums/forum/297610
http://code.google.com/hosting/search?q=mediainfo&projectsearch=Search+projects
上也有很多基于mediainfo的开发项目)

/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Microsoft Visual C# wrapper for MediaInfo Library
// See MediaInfo.h for help
//
// To make it working, you must put MediaInfo.Dll
// in the executable folder
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ using System;
using System.Runtime.InteropServices; #pragma warning disable 1591 // Disable XML documentation warnings namespace MediaInfoLib
{
public enum StreamKind
{
General,
Video,
Audio,
Text,
Other,
Image,
Menu,
} public enum InfoKind
{
Name,
Text,
Measure,
Options,
NameText,
MeasureText,
Info,
HowTo
} public enum InfoOptions
{
ShowInInform,
Support,
ShowInSupported,
TypeOfValue
} public enum InfoFileOptions
{
FileOption_Nothing = 0x00,
FileOption_NoRecursive = 0x01,
FileOption_CloseAll = 0x02,
FileOption_Max = 0x04
}; public enum Status
{
None = 0x00,
Accepted = 0x01,
Filled = 0x02,
Updated = 0x04,
Finalized = 0x08,
} public class MediaInfo
{
//Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory)
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_New();
[DllImport("MediaInfo.dll")]
private static extern void MediaInfo_Delete(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Open(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string FileName);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_Open(IntPtr Handle, IntPtr FileName);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Open_Buffer_Init(IntPtr Handle, Int64 File_Size, Int64 File_Offset);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_Open(IntPtr Handle, Int64 File_Size, Int64 File_Offset);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Open_Buffer_Continue(IntPtr Handle, IntPtr Buffer, IntPtr Buffer_Size);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_Open_Buffer_Continue(IntPtr Handle, Int64 File_Size, byte[] Buffer, IntPtr Buffer_Size);
[DllImport("MediaInfo.dll")]
private static extern Int64 MediaInfo_Open_Buffer_Continue_GoTo_Get(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern Int64 MediaInfoA_Open_Buffer_Continue_GoTo_Get(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Open_Buffer_Finalize(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_Open_Buffer_Finalize(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern void MediaInfo_Close(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Inform(IntPtr Handle, IntPtr Reserved);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_Inform(IntPtr Handle, IntPtr Reserved);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_GetI(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_GetI(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Get(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, [MarshalAs(UnmanagedType.LPWStr)] string Parameter, IntPtr KindOfInfo, IntPtr KindOfSearch);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_Get(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo, IntPtr KindOfSearch);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Option(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string Option, [MarshalAs(UnmanagedType.LPWStr)] string Value);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoA_Option(IntPtr Handle, IntPtr Option, IntPtr Value);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_State_Get(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_Count_Get(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber); //MediaInfo class
public MediaInfo()
{
try
{
Handle = MediaInfo_New();
}
catch
{
Handle = (IntPtr);
}
if (Environment.OSVersion.ToString().IndexOf("Windows") == -)
MustUseAnsi=true;
else
MustUseAnsi=false;
}
~MediaInfo() { if (Handle == (IntPtr)) return; MediaInfo_Delete(Handle); }
public int Open(String FileName)
{
if (Handle == (IntPtr))
return ;
if (MustUseAnsi)
{
IntPtr FileName_Ptr = Marshal.StringToHGlobalAnsi(FileName);
int ToReturn = (int)MediaInfoA_Open(Handle, FileName_Ptr);
Marshal.FreeHGlobal(FileName_Ptr);
return ToReturn;
}
else
return (int)MediaInfo_Open(Handle, FileName);
}
public int Open_Buffer_Init(Int64 File_Size, Int64 File_Offset)
{
if (Handle == (IntPtr)) return ; return (int)MediaInfo_Open_Buffer_Init(Handle, File_Size, File_Offset);
}
public int Open_Buffer_Continue(IntPtr Buffer, IntPtr Buffer_Size)
{
if (Handle == (IntPtr)) return ; return (int)MediaInfo_Open_Buffer_Continue(Handle, Buffer, Buffer_Size);
}
public Int64 Open_Buffer_Continue_GoTo_Get()
{
if (Handle == (IntPtr)) return ; return (Int64)MediaInfo_Open_Buffer_Continue_GoTo_Get(Handle);
}
public int Open_Buffer_Finalize()
{
if (Handle == (IntPtr)) return ; return (int)MediaInfo_Open_Buffer_Finalize(Handle);
}
public void Close() { if (Handle == (IntPtr)) return; MediaInfo_Close(Handle); }
public String Inform()
{
if (Handle == (IntPtr))
return "Unable to load MediaInfo library";
if (MustUseAnsi)
return Marshal.PtrToStringAnsi(MediaInfoA_Inform(Handle, (IntPtr)));
else
return Marshal.PtrToStringUni(MediaInfo_Inform(Handle, (IntPtr)));
}
public String Get(StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo, InfoKind KindOfSearch)
{
if (Handle == (IntPtr))
return "Unable to load MediaInfo library";
if (MustUseAnsi)
{
IntPtr Parameter_Ptr=Marshal.StringToHGlobalAnsi(Parameter);
String ToReturn=Marshal.PtrToStringAnsi(MediaInfoA_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter_Ptr, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch));
Marshal.FreeHGlobal(Parameter_Ptr);
return ToReturn;
}
else
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch));
}
public String Get(StreamKind StreamKind, int StreamNumber, int Parameter, InfoKind KindOfInfo)
{
if (Handle == (IntPtr))
return "Unable to load MediaInfo library";
if (MustUseAnsi)
return Marshal.PtrToStringAnsi(MediaInfoA_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo));
else
return Marshal.PtrToStringUni(MediaInfo_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo));
}
public String Option(String Option, String Value)
{
if (Handle == (IntPtr))
return "Unable to load MediaInfo library";
if (MustUseAnsi)
{
IntPtr Option_Ptr=Marshal.StringToHGlobalAnsi(Option);
IntPtr Value_Ptr=Marshal.StringToHGlobalAnsi(Value);
String ToReturn=Marshal.PtrToStringAnsi(MediaInfoA_Option(Handle, Option_Ptr, Value_Ptr));
Marshal.FreeHGlobal(Option_Ptr);
Marshal.FreeHGlobal(Value_Ptr);
return ToReturn;
}
else
return Marshal.PtrToStringUni(MediaInfo_Option(Handle, Option, Value));
}
public int State_Get() { if (Handle == (IntPtr)) return ; return (int)MediaInfo_State_Get(Handle); }
public int Count_Get(StreamKind StreamKind, int StreamNumber) { if (Handle == (IntPtr)) return ; return (int)MediaInfo_Count_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber); }
private IntPtr Handle;
private bool MustUseAnsi; //Default values, if you know how to set default values in C#, say me
public String Get(StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo) { return Get(StreamKind, StreamNumber, Parameter, KindOfInfo, InfoKind.Name); }
public String Get(StreamKind StreamKind, int StreamNumber, String Parameter) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text, InfoKind.Name); }
public String Get(StreamKind StreamKind, int StreamNumber, int Parameter) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text); }
public String Option(String Option_) { return Option(Option_, ""); }
public int Count_Get(StreamKind StreamKind) { return Count_Get(StreamKind, -); }
} public class MediaInfoList
{
//Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory)
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_New();
[DllImport("MediaInfo.dll")]
private static extern void MediaInfoList_Delete(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_Open(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string FileName, IntPtr Options);
[DllImport("MediaInfo.dll")]
private static extern void MediaInfoList_Close(IntPtr Handle, IntPtr FilePos);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_Inform(IntPtr Handle, IntPtr FilePos, IntPtr Reserved);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_GetI(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_Get(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber, [MarshalAs(UnmanagedType.LPWStr)] string Parameter, IntPtr KindOfInfo, IntPtr KindOfSearch);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_Option(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string Option, [MarshalAs(UnmanagedType.LPWStr)] string Value);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_State_Get(IntPtr Handle);
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfoList_Count_Get(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber); //MediaInfo class
public MediaInfoList() { Handle = MediaInfoList_New(); }
~MediaInfoList() { MediaInfoList_Delete(Handle); }
public int Open(String FileName, InfoFileOptions Options) { return (int)MediaInfoList_Open(Handle, FileName, (IntPtr)Options); }
public void Close(int FilePos) { MediaInfoList_Close(Handle, (IntPtr)FilePos); }
public String Inform(int FilePos) { return Marshal.PtrToStringUni(MediaInfoList_Inform(Handle, (IntPtr)FilePos, (IntPtr))); }
public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo, InfoKind KindOfSearch) { return Marshal.PtrToStringUni(MediaInfoList_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch)); }
public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, int Parameter, InfoKind KindOfInfo) { return Marshal.PtrToStringUni(MediaInfoList_GetI(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)); }
public String Option(String Option, String Value) { return Marshal.PtrToStringUni(MediaInfoList_Option(Handle, Option, Value)); }
public int State_Get() { return (int)MediaInfoList_State_Get(Handle); }
public int Count_Get(int FilePos, StreamKind StreamKind, int StreamNumber) { return (int)MediaInfoList_Count_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber); }
private IntPtr Handle; //Default values, if you know how to set default values in C#, say me
public void Open(String FileName) { Open(FileName, ); }
public void Close() { Close(-); }
public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo) { return Get(FilePos, StreamKind, StreamNumber, Parameter, KindOfInfo, InfoKind.Name); }
public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, String Parameter) { return Get(FilePos, StreamKind, StreamNumber, Parameter, InfoKind.Text, InfoKind.Name); }
public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, int Parameter) { return Get(FilePos, StreamKind, StreamNumber, Parameter, InfoKind.Text); }
public String Option(String Option_) { return Option(Option_, ""); }
public int Count_Get(int FilePos, StreamKind StreamKind) { return Count_Get(FilePos, StreamKind, -); }
} } //NameSpace

MediaInfoDLL.cs

---- 以下2 个参考看

/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Microsoft Visual C# example
//
// To make this example working, you must put MediaInfo.Dll and Example.ogg
// in the "./Bin/__ConfigurationName__" folder
// and add MediaInfoDll.cs to your project
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.IO;
using MediaInfoLib; namespace MediaInfoLib_MSCS
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Methode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(, );
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(, );
this.richTextBox1.TabIndex = ;
this.richTextBox1.Text = "";
//
// Form1
//
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.richTextBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "How to use MediaInfo.Dll";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary> [STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
//Test if version of DLL is compatible : 3rd argument is "version of DLL tested;Your application name;Your application version"
String ToDisplay;
MediaInfo MI = new MediaInfo(); ToDisplay = MI.Option("Info_Version", "0.7.0.0;MediaInfoDLL_Example_CS;0.7.0.0");
if (ToDisplay.Length == )
{
richTextBox1.Text = "MediaInfo.Dll: this version of the DLL is not compatible";
return;
} //Information about MediaInfo
ToDisplay += "\r\n\r\nInfo_Parameters\r\n";
ToDisplay += MI.Option("Info_Parameters"); ToDisplay += "\r\n\r\nInfo_Capacities\r\n";
ToDisplay += MI.Option("Info_Capacities"); ToDisplay += "\r\n\r\nInfo_Codecs\r\n";
ToDisplay += MI.Option("Info_Codecs"); //An example of how to use the library
ToDisplay += "\r\n\r\nOpen\r\n";
MI.Open("Example.ogg"); ToDisplay += "\r\n\r\nInform with Complete=false\r\n";
MI.Option("Complete");
ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nInform with Complete=true\r\n";
MI.Option("Complete", "");
ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nCustom Inform\r\n";
MI.Option("Inform", "General;File size is %FileSize% bytes");
ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='FileSize'\r\n";
ToDisplay += MI.Get(, , "FileSize"); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter=46\r\n";
ToDisplay += MI.Get(, , ); ToDisplay += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
ToDisplay += MI.Count_Get(StreamKind.Audio); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n";
ToDisplay += MI.Get(StreamKind.General, , "AudioCount"); ToDisplay += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n";
ToDisplay += MI.Get(StreamKind.Audio, , "StreamCount"); ToDisplay += "\r\n\r\nClose\r\n";
MI.Close(); //Example with a stream
//ToDisplay+="\r\n"+ExampleWithStream()+"\r\n"; //Displaying the text
richTextBox1.Text = ToDisplay;
} String ExampleWithStream()
{
//Initilaizing MediaInfo
MediaInfo MI = new MediaInfo(); //From: preparing an example file for reading
FileStream From = new FileStream("Example.ogg", FileMode.Open, FileAccess.Read); //From: preparing a memory buffer for reading
byte[] From_Buffer = new byte[*];
int From_Buffer_Size; //The size of the read file buffer //Preparing to fill MediaInfo with a buffer
MI.Open_Buffer_Init(From.Length, ); //The parsing loop
do
{
//Reading data somewhere, do what you want for this.
From_Buffer_Size = From.Read(From_Buffer, , * ); //Sending the buffer to MediaInfo
System.Runtime.InteropServices.GCHandle GC = System.Runtime.InteropServices.GCHandle.Alloc(From_Buffer, System.Runtime.InteropServices.GCHandleType.Pinned);
IntPtr From_Buffer_IntPtr = GC.AddrOfPinnedObject();
Status Result = (Status)MI.Open_Buffer_Continue(From_Buffer_IntPtr, (IntPtr)From_Buffer_Size);
GC.Free();
if ((Result & Status.Finalized) == Status.Finalized)
break; //Testing if MediaInfo request to go elsewhere
if (MI.Open_Buffer_Continue_GoTo_Get() != -)
{
Int64 Position = From.Seek(MI.Open_Buffer_Continue_GoTo_Get(), SeekOrigin.Begin); //Position the file
MI.Open_Buffer_Init(From.Length, Position); //Informing MediaInfo we have seek
}
}
while (From_Buffer_Size > ); //Finalizing
MI.Open_Buffer_Finalize(); //This is the end of the stream, MediaInfo must finnish some work //Get() example
return "Container format is " + MI.Get(StreamKind.General, , "Format");
}
}
}

HowToUse_Dll

/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Microsoft Visual C# example
//
// To make this example working, you must put MediaInfo.Dll and Example.ogg
// in the "./Bin/__ConfigurationName__" folder
// and add MediaInfoDll.cs to your project
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ using System;
using MediaInfoLib; namespace MediaInfoLib_MSCS
{
public class CLI
{
[STAThread]
static void Main(string[] Args)
{
String ToDisplay;
MediaInfo MI = new MediaInfo(); ToDisplay = MI.Option("Info_Version", "0.7.0.0;MediaInfoDLL_Example_CS;0.7.0.0");
if (ToDisplay.Length == )
{
Console.Out.WriteLine("MediaInfo.Dll: this version of the DLL is not compatible");
return;
} //Information about MediaInfo
ToDisplay += "\r\n\r\nInfo_Parameters\r\n";
ToDisplay += MI.Option("Info_Parameters"); ToDisplay += "\r\n\r\nInfo_Capacities\r\n";
ToDisplay += MI.Option("Info_Capacities"); ToDisplay += "\r\n\r\nInfo_Codecs\r\n";
ToDisplay += MI.Option("Info_Codecs"); //An example of how to use the library
ToDisplay += "\r\n\r\nOpen\r\n";
String File_Name;
if (Args.Length == )
File_Name = "Example.ogg";
else
File_Name = Args[];
MI.Open(File_Name); ToDisplay += "\r\n\r\nInform with Complete=false\r\n";
MI.Option("Complete");
ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nInform with Complete=true\r\n";
MI.Option("Complete", "");
ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nCustom Inform\r\n";
MI.Option("Inform", "General;File size is %FileSize% bytes");
ToDisplay += MI.Inform(); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='FileSize'\r\n";
ToDisplay += MI.Get(, , "FileSize"); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter=46\r\n";
ToDisplay += MI.Get(, , ); ToDisplay += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
ToDisplay += MI.Count_Get(StreamKind.Audio); ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n";
ToDisplay += MI.Get(StreamKind.General, , "AudioCount"); ToDisplay += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n";
ToDisplay += MI.Get(StreamKind.Audio, , "StreamCount"); ToDisplay += "\r\n\r\nClose\r\n";
MI.Close(); //Displaying the text
Console.Out.WriteLine(ToDisplay);
}
}
}

HowToUse_Dll_CLI.cs

---

3.接下来是调用了。

//0.视频StreamKind.Video,音频参数StreamKind.Audio,全局参数StreamKind.General Parameter
MediaInfo MI = new MediaInfo();
MI.Open("E:\\Downloads\\测试音频03.mp3");
//1.
string width = MI.Get(StreamKind.Video, , "Width");//视频width
string height = MI.Get(StreamKind.Video, , "Height");
string s1 = MI.Inform();
//2.
MI.Option("Inform", "General;%Duration%");
string durationL = MI.Inform();
//3.
//MI.Option("Info_Parameters");
string s = MI.Get(StreamKind.Audio, , "Duration");//音频时长
MI.Close();
//4.
StringBuilder sb = new StringBuilder();
sb.Append("用mediainfo.dll计算时长:" + TimeSpan.FromMilliseconds(Convert.ToDouble(s)));

出现"Unable to load MediaInfo library",肯能是DLL 不成功,(可能版本高或者注册下)

4.由MI.Get(StreamKind.Video, 0, "Width")这个函数调用方式可知,我们想查询视频宽度,直接使用width参数就行了,但是视频、音频有大量的参数,我们不可以都猜的到,网上反正我没找到这些参数的介绍,幸好找到了一个方法可以把这些方法遍历出来,参数出来了,就好办了,不明白意思的话google下,基本上就可以把全部参数弄懂了。

// 遍历Video所有可有参数
//如果要遍历Audio的参数,StreamKind.Video换成StreamKind.Audio即可,General同理。
string parameter="";//存放所有参数
string tempstr;int i=;
while (true)
{
tempstr = MI.Get(StreamKind.Video, , i++, InfoKind.Name);
if (tempstr == "")
{
break;
}
parameter += "\r\n" + tempstr;
}

获取参数

转  获取参数:http://www.cnblogs.com/royzou/archive/2011/09/06/mediainfo_parameter.html

http://www.cnblogs.com/dudu837/p/4534350.html

http://www.cnblogs.com/grenet/p/3222731.html

C#使用MediaInfo查看媒体信息的更多相关文章

  1. FFmpeg命令行工具学习(一):查看媒体文件头信息工具ffprobe

    一.简述 ffprobe是ffmpeg命令行工具中相对简单的,此命令是用来查看媒体文件格式的工具. 二.命令格式 在命令行中输入如下格式的命令: ffprobe [文件名] 三.使用ffprobe查看 ...

  2. Android之使用MediaMetadataRetriever类获取媒体信息

    一.昨天.介绍了使用MediaMetadataRetriever类来获取视频第一帧:http://blog.csdn.net/u012561176/article/details/47858099,今 ...

  3. you-get 下载网络上的富媒体信息

    You-Get 乃一小小哒命令行程序,提供便利的方式,下载网络上的富媒体信息. 利用you-get下载这个网页的视频: $ you-get http://www.fsf.org/blogs/rms/2 ...

  4. Linux常见查看硬件信息指令

    CPUlscpu 查看的是CPU的统计信息./proc/cpuinfo 查看每个cpu信息,如每个CPU的型号,主频等. 内存free -m 概要查看内存情况cat /proc/meminfo 查看内 ...

  5. Linux下如何查看版本信息

    Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然.   1.# uname -a   (Linux查看版本当前操作系统内核信息)   L ...

  6. Sql Server之使用T_SQL创建,修改,查看数据库信息

    一.使用Transact_SQL创建数据库 Transact_SQL语法如下:  create database database_name   [ on     [primary]  [<fi ...

  7. Liunx下查看服务器硬件信息

    一.如何查看服务器的CPU 今天安装了9台Linux服务器,型号完全不一样(有DELL. HP和IBM服务器),又懒得去对清单,如何在Linux下cpu的个数和核数呢?另外,nginx的cpu工作模式 ...

  8. Ubuntu下查看机器信息

    原文地址 测试机器的硬件信息 查看CPU信息(看到有8个逻辑CPU, 也知道了CPU型号)   # cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq ...

  9. FreeBSD 查看硬件信息

    systat 能实时查看各种信息 systat -pigs 默认值CPU systat -iostat 硬盘IO systat -swap 交换分区 systat -mbufs 网络缓冲区 systa ...

随机推荐

  1. access + vb + asp 遇到一些问题的总结

    Data Base access + vb + asp  遇到一些问题的总结 1.asp中sql语句: select * from users whre name=’张三‘ and addTime=# ...

  2. TensorFlow创建变量

    1 使用tf.Variable函数创建变量 tf.Variable(initial_value=None,trainable=True,collections=None,validate_shape= ...

  3. 【转】php通过curl跨域向asp.net服务器上传文件及参数

    转:http://blog.sina.com.cn/s/blog_13331dce50102vq32.html 这是一个由php通过调用asp.net接口向asp.net服务器post上传文件及参数并 ...

  4. BFS【bzoj1667】: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛

    1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛 Description 经过跟Farmer John长达数年的谈判,奶牛们终于如愿以偿地得到了想要的旱冰鞋.农场上大 ...

  5. 最短路【洛谷P1606】 [USACO07FEB]荷叶塘Lilypad Pond

    P1606 [USACO07FEB]荷叶塘Lilypad Pond 为了让奶牛们娱乐和锻炼,农夫约翰建造了一个美丽的池塘.这个长方形的池子被分成了M行N列个方格(1≤M,N≤30).一些格子是坚固得令 ...

  6. CF580C Kefa and Park dfs

    Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual pa ...

  7. for循环删除list中多个元素出现的误区

    错误的做法是: for(int i= 0;i<list.size();i++) 因为在你删除元素的同时list.size()也在变小,这样就会照成越界. 正确做法:因为要删除list里面的多个的 ...

  8. 说Gradle

      说Gradle 刚开始认识Gradle这个名词是在蘑菇街的一场 交流会上,当时只是一个概念:第二面,是试图下载编译spring源码的时候:第三面,就是我司较真的安卓主程,有一天兴高彩烈的跟我说,我 ...

  9. spring boot app

    一个demo  可以参考一下 AppConfig @Configuration @ComponentScan(basePackages = { "org.whm.test" }) ...

  10. C#学习之按钮点击事件

    描述:asp.net中服务器控件Button的点击事件OnClientClick和OnClick的区别? 解答:http://www.cnblogs.com/ypfnet/archive/2012/1 ...