简体   繁体   English

如何在Nodejs中将缓冲区数组保存到webm视频

[英]How to save an array of Buffer to webm video in Nodejs

[
  <Buffer 1a 45 df a3 9f 42 86 81 01 42 f7 81 01 42 f2 81 04 42 f3 81 08 42 82 84 77 65 62 6d 42 87 81 04 42 85 81 02 18 53 80 67 01 ff ff ff ff ff ff ff 15 49 ... 6365 more bytes>,
  <Buffer 41 83 81 03 c0 80 fb 03 5e ca af 6b 8a 35 12 02 42 0f 9b 35 37 9f 1f 4e a1 a3 05 7d b8 22 45 50 11 4f 01 d4 69 01 8d ee b6 3d 11 1e 7b 9d 25 f7 39 6b ... 6624 more bytes>,
  <Buffer 41 bc 81 07 bc 80 fb 83 7b 7f 5a 83 1e bf 32 bc a3 93 af dc c1 b3 14 09 52 d1 5b ca 91 ab 52 43 3e a2 d5 e6 11 d1 cf 54 24 71 ad 73 57 85 d0 5e 34 02 ... 6762 more bytes>,
  <Buffer 41 86 81 0b b8 80 fb 83 7f 80 53 a3 08 1f 88 d2 b1 66 e8 7f 1c 58 fc 7b 93 26 4b e6 58 0f 83 85 ee 27 e9 80 48 19 d7 fb 0a b2 0f 20 27 82 12 46 fe 6f ... 6496 more bytes>
]

I have an array of Buffer like this.我有一个像这样的缓冲区数组。 How can i create a webm video in Nodejs?如何在 Nodejs 中创建 webm 视频? In frontend I can new Blob and send to server.在前端,我可以新建 Blob 并发送到服务器。 But in Node there isn't new Blob method.但是在 Node 中没有新的 Blob 方法。

I assume the "Blob" is a WebM binary file that you want to save in the server.我假设“Blob”是您要保存在服务器中的 WebM 二进制文件。

You can push those buffers into a readable stream and pipe it out as a WebM file.您可以将这些缓冲区推送到可读的 stream 和 pipe 中,并将其作为 WebM 文件输出。

Example code:示例代码:

const fs = require('fs');
const { Readable } = require('stream');
const webmBuffers = [
   <Buffer...>,
   <Buffer...>,
];

const webmReadable = new Readable();
webmReadable._read = () => {  };
webmBuffers.forEach(chunk => {
    webmReadable.push(chunk);
});
webmReadable.push(null);

const outputWebmStream = fs.createWriteStream('./bunny.webm');
webmReadable.pipe(outputWebmStream);

Output: Output:

A media file bunny.webm is generated in the same directory.

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

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