Search code examples
videoffmpegemgucv

EmguCV/ FFmpeg get video information


How to get information about a video file (ex: frames per second, bitrate, frame height, width etc) using emguCV or FFmpeg to a C# code. I am using C#.net for my project.


Solution

  • maybe shiping ffmpeg's ffprobe.exe (from zeranoe builds) along with your project, running it silently and parse its output?

    using System; using System.Diagnostics; using System.Text.RegularExpressions;
    namespace MyClientApp
    {  public class MyApp
       {  public static void Main()
          {  var proc = new Process { StartInfo = new ProcessStartInfo 
             {   FileName = "ffprobe.exe",         Arguments = "testvideo.mp4",
                 UseShellExecute = false,          RedirectStandardError = true, CreateNoWindow = true }
             };    
             proc.Start();
             while (!proc.StandardError.EndOfStream) 
             {  string line = proc.StandardError.ReadLine();
                Match match = Regex.Match(line, @"Video:.*(\d{3,5}x\d{3,5}).*$");
                if (match.Success) 
                   Console.WriteLine("resolution is: {0}", match.Groups[1].Value);
             }
          }
       }
    }