Table of Contents

Class MediaInfoReader

Namespace
VisioForge.Core.MediaInfo
Assembly
VisioForge.Core.dll

Provides comprehensive media file analysis capabilities using DirectShow and LibMediaInfo. This class can extract detailed information about video files including codec information, stream properties, duration, bitrates, and format-specific metadata. Supports a wide range of media formats including AVI, MP4, MKV, MPEG, WMV, and many others.

public class MediaInfoReader

Inheritance

Inherited Members

Constructors

MediaInfoReader(string, DSContext)

Initializes a new instance of the VisioForge.Core.MediaInfo.MediaInfoReader class with a specific DirectShow context. Use this constructor when you need to share a context across multiple operations or when you need custom logging/error handling.

public MediaInfoReader(string filename, DSContext context)

Parameters

filename string

The full path to the media file to analyze.

context DSContext

The DirectShow context for filter operations and logging.

MediaInfoReader(string)

Initializes a new instance of the VisioForge.Core.MediaInfo.MediaInfoReader class with a default context. This is the simplest constructor for basic media file analysis.

public MediaInfoReader(string filename)

Parameters

filename string

The full path to the media file to analyze.

MediaInfoReader()

Initializes a new instance of the VisioForge.Core.MediaInfo.MediaInfoReader class without a filename. Use this constructor when you need to set the filename later or when analyzing streams rather than files.

public MediaInfoReader()

Fields

Context

DirectShow context providing access to filters, logging, and DirectShow infrastructure. Used throughout the analysis process for filter graph operations.

protected DSContext Context

Field Value

DSContext

Properties

AudioStreams

Gets the list of audio streams found in the media file. Each stream contains information about codec, sample rate, channels, bitrate, language, and duration.

public List<AudioStreamInfo> AudioStreams { get; }

Property Value

List<AudioStreamInfo>

Audio_Streams_AllInOne

Gets or sets a value indicating whether all audio streams should be treated as a single combined stream. When true, multiple audio tracks are presented as one unified stream. When false, each audio track is analyzed and reported separately.

public bool Audio_Streams_AllInOne { get; set; }

Property Value

bool

Debug_Dir

Gets or sets the directory path where debug files should be saved. This includes filter graph files (.grf) and text representations of the graph. Only used when Debug_Mode is true.

public string Debug_Dir { get; set; }

Property Value

string

Debug_Mode

Gets or sets a value indicating whether debug mode is enabled. When true, additional diagnostic information is logged and debug files (such as filter graphs) may be saved to Debug_Dir.

public bool Debug_Mode { get; set; }

Property Value

bool

DefaultAudioDuration

Gets the overall duration of the audio content in the file. This represents the primary audio stream duration and is used when individual stream durations are not available.

public TimeSpan DefaultAudioDuration { get; }

Property Value

TimeSpan

DefaultVideoDuration

Gets the overall duration of the video content in the file. This represents the primary video stream duration and is used when individual stream durations are not available.

public TimeSpan DefaultVideoDuration { get; }

Property Value

TimeSpan

FileFormat

Gets the detected media container format of the analyzed file. Examples include "AVI", "MP4", "MKV", "MPEG-PS", "MPEG-TS", "WMV", etc. This represents the container format, not the codec used within.

public string FileFormat { get; }

Property Value

string

Filename

Gets or sets the full path to the media file to be analyzed. Supports local file paths, UNC paths, and in some cases HTTP/RTSP URLs.

public string Filename { get; set; }

Property Value

string

Subtitles

Gets the list of subtitle/caption streams found in the media file. Each stream contains information about language, format (SRT, ASS, VobSub), and other subtitle-specific properties.

public List<SubtitleStreamInfo> Subtitles { get; }

Property Value

List<SubtitleStreamInfo>

VideoStreams

Gets the list of video streams found in the media file. Each stream contains detailed information including codec, resolution, frame rate, bitrate, aspect ratio, and duration.

public List<VideoStreamInfo> VideoStreams { get; }

Property Value

List<VideoStreamInfo>

Methods

AddMediaType(AMMediaType, IMediaDet)

Processes and adds media type information to the appropriate stream collection. This method analyzes DirectShow media type structures and extracts relevant information for video, audio, or subtitle streams.

protected void AddMediaType(AMMediaType mt, IMediaDet mediaDet)

Parameters

mt AMMediaType

The DirectShow AMMediaType structure containing stream format information.

mediaDet IMediaDet

The IMediaDet interface for retrieving additional stream properties like duration and frame rate.

Attach(DSContext)

Attaches a DirectShow context to this MediaInfoReader instance. This allows changing the context after construction, useful for reusing the reader with different logging or filter configurations.

public void Attach(DSContext context)

Parameters

context DSContext

The DirectShow context to attach for subsequent operations.

ConfigureLocalRedist()

Configures the application to use local redistributable DirectShow filters. Call this method once at application startup to ensure all required codecs and filters are available from the local installation directory rather than relying on system-installed components.

public static void ConfigureLocalRedist()

EvalAudioCodec(ushort)

Gets codec name.

protected static string EvalAudioCodec(ushort tag)

Parameters

tag ushort

Audio tag.

Returns

string

Returns codec name.

EvalFourCC(string)

Resolves the human-readable codec name from the provided FourCC string. Matches the code against a comprehensive list of known video and audio codecs.

protected static string EvalFourCC(string srcFourCC)

Parameters

srcFourCC string

The FourCC (Four Character Code) string to evaluate.

Returns

string

The human-readable codec name (e.g., "MPEG-4", "DivX"), or "Unknown Codec" if not found.

FillFileFormat()

Determines and sets the human-readable file format description based on the file extension. Populates the FileFormat property with a friendly name (e.g., "MPEG 4" for .mp4, "Matroska" for .mkv).

public void FillFileFormat()

~MediaInfoReader()

Finalizes an instance of the VisioForge.Core.MediaInfo.MediaInfoReader class. Ensures all allocated stream information lists are properly cleared to prevent memory leaks.

protected ~MediaInfoReader()

FixBitrates()

Calculates and updates the video bitrate based on file size and duration if the initial bitrate detection failed. This is a fallback mechanism to ensure a non-zero bitrate is reported when the codec header information is insufficient.

protected void FixBitrates()

GetStreamAvailabilityFromMemoryStream(DSContext, IStream, long, out bool, out bool)

Gets the stream availability from memory stream.

public static bool GetStreamAvailabilityFromMemoryStream(DSContext context, IStream stream, long streamSize, out bool videoStream, out bool audioStream)

Parameters

context DSContext

The context.

stream IStream

The stream.

streamSize long

Size of the stream.

videoStream bool

if set to true [video stream].

audioStream bool

if set to true [audio stream].

Returns

bool

true if successful, false otherwise.

IsFilePlayable(string, out FilePlaybackError, out string)

Determines whether a media file can be successfully played back on the current system. This method checks file validity, extension, and attempts to build a DirectShow render graph to verify if the necessary codecs and filters are installed.

public static bool IsFilePlayable(string filename, out FilePlaybackError errorCode, out string errorText)

Parameters

filename string

The full path to the media file to test.

errorCode FilePlaybackError

Output parameter returning a specific error code if playback fails.

errorText string

Output parameter returning a descriptive error message if playback fails.

Returns

bool

True if the file can be played; otherwise, false.

ReadBluRayInfo()

Analyzes Blu-Ray media files by building a DirectShow filter graph with LAV filters. This method is specifically designed to handle Blu-Ray structures, extracting video and audio stream details by explicitly loading and connecting LAV Splitter and Decoder filters.

public void ReadBluRayInfo()

ReadFileInfo(bool)

Reads file info.

public void ReadFileInfo(bool allowLibMediaInfoUsage)

Parameters

allowLibMediaInfoUsage bool

True to allow LibMediaInfo usage.

ReadFileInfo(Stream)

Reads file info from stream using LibMediaInfo.

public void ReadFileInfo(Stream stream)

Parameters

stream Stream

Seekable stream.

ReadFileInfo(bool, object, EncryptionKeyType, bool)

Reads file info.

public void ReadFileInfo(bool encryptedFile, object encryptionKey, EncryptionKeyType encryptionKeyType, bool allowLibMediaInfoUsage)

Parameters

encryptedFile bool

True if file is encrypted.

encryptionKey object

Encryption key.

encryptionKeyType EncryptionKeyType

Encryption key type.

allowLibMediaInfoUsage bool

True to allow LibMediaInfo usage.

ReadFullFileInfoEx()

Performs a comprehensive analysis of the media file using DirectShow filter graph rendering. This method attempts to render the file to allow downstream filters to report detailed stream information, handling various DirectShow return codes and fallback scenarios for different file types.

protected void ReadFullFileInfoEx()

ReadInfoMain()

Orchestrates the primary media information retrieval process. This method determines the file format, executes various analysis strategies (including deep analysis and fallback mechanisms), and compiles the results. It handles both local files and network streams (HTTP/RTSP).

protected bool ReadInfoMain()

Returns

bool

True if the media information was successfully read; otherwise, false.

SecondsToString(int)

Converts time to string.

protected static string SecondsToString(int seconds)

Parameters

seconds int

Seconds.

Returns

string

Returns time as a string.

Video_ResolutionWithAspect(int, out bool)

Returns video width.

public Size Video_ResolutionWithAspect(int streamIndex, out bool notOriginal)

Parameters

streamIndex int

Stream index.

notOriginal bool

True if video size changed.

Returns

Size

Returns video width, 0 if error happen.