我想从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/