6

My ASP.NET / C# web app allows users to upload MP4 files to a database for later display using the HTML5 <video> tag.

What I am looking for is a way (code, component) to determine the on-screen dimension that a given MP4 file will need to properly play. I haven't been able to find anything so far.

Given a MP4 file (as a file upload) - how can I determine the on-screen dimensions of the video contained in it, using C# code? Is there something like MP4 metadata that can be read from the file?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    http://stackoverflow.com/questions/5085897/how-do-i-get-the-dimensions-of-a-mp4-video-file This may help you solve your problem – Jake Rote Jan 30 '14 at 12:38
  • 1
    @JakeRote: both approaches seem rather "kludgy" and messy - I'd really prefer to have a nice, clean .NET **library** to do this. `MP4Metadata.GetDimensions("c:\tmp\myfile.mp4");` or something like that - **that** would be a nice solution! – marc_s Jan 30 '14 at 12:58

1 Answers1

3

Rather than solving this problem on the server, you can solve it on the client at view time with the HTML5 video element.

$("#video").bind("loadedmetadata", function () {
        var width = this.videoWidth;
        var height = this.videoHeight;
        // ...
});

Using this approach your upload solution can remain untouched.

If storing the dimensions in the database is a requirement, consider finding a way to leverage the video element during the upload process. One approach would be to have a video 'preview' step right after upload that would extract the dimensions with the JavaScript code above and post them as hidden form elements to your server.

Shawn McGough
  • 1,980
  • 2
  • 22
  • 32