简体   繁体   中英

Ffmpeg command in nodejs

I want to use ffmpeg commands in my nodejs application. I dont want to using any npm packages like fluent-ffmpeg. Till now I have done this :

var ffmpeg = spawn('ffmpeg', ['-i',fileName+'.wav' ,fileName+'.amr','-acodec libopencore_amrnb', '-ab 12200k', '-ac 1', '-ar 8000']);
            // input_file.pipe(ffmpeg.stdin);
            // ffmpeg.stdout.pipe(output_stream);

            ffmpeg.stderr.on('data', function (data) {
                console.log(data.toString());
            });

            ffmpeg.stderr.on('end', function () {
                console.log('file has been converted succesfully');
            });

            ffmpeg.stderr.on('exit', function () {
                console.log('child process exited');
            });

            ffmpeg.stderr.on('close', function() {
                console.log('...closing time! bye');
            });

In output it gives error like this :

Unrecognized option 'acodec libopencore_amrnb'

I have installed all binaries required. Just need to know what command i have to pass in spawn() like :

var ffmpeg = spawn('ffmpeg', ['-i',fileName+'.wav' ,fileName+'.amr','-acodec libopencore_amrnb', '-ab 12200k', '-ac 1', '-ar 8000']);

I have tried the command on terminal and works perfectly. All i want is the correct way to pass command (options) in spawn() . Any help would be appreciated.

When you call spawn , you pass the command, and then an array where every flag and every associated argument is a separate element.

So instead of '-acodec libopencore_amrnb' , like you have, you want '-acodec', 'libopencore_amrnb' . They need to be two separate elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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