36534

How to get video dimensions using FFMPEG

My goal is to pass a Video file to FFMPEG and to get its dimension as output.How can I achieve this. Can anyone help me out with sample code?

Answer1:

public void GetVideoInfo(string input) { // set up the parameters for video info. string @params = string.Format("-i {0}", input); string output = Run(ffmpegProcess, @params); //get the video format re = new Regex("(\\d{2,3})x(\\d{2,3})"); Match m = re.Match(output); if (m.Success) { int width = 0; int height = 0; int.TryParse(m.Groups[1].Value, out width); int.TryParse(m.Groups[2].Value, out height); } } private static string Run(string process/*ffmpegFile*/, string parameters) { if (!File.Exists(process)) throw new Exception(string.Format("Cannot find {0}.", process)); // Create a process info. ProcessStartInfo oInfo = new ProcessStartInfo(process, parameters); //oInfo.UseShellExecute = false; //oInfo.CreateNoWindow = true; //oInfo.RedirectStandardOutput = true; //oInfo.RedirectStandardError = true; // Create the output and streamreader to get the output. string output = null; //StreamReader outputStream = null; // Try the process. //try //{ // Run the process. Process proc = System.Diagnostics.Process.Start(oInfo); proc.WaitForExit(); //outputStream = proc.StandardError; //output = outputStream.ReadToEnd(); proc.Close(); //} //catch( Exception ex ) //{ // output = ex.Message; //} //finally //{ // // Close out the streamreader. // if( outputStream != null ) // outputStream.Close(); //} return output; }

You should uncomment some code to get this working. Hope it helps.

I have code that gets more info from the video, different converts, etc. The code above is sliced and may need slight modifications.

Answer2:

Have you tried the FFMPEG-C# Library?

Recommend

  • Scala using regex with or syntax in match case statement
  • Negating Regex PO BOX
  • Wrap C++ function using Boost Reflect or another C++ reflection library
  • android Navigation Bar hiding and persantage of usable screen overlap
  • Efficient User-Agent Regex to find Safari in Python
  • Drawing a Path in XAML (with binding) vs. C#. One works, one doesn't
  • chrome video src change not working
  • WPF Template Binding in ToggleButton UserControl
  • WPF version of .ScaleControl?
  • blade.php method outputting it's result to the form
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • D3 get axis values on zoom event
  • Textfile Structure (tables)
  • Rails Find when some params will be blank
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Extracting HTML between tags
  • Get data from AJAX - How to
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Email format validation in mvc3 view
  • Cannot connect to cassandra from Spark
  • Regex thinks I'm nesting, but I'm not
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Bug in WPF DataGrid
  • Fill an image in a square container while keeping aspect ratio
  • How to show dropdown in excel using jrxml (jasper api)?
  • Font Awesome Showing Box instead of Icons
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • python draw pie shapes with colour filled
  • Is it possible to post an object from jquery to bottle.py?
  • Can't mass-assign protected attributes when import data from csv file
  • Sorting a 2D array using the second column C++
  • Python/Django TangoWithDjango Models and Databases
  • java string with new operator and a literal