简体   繁体   English

LAME编码器Node.js MP3流

[英]LAME Encoder Node.js MP3 streaming

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. 目前,我的代码将MP3文件解码为PCM,然后将输出编码为所需的任何格式“ MP3”或“其他”,目前使用Node和FFMPEG。 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. 我想使用LAME进行MP3转换编码,而将FFMEG保留为其他格式,但不确定如何处理。 my relevant code currently: var createOutput = function(key) { 我目前的相关代码: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. 我曾尝试将“ inStream[key] ”管道outStream[key] encoder以“ historyBuffer[key]和“ outStream[key]但是它不起作用。 can someone point me in the right direction please? 有人可以指出我正确的方向吗?

inStream[key]
    .pipe(encoder)
    .pipe(outStream[key]);

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

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