Reputation: 3186
I want to retrieve the Resolution and Duration of the video file that a end user uploads in my site before it gets uploaded into my Server. In this way, I want to check if the resolution and duration meets my requirement. Went through many APIs and they all give this Meta data information only after video gets uploaded into the Server. My Server is running on Linux and am using Java, Struts. Are there any APIs which will give this information before video file gets uploaded?
Upvotes: 0
Views: 6526
Reputation: 3630
Consider uploading, by AJAX, a small portion of the beginning of the file to the server side. In most file formats, 50-100 kbytes of data should be enough (and that number can be determined per file format; in FLV, AVI, MKV files even few kbytes should be enough). The server side can then use mediainfo, xuggle or plain ffmpeg to get the dimensions and duration, and accordingly allow or disallow the upload by the client.
Here's a tutorial with code examples on how to send only a part of the file using the HTML5 file API.
Upvotes: 2
Reputation: 3630
On browsers support HTML5, you can use an MP4 parser (such as mp4.js) to parse the file headers.
moov
atom of the file, and inside it the mvhd
atom. The duration, in seconds, can be calculated by dividing the mvhd
's Duration field by the TimeScale field. moov
atom, the trak
atom for the video track (ignore the audio track, or other tracks if you encounter them; usually the file has only one video track), and in it the tkhd
atom, which has width and height fields.Upvotes: 1
Reputation: 50203
You can (now) just check the size (and some other things, but no duration nor resolution, AFAIK), client side, with HTML5:
http://www.html5rocks.com/en/tutorials/file/dndfiles/
and
Using jQuery, Restricting File Size Before Uploading
Upvotes: 1