简体   繁体   English

fluent-ffmpeg将音频块转换为mp3并将其附加到mp3文件

[英]fluent-ffmpeg to convert audio chunks to mp3 and append them to an mp3 file

What? 什么?

Passing an appending write stream, fs.createWriteStream(filePath, { flags: 'a' }) , as an output doesn't seem to work. 传递附加的写流fs.createWriteStream(filePath, { flags: 'a' }) ,因为输出似乎不起作用。

The code I tried to run 我尝试运行的代码

const stream = require('stream');
let bufferReadStream = new stream.PassThrough();
bufferReadStream.end(Buffer.concat(largeChunk));

ffmpeg(bufferReadStream)
.format('mp3')
.output(fs.createWriteStream(filePath, { flags: 'a' }))
.on('end', () => {
  console.log('formatting finished!');
})
.on('error', err => {
  console.log('format buffer error: ', err);
})
.run();

What I expected to happen and what actually happened 我期望发生什么以及实际发生了什么

I was uploading an audio stream (.webm) to node which is accepted as an array of buffers. 我正在将音频流(.webm)上传到被接受为缓冲区数组的节点。 I am trying to avoid saving a very large audio file to disk and then formatting it to an .mp3 file because of the wait time for large audio files. 由于大量音频文件的等待时间,我试图避免将非常大的音频文件保存到磁盘,然后将其格式化为.mp3文件。

I tried take chunks of an audio file and directly convert them into an mp3 and append them to an mp3 file. 我尝试将音频文件的块直接转换为mp3并将其附加到mp3文件中。 The code successfully runs the first time, creating an mp3 file, but after the 2nd time, it throws an error instead of appending it to the existing mp3 file. 该代码第一次成功运行,创建了一个mp3文件,但是第二次之后,它将引发错误,而不是将其附加到现有的mp3文件中。

format buffer error:  
Error: ffmpeg exited with code 1: pipe:0: Invalid data found when processing input

at ChildProcess.<anonymous> (/Users/inspiredtolive/Desktop/HackReactor/Picky-Notes/node_modules/fluent-ffmpeg/lib/processor.js:177:22)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

Don't make/use the truncated files. 不要制作/使用被截断的文件。 Instead pass the request upload stream itself to the ffmpeg thing you have. 而是将请求上传流本身传递给您拥有的ffmpeg东西。 You may use something like the multipart module which has Stream support. 您可以使用具有Stream支持的multipart模块之类的东西。 BTW the other code you left out, like the file upload details, and which module ffmpeg comes from/how it was inited, was important. 顺便说一句,您遗漏的其他代码(例如文件上传详细信息以及ffmpeg来自哪个模块/如何初始化)非常重要。

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

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