Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H.264 video encoder in javascript

I am looking to make a video encoder entirely in Javascript. The idea is that the user will be able to specify an existing video (easy enough) or a range of images and then be able to encode it to H.264 for publishing.

I understand that encoding content is not supported right now but I was wondering if this is something that is possible entirely in Javascript (or a Flash bridge) or not?

Thanks.

like image 248
GlGuru Avatar asked Jun 10 '13 13:06

GlGuru


2 Answers

It is possible to compile a video encoder to javascript using emscripten. For example, here is an emscripten-compiled version of google's VP9 libvpx library:

https://bitbucket.org/desmaj/libvpx.js/overview

Unfortunately it is incredibly slow - on the order of one tenth of the speed of the native library. I believe this is due to the fact that there is a lot of memory access going on, and that is incredibly slow in emscripten (see https://bugzilla.mozilla.org/show_bug.cgi?id=771106). Also, encoding generally relies on GPU or SIMD parallelism, which isn't currently available in javascript.

I think video encoding is just not feasible in javascript at present. The best solution would be for W3C to add a video encoding/decoding API to HTML5, perhaps as part of WebRTC/getUserMedia.

Also, see this blog post which describes the situation:

https://brendaneich.com/2013/05/today-i-saw-the-future/

like image 150
CpnCrunch Avatar answered Oct 01 '22 14:10

CpnCrunch


Video encoding is essentially just a specialized mathematical operation on binary data from one file to get more binary data to put in another file. Provided you have a way to get the data in (e.g. HTML 5 FileReader) and out (e.g. AJAX) in the ways you need, it's certainly within the realm of possibility for the part in the middle to be in JavaScript.

With that said, most computers and mobile devices contain specialized hardware for vector processing or video compression specifically, and these allow platform-specific software to encode video relatively fast compared to CPU-based processing alone. You may find that what you can do in JavaScript is slow enough to not be a very good alternative, depending on what functionality your JavaScript environment makes available.

like image 45
rakslice Avatar answered Oct 01 '22 15:10

rakslice