H.264 video encoder in javascript

喜欢而已 提交于 2019-12-01 03:27:43

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/

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!