Search code examples
c#audiostreamcodecmediainfo

MediaInfo check AudioStreams dynamically in C#


I am using MediaInfo.dll with Wrapper-Class to check Video-Files for Audio-Codecs.

Can someone tell me how I can check COUNT of the Audio-Streams of the File?

string pfad = Console.ReadLine();
        string[] verzeichnisse = Directory.GetDirectories(pfad);
        foreach (string verzeichnis in verzeichnisse)
        {
            string[] dateien = Directory.GetFiles(verzeichnis);
            foreach (string datei in dateien)
            {
                if(datei.ToLower().Contains(".mkv") || datei.ToLower().Contains(".avi") || datei.ToLower().Contains(".mp4"))
                {
                    var mediaInfo = new MediaInfo();
                    mediaInfo.Open(datei);

                    // HERE I WANT CHECK FIRST HOW MANY AUDIO-STREAMS THERE ARE
                    // ???

                    var audioStream1 = mediaInfo.Get(StreamKind.Audio, 0, "Format");
                    var audioStream2 = mediaInfo.Get(StreamKind.Audio, 1, "Format");  
                    
                    mediaInfo.Close();

                }
            }
        }

Solution

  • how I can check COUNT of the Audio-Streams of the File?

    mediaInfo.Count_Get(StreamKind.Audio);
    

    You may check the MediaInfo C# example for more examples.

    Another example (you can find it with the linked example) :

    mediaInfo.Get(StreamKind.Audio, 0, "Language");
    

    Jérôme, developer of MediaInfo.