MediaInfo is an open-source tool for obtaining video or audio information. It comes with a GUI that allows you to conveniently view video information. However, when writing some transcoding programs, we often need to obtain video information in the program.
Previously, I often used mediainfo.exe via a command line. The -- Output = XML parameter is used to Output mediainfo.exe as an XML file, and then the video information is obtained by parsing the XML file. Although this conventional approach is relatively simple, it is complicated if there are many attributes to be parsed. You want to directly call the api interface in MediaInfo. dll to directly obtain its attributes.
Although MediaInfo is open-source, it cannot be directly used in C # because it is not written in. net, but it can still be called through Pinvoke. However, Nuget already has such encapsulated libraries for our direct use:
I tried this package for a while, but I don't know why the author is not used to the attribute in the lower-case mode. Find another library MediaInfoNET on Sourceforge. The address of this library is as follows: http://teejeetech.blogspot.com/2013/01/mediainfo-wrapper-for-net-projects.html. However, because President Fang was uncomfortable reading this address, he could only access this website on Mars. Therefore, I copied the original example and used it very easily:
Static
Void Main (string [] args)
{
MediaFile aviFile = new
MediaFile (@ "r: \ test. avi ");
Console. WriteLine ();
Console. WriteLine ("General ---------------------------------");
Console. WriteLine ();
Console. WriteLine ("File Name: {0}", aviFile. Name );
Console. WriteLine ("Format: {0}", aviFile. General. Format );
Console. WriteLine ("Duration: {0}", aviFile. General. DurationString );
Console. WriteLine ("Bitrate: {0}", aviFile. General. Bitrate );
If (aviFile. Audio. Count> 0)
{
Console. WriteLine ();
Console. WriteLine ("Audio ---------------------------------");
Console. WriteLine ();
Console. WriteLine ("Format: {0}", aviFile. Audio [0]. Format );
Console. WriteLine ("Bitrate: {0}", aviFile. Audio [0]. Bitrate. ToString ());
Console. WriteLine ("Channels: {0}", aviFile. Audio [0]. Channels. ToString ());
Console. WriteLine ("Sampling: {0}", aviFile. Audio [0]. SamplingRate. ToString ());
}
If (aviFile. Video. Count> 0)
{
Console. WriteLine ();
Console. WriteLine ("Video ---------------------------------");
Console. WriteLine ();
Console. WriteLine ("Format: {0}", aviFile. Video [0]. Format );
Console. WriteLine ("Bit rate: {0}", aviFile. Video [0]. Bitrate. ToString ());
Console. WriteLine ("Frame rate: {0}", aviFile. Video [0]. FrameRate. ToString ());
Console. WriteLine ("Frame size: {0}", aviFile. Video [0]. FrameSize. ToString ());
}
Console. ReadLine ();
}
This library does not seem to be released on Nuget. It would be easier for the author to upload it to Nuget.