Code sample - How to read file info?

1. Create MediaInfoReader class object (VisioForge.Tools assembly). mmInfo is TextBox.

var infoReader = new MediaInfoReader();

2. Check that file is playable (optional).

VFFilePlaybackError 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.Video_Streams_Count(); i++)
{
                mmInfo.Text += string.Empty + Environment.NewLine;
                mmInfo.Text += "Video #" + Convert.ToString(i + 1) + Environment.NewLine;
                mmInfo.Text += "Codec: " + infoReader.Video_Codec(i) + Environment.NewLine;
                mmInfo.Text += "Duration: " + infoReader.Video_Duration(i) + Environment.NewLine;
                mmInfo.Text += "Width: " + infoReader.Video_Width(i) + Environment.NewLine;
                mmInfo.Text += "Height: " + infoReader.Video_Height(i) + Environment.NewLine;
                mmInfo.Text += "FOURCC: " + infoReader.Video_FourCC(i) + Environment.NewLine;
                mmInfo.Text += "Aspect Ratio: " + infoReader.Video_AspectRatioStr(i) + Environment.NewLine;
                mmInfo.Text += "Frame rate: " + infoReader.Video_FrameRate(i) + Environment.NewLine;
                mmInfo.Text += "Bitrate: " + infoReader.Video_Bitrate(i) + Environment.NewLine;
                mmInfo.Text += "Frames count: " + infoReader.Video_FramesCount(i) + Environment.NewLine;
}

for (int i = 0; i < infoReader.Audio_Streams_Count(); i++)
{
                mmInfo.Text += string.Empty + Environment.NewLine;
                mmInfo.Text += "Audio #" + Convert.ToString(i + 1) + Environment.NewLine;
                mmInfo.Text += "Codec: " + infoReader.Audio_Codec(i) + Environment.NewLine;
                mmInfo.Text += "Codec info: " + infoReader.Audio_CodecInfo(i) + Environment.NewLine;
                mmInfo.Text += "Duration: " + infoReader.Audio_Duration(i) + Environment.NewLine;
                mmInfo.Text += "Bitrate: " + infoReader.Audio_Bitrate(i) + Environment.NewLine;
                mmInfo.Text += "Channels: " + infoReader.Audio_Channels(i) + Environment.NewLine;
                mmInfo.Text += "Sample rate: " + infoReader.Audio_SampleRate(i) + Environment.NewLine;
                mmInfo.Text += "BPS: " + infoReader.Audio_BPS(i) + Environment.NewLine;
}

for (int i = 0; i < infoReader.Text_Streams_Count(); i++)
{
                mmInfo.Text += string.Empty + Environment.NewLine;
                mmInfo.Text += "Text #" + Convert.ToString(i + 1) + Environment.NewLine;
                mmInfo.Text += "Codec: " + infoReader.Text_Codec(i) + Environment.NewLine;
                mmInfo.Text += "Name: " + infoReader.Text_Name(i) + Environment.NewLine;
                mmInfo.Text += "Language: " + infoReader.Text_Language(i) + Environment.NewLine;
}

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

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

VisioForge © 2006-2019

  • GitHub-Mark-64px
  • Twitter Социальные Иконка
  • VisioForge Facebook page
  • YouTube channel