简体   繁体   English

javascript中的H.264视频编码器

[英]H.264 video encoder in javascript

I am looking to make a video encoder entirely in Javascript. 我期待完全用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. 想法是用户将能够指定现有视频(足够简单)或一系列图像,然后能够将其编码为H.264以进行发布。

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? 我知道目前不支持编码内容,但我想知道这是否完全可以在Javascript(或Flash桥)中使用?

Thanks. 谢谢。

It is possible to compile a video encoder to javascript using emscripten. 可以使用emscripten将视频编码器编译为javascript。 For example, here is an emscripten-compiled version of google's VP9 libvpx library: 例如,这是google的VP9 libvpx库的emscripten编译版本:

https://bitbucket.org/desmaj/libvpx.js/overview 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 ). 我相信这是因为有很多内存访问正在进行,而且在emscripten中速度非常慢(请参阅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. 此外,编码通常依赖于GPU或SIMD并行性,这在javascript中目前不可用。

I think video encoding is just not feasible in javascript at present. 我认为视频编码目前在javascript中是不可行的。 The best solution would be for W3C to add a video encoding/decoding API to HTML5, perhaps as part of WebRTC/getUserMedia. 最好的解决方案是W3C将视频编码/解码API添加到HTML5,可能是WebRTC / getUserMedia的一部分。

Also, see this blog post which describes the situation: 此外,请参阅此博客文章,其中描述了这种情况:

https://brendaneich.com/2013/05/today-i-saw-the-future/ 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 (eg HTML 5 FileReader ) and out (eg AJAX ) in the ways you need, it's certainly within the realm of possibility for the part in the middle to be in JavaScript. 如果你有办法以你需要的方式获取数据(例如HTML 5 FileReader )和out(例如AJAX ),那么中间部分可能在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. 话虽如此,大多数计算机和移动设备都包含专门用于矢量处理或视频压缩的专用硬件,这些允许平台专用软件相对于单独的基于CPU的处理相对快速地编码视频。 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. 您可能会发现,您在JavaScript中可以做的很慢,不能成为一个非常好的替代方案,具体取决于您的JavaScript环境可用的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM