Reputation: 185
currently my code decodes MP3 files to PCM and then encodes output to whatever format is required 'MP3' or 'other', its using Node and FFMPEG for this currently. i want to use LAME to do the MP3 conversion encode and leave FFMEG for other formats but not sure how to go about with it. my relevant code currently: var createOutput = function(key) {
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);
});
});
i have tried to 'pipe' inStream[key]
to encoder
to historyBuffer[key]
and outStream[key]
but it does not work. can someone point me in the right direction please?
Upvotes: 0
Views: 1822