H.264 video encoder in javascript

China☆狼群 提交于 2019-12-19 06:02:20

问题


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.


回答1:


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/




回答2:


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.



来源:https://stackoverflow.com/questions/17025600/h-264-video-encoder-in-javascript

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