Skip to main content

How to read file info?

Products: Video Capture SDK .Net, Video Edit SDK .Net, Media Player SDK .Net

Sample code

1. Create MediaInfoReader class object (VisioForge.Core assembly)

WinForms C# sample code. mmInfo is a TextBox.

var infoReader = new MediaInfoReader();

2. Check that file is playable (optional)

FilePlaybackError errorCode;
string errorText;

if (MediaInfoReader.IsFilePlayable(filename, out errorCode, out errorText))
{
mmInfo.Text += "This file is playable" + Environment.NewLine;
}
else
{
mmInfo.Text += "This file is not playable" + Environment.NewLine;
}

3. Read file information

infoReader.Filename = filename;
infoReader.ReadFileInfo(true);

for (int i = 0; i < infoReader.VideoStreams.Count; i++)
{
var stream = infoReader.VideoStreams[i];

mmInfo.Text += string.Empty + Environment.NewLine;
mmInfo.Text += "Video #" + Convert.ToString(i + 1) + Environment.NewLine;
mmInfo.Text += "Codec: " + stream.Codec + Environment.NewLine;
mmInfo.Text += "Duration: " + stream.Duration.ToString() + Environment.NewLine;
mmInfo.Text += "Width: " + stream.Width + Environment.NewLine;
mmInfo.Text += "Height: " + stream.Height + Environment.NewLine;
mmInfo.Text += "FOURCC: " + stream.FourCC + Environment.NewLine;
mmInfo.Text += "Aspect Ratio: " + $"{stream.AspectRatio.Item1}:{stream.AspectRatio.Item2}" + Environment.NewLine;
mmInfo.Text += "Frame rate: " + stream.FrameRate + Environment.NewLine;
mmInfo.Text += "Bitrate: " + stream.Bitrate + Environment.NewLine;
mmInfo.Text += "Frames count: " + stream.FramesCount + Environment.NewLine;
}

for (int i = 0; i < infoReader.AudioStreams.Count; i++)
{
var stream = infoReader.AudioStreams[i];

mmInfo.Text += string.Empty + Environment.NewLine;
mmInfo.Text += "Audio #" + Convert.ToString(i + 1) + Environment.NewLine;
mmInfo.Text += "Codec: " + stream.Codec + Environment.NewLine;
mmInfo.Text += "Codec info: " + stream.CodecInfo + Environment.NewLine;
mmInfo.Text += "Duration: " + stream.Duration.ToString() + Environment.NewLine;
mmInfo.Text += "Bitrate: " + stream.Bitrate + Environment.NewLine;
mmInfo.Text += "Channels: " + stream.Channels + Environment.NewLine;
mmInfo.Text += "Sample rate: " + stream.SampleRate + Environment.NewLine;
mmInfo.Text += "BPS: " + stream.BPS + Environment.NewLine;
mmInfo.Text += "Language: " + stream.Language + Environment.NewLine;
}

for (int i = 0; i < infoReader.Subtitles.Count; i++)
{
var stream = infoReader.Subtitles[i];

mmInfo.Text += string.Empty + Environment.NewLine;
mmInfo.Text += "Text #" + Convert.ToString(i + 1) + Environment.NewLine;
mmInfo.Text += "Codec: " + stream.Codec + Environment.NewLine;
mmInfo.Text += "Name: " + stream.Name + Environment.NewLine;
mmInfo.Text += "Language: " + stream.Language + Environment.NewLine;
}

4. Read tags using VFTagLibHelper (you can write tags using this class)

var tags = TagLibHelper.ReadTags(filename);
mmInfo.Text += tags?.ToString();

Required redists

  • Base redist

Visit our GitHub page to get more code samples.