Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the dimension (height x width) of a MP4 file being uploaded

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?

like image 752
marc_s Avatar asked Jan 30 '14 12:01

marc_s


1 Answers

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.

like image 75
Shawn McGough Avatar answered Oct 20 '22 21:10

Shawn McGough