Search code examples
c#asp.netvideoasp.net-2.0

How do I get the dimensions of a mp4 video file?


I have a form that will accept and save a MP4 video file. I need to be able to get the dimensions of the video as well. This will be running on a server running ASP.NET 2.0 so any external libs must be able to be placed in the Bin folder as they can not be installed on the server.

Any ideas how to get the information? If the same lib would let me transcode the video to flv that would be a huge bonus.

Update: The server is XP Service Pack 2 with .NET Framework (2,0,50727,0)


Solution

  • There are a few ways to do this, but no library per-se that will work with C# for any/all .mp4 video files. That is nothing that is 100% reliable.

    Both are command line options (in a sense). Basically, what you'd be doing is running a process from your ASP.NET application using System.Diagnostics.Process.

    On of them is to use ffmpeg. With ffmpeg if you just give it a file (as a command line argument if will return various metadata about the file. This information can be parsed to extract the dimensions.

    The other is to use MediaInfo. It's a great tool for this. But again, you'll have to use the Command line version (CLI version) and pretty much give it the file name as a command line argument. It has an otion to produce and xml response so you can easily parse this and other information if can provide.

    ffmpeg can transcode your video as well. Though I don't see the point of transcoding from mp4. flv?