admin管理员组

文章数量:1305140

I want to trim and concat several audio files in Node.js. I found FFmpeg and it looks like it does what I need, but I don't know how to use it in Node since the installation is through apt-get. Theoretically, I can use what's called child_process to execute several mands from bash, but I'm not sure if this is performant.

I want to trim and concat several audio files in Node.js. I found FFmpeg and it looks like it does what I need, but I don't know how to use it in Node since the installation is through apt-get. Theoretically, I can use what's called child_process to execute several mands from bash, but I'm not sure if this is performant.

Share Improve this question asked Feb 20, 2018 at 20:01 feerlayfeerlay 2,6385 gold badges29 silver badges50 bronze badges 2
  • Possible duplicate of Audio manipulation using node.js – AP. Commented Feb 20, 2018 at 20:04
  • 2 Not exactly. That thread is 4 years old and has 2 answers while in JS you get new framework every week :P – feerlay Commented Feb 20, 2018 at 20:07
Add a ment  | 

1 Answer 1

Reset to default 8

Of course you can do this by spawning a child_process and use ffmpeg this way. This should perfectly works without any noticeable performance problem.

However there is a fluent-ffmpeg package that you could use for more convenience. For example you can trim a file with the -t duration option and concat files with -f concat option. You can also use the builtin method mergeToFile().

Example:

// trim file
ffmpeg('input.wav')
  .inputOptions('-t 2') // 2s
  .output('output.wav')
  .run()

// merge file
ffmpeg('input.wav')
  .input('input2.wav')
  .mergeToFile('merged.wav')

本文标签: javascripttrim and concat audio files in NodejsStack Overflow