Jump to content
MakeWebGames

Uploading videos - Issues


Coly010

Recommended Posts

Ok, so in my site I want to allow users to upload videos.

The problem I'm facing is cross-compatibility for playing different video types across different browsers.

As an upload is basically a users choice, and many wont have a say in what type of file their video is. Therefore I need a way of playing all types of video files

and get the dimensions of the video, so it can be resized proportionally.

One solution was to convert all uploaded files to .mp4 and then simply use html5's video tag to play it, or if need be, <embed>

But I learned the server that my hosting is with doesn't support ffmpeg,(or crons for that matter so I'm considering leaving, if you have any suggestions that would be great)

Does anyone know of any other solutions to my problem?

Link to comment
Share on other sites

I recently had a go at something like this for another project, and I found that regardless of what you try, it still relies on what the end user has installed to view videos. But here is what I done:

When uploading a file, you have the $_FILES['name']['type'] parameter. I found that by using that "type" parameter, you can store it in the database, and by using php headers Content-Type, use the type from the DB. You can also use that same Content-Type in your html5 video tag. The problem comes in with certain file formats, specifically wma. Requires the end user to install quicktime.

I would switch to DigitalOcean VPS, or even still, use a cheap $5 vps on DigitalOcean to connect to your database, fetch the files & convert them using ffmpeg (you can install it onto your own vps). And then on your website server, serve the files from the VPS (http://enable-cors.org/).

There are many approaches. It depends on what you feel like using :cool:

Link to comment
Share on other sites

I'll take a look at DigitalOcean, and look into VPS as I've never used one before.

Using the Content-Type seems like a good idea, but does <video> not only work with ogg/mp4/webm ? I suppose I could filter it if I had the file type stored. The only other problem that arises from that, is security. Is there a way to check that the file is video and not say a text file saved as a video type?

Link to comment
Share on other sites

I'll take a look at DigitalOcean, and look into VPS as I've never used one before.

Using the Content-Type seems like a good idea, but does <video> not only work with ogg/mp4/webm ? I suppose I could filter it if I had the file type stored. The only other problem that arises from that, is security. Is there a way to check that the file is video and not say a text file saved as a video type?

Yes, have a read here: https://www.owasp.org/index.php/Unrestricted_File_Upload

 

Thankfully, we can get coverage for all modern (and mobile) browsers using only two formats:

WebM - uses the VP8 codec for video and the Vorbis codec for audio

MP4 - uses the H.264 codec for video and the AAC codec for audio

Link to comment
Share on other sites

From reading that post alone, it seems almost impossible to prevent an attacker from getting code into the webserver. I'll need to read into ways of making sure it is a video, and I think the best solution for that could in fact be ffmpeg :/

If it was built by a human, it can be broken by a human ;)

Edited by sniko
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...