简体   繁体   中英

Is there a way to set maximum duration for browser-based video uploaders?

Vine.co allows videos at most 6 seconds. But users only upload from phones. I wonder if this can be done with browsers. Thanks.

(I rely on node.js)

It depends how you want to perform the upload.

Option 1 - If the movie is uploaded by streaming it to the server in, for example, RTSP or RTMP, then the server can elect to drop the movie based on its duration, as determined during the upload. This is the most accurate and efficient option but it requires the uploader to be able to stream the file and the server to accept the stream by a media server.

Option 2 - If the movie is uploaded by file transfer then the easiest is to limit the movie file size. The size can be determined by heuristics if you know its bit rate. For example, at 500Kbps you'd expect a 6 second movie to weigh approximately 375KB, so you might limit the uploads to 450KB and figure the exact boundary while inspecting the file on the server side. For this to actually work you must know in advance the movie's average bit rate.

Option 3 - Yet another option, based on the movie metadata: Depending on the movie format you might be able to determine upfront the movie's duration by just inspecting the file headers. In mp4, for example, if the MOV atom is at the beginning of the file you can tell upfront what's the movie's duration. However, if the MOV atom is at the end of the file or if the H.264 stream is muxed for live streaming as MPEG-TS then there is no way to tell upfront the movie's duration. Note that the header info is in any case just metadata, so a non-conforming client (whether accidentally or maliciously) might fool the server by posting incorrect duration metadata. In other words - this method is not reliable.

Option 4 - The more accurate method in case you use only HTTP/FTP, though probably the most labor intensive programming-wise, is to analyze the movie during upload. This method is highly dependent on the movie format and upload method. And it is still less accurate and responsive than the first option (upstreaming the files).

To summarize, if you can compromise on the upfront accuracy of the quota assertion and wait for the file to be on the server before accepting or rejecting it then the simplest and recommended solution would be Option 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM