目前,我的代码将 MP3 文件解码为 PCM,然后将输出编码为所需的“MP3”或“其他”格式,目前使用 Node 和 FFMPEG。我想使用 LAME 进行 MP3 转换编码,并将 FFMEG 留给其他格式,但不知道如何处理。我目前的相关代码: var createOutput = 函数(键){
var encoderArgs = [];
var encoder;
if (outputs[key].format === 'mp3') {
//encoder settings
encoderArgs.push('-acodec', 'pcm_s16le');
..
encoderArgs.push('-strict', '-2');
} else if (outputs[key].format === 'SOME OTHER FORMAT') {
//encoder settings
encoderArgs.push('-acodec', 'pcm_s16le');
..
encoderArgs.push('-strict', '-2');
} else {
return;
}
var encoder = child_process.spawn(serverOpts.converterPath, encoderArgs);
encoderArgs = null;
//handles any errors and resumes
encoder.once('error', function(err) { });
encoder.stdin.once('error', function(err) { });
encoder.stdout.once('error', function(err) { });
encoder.stderr.once('error', function(err) { });
encoder.stderr.resume();
//when data received in the standard in stream
inStream[key].on('data', function (chunk) {
if (encoder.stdin.writable && !encoder.stdin._writableState.length) {
encoder.stdin.write(chunk);
}
});
//setup data listener
//when 'data' received on standard out stream
encoder.stdout.on('data', function (chunk) {
historyBuffer[key].write(chunk);
outStream[key].write(chunk);
});
encoder.once('close', function() {
encoder.removeAllListeners();
encoder.stdin.removeAllListeners();
encoder.stderr.removeAllListeners();
encoder.stdout.removeAllListeners();
inStream[key].removeAllListeners();
encoder = null;
process.nextTick(function() {
createOutput(key);
});
});
我尝试将inStream[key]
“管道”到encoder
到historyBuffer[key]
和outStream[key]
但它不起作用。有人可以指出我正确的方向吗?
最佳答案
inStream[key]
.pipe(encoder)
.pipe(outStream[key]);
关于javascript - LAME 编码器 Node.js MP3 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33019296/