Use MediaInfo in C # To obtain the attributes of a video or audio.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.