javascript - 在nodejs中将缓冲区转换为视频时出错

标签 javascript node.js encoding

我想从mp4 video创建缓冲区然后再次将该缓冲区转换为视频。

我正在生成缓冲区

const buffer = Buffer.from("Cat.mp4");
console.log(buffer);

我得到输出 <Buffer 43 61 74 2e 6d 70 34>

现在我再次将该缓冲区转换为视频

fs.writeFile("test.mp4", buffer, 'binary',function(err) {
    if(err) {
        console.log(err);
    } else {
        console.log("Done!");
    }
});

它给出输出 Done!但是当我尝试播放该视频时,出现错误 Could not determine the stream .

我不知道我在转换缓冲区或转换视频时是否错误。

请有人帮助我。

最佳答案

您实际上是将字符串“Cat.mp4”转换为缓冲区:

//<Buffer 43 61 74 2e 6d 70 34>
//        C  a  t  .  m  p  4

尝试使用:

const fs = require('fs');
fs.readFile('Cat.mp4', (err, buffer) => {
  if (err) throw err;
  console.log('do we have a buffer?', buffer instanceof Buffer)
});

根据 its documentation :

If no encoding is specified, then the raw buffer is returned.

关于javascript - 在nodejs中将缓冲区转换为视频时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54921716/

相关文章:

javascript - 如何在托管 Web 服务器上实际部署 Node.js(或 django)项目?

javascript - 在页面加载时在 chrome 扩展中运行 js 脚本

javascript - 跨域调用 JavaScript

mysql - node-mysql 一个查询中的多个语句

ios - iOS Web 服务接收空数据

php - 加载页面时如何更改地址栏中的 URL?

node.js - 尝试使用 PM2 Cluster 启动 Node.js 应用程序时出现错误

json - 字符串化对象时如何从对象中删除引号和反斜杠(不使用正则表达式)

linux - 在 Linux 上搜索文件中的错误编码字符

python - BeautifulSoup 汉字编码错误