I am making an application in HTML5 that lets you choose a local video file, then play it using the video
tag. The problem is that some of the codecs of the videos are not playable by current browsers (XviD in general, H.264 for Firefox, etc). Is it possible to locally convert the videos to the right codec using JavaScript?
Edit: I probably didn't explain myself correctly, I am making a kind of "Media Player" using HTML5: The user chooses a file, the script reads it using the HTML5 File API and then adds it to a video
tag, no server involved. This is why I need JavaScript for this.
I am making an application in HTML5 that lets you choose a local video file, then play it using the video
tag. The problem is that some of the codecs of the videos are not playable by current browsers (XviD in general, H.264 for Firefox, etc). Is it possible to locally convert the videos to the right codec using JavaScript?
Edit: I probably didn't explain myself correctly, I am making a kind of "Media Player" using HTML5: The user chooses a file, the script reads it using the HTML5 File API and then adds it to a video
tag, no server involved. This is why I need JavaScript for this.
- 1 Yeah, sure! If you know enough about the spec for both versions, you can do it yourself. It might take a few hours to run, but you can do it. Sarcasm aside, I would just have them upload it to your server, where you can do the conversion and re-download it to the browser. – beatgammit Commented Sep 16, 2011 at 1:04
- But most of the videos will weigh a lot, and it will take hours to upload them to a server. – Cokegod Commented Sep 16, 2011 at 1:10
- 1 You can do it in a WebWorker, but I don't advise it. You'd have to read up on video conversion codecs and audio conversion codecs. There's nothing built in, and even doing it this way could take hours itself. I would just stream it to your server, run it through a streaming converter, then stream it back, but this will also take tons of bandwidth. – beatgammit Commented Sep 16, 2011 at 1:13
- 3 You could use Emscripten to pile FFmpeg... – icktoofay Commented Sep 16, 2011 at 1:13
- @Cokegod You could do this with NaCL It seems like a huge problem to solve in JavaScript, but I'm sure it's doable with something like Binary AJAX. – fnp Commented Sep 16, 2011 at 1:23
4 Answers
Reset to default 2This would be a great deal of work, but you may want to look at the NaCl project, from Google, but it will still take a long time to do the conversion.
http://www.chromium/nativeclient/getting-started/getting-started-background-and-basics
Eventually this will be browser-independent, as they make plugins available, but at the moment this would only work on some versions of Chrome, I expect.
But, this way you can write your conversion in C so you can use other conversions tools already written.
You may want to explain which formats you can handle, and if they try to do one that isn't in that format, then suggest free tools to help do the conversion, to help them out.
I don't believe you can easily do anything like what you want - especially if you expect users to select a video file and then within seconds it's being shared online.
There are a lot of variables and a ton of processing involved in video conversion/pression and there's a reason why even gigantic sites like YouTube take quite awhile to have your videos appear.
Plus, you want people to use a variety of video file types and somehow output the same type of video file, correct? Geez. Now you have to find open source video conversion apps that you can perhaps get to work behind the scenes just to get it to play nice with whatever you final video file type will be.
I don't see how this can be done with JavaScript alone. I think you could probably build an uploader and then maybe use another app to check a directory for new files and convert the files with a script to something else....but JS alone? And from your browser? And in a halfway decent amount of time? No way.
I would suggest only allowing certain types of video files to be uploaded and reject all others. Don't even mess with converting them.
I recently came across videoconverter.js but haven't had the time to try it out yet.
Take a look at this sample: http://code.msdn.microsoft./Media-Plugins-Sample-8913a7e9