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. Data Base sql server 备份数据库

    sql server 备份数据库 1.维护计划向导: 右键维护计划-维护计划向导-然后安装提示: 勾选自己要干的事,比如:完整备份数据库.差异备份数据库等等 2.作业计划: 如下图: SQL Serv ...

  2. 简单配置webpack4 + vue

    1.创建webpack4-vue文件夹 mkdir webpack4-vue && cd webpack4-vue 2.初始化npm npm init -y 3.安装相关依赖 npm ...

  3. vue 路由里面的 hash 和 history

    对于 Vue 这类渐进式前端开发框架,为了构建 SPA(单页面应用),需要引入前端路由系统,这也就是 Vue-Router 存在的意义.前端路由的核心,就在于 —— 改变视图的同时不会向后端发出请求. ...

  4. Apache Spark

    1. 用Apache Spark进行大数据处理——第一部分:入门介绍 2.

  5. ThreadLocalRandom原理

    原文链接:https://www.jianshu.com/p/9c2198586f9b 2.2. 并发包中ThreadLocalRandom类原理剖析 ThreadLocalRandom类是JDK7在 ...

  6. kuangbin专题七 HDU1754 I Hate It (单点修改维护最大值)

    很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师有 ...

  7. Unity组件

    在学习C++的时候,对于面对对象有点了解.然后也使用过一段时间的Unity,用起来还是觉得,怎么这么好用.耦合性极低.当时不知道这是基于组件编程.所以现在来学习下基于组件的知识,并比较下基于组件和基于 ...

  8. doors dxl 遍历object 查找

    Module m = current; //m = edit(“xxx”) Object o for o in m do { string sht = o.”shtName” Buffer bf=cr ...

  9. Github如何在Linux系统下创建本地仓库

    一.电脑上安装 Git Ubuntu安装GIt:  apt-get install git 查看版本信息:    git version 配置Git用户信息  输入: git config --glo ...

  10. P3802 小魔女帕琪

    传送门 考虑前面7个魔法 如果前面七个魔法各不相同,那么就能完成一次帕琪七重奏 设 A=a1*a2*...*a7,S=a1+a2+...+a7,B=S*(S-1)*...*(S-6) 对于不同的施法顺 ...