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 commands from bash, but I'm not sure if this is performant.
Asked
Active
Viewed 5,115 times
4

feerlay
- 2,286
- 5
- 23
- 47
-
Possible duplicate of [Audio manipulation using node.js](https://stackoverflow.com/questions/21996275/audio-manipulation-using-node-js) – AP. Feb 20 '18 at 20:04
-
1Not exactly. That thread is 4 years old and has 2 answers while in JS you get new framework every week :P – feerlay Feb 20 '18 at 20:07
1 Answers
6
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')

TGrif
- 5,725
- 9
- 31
- 52