13

I am trying to convert mp3 file to wav file but I am not getting idea how to do that, I tried using fluent-ffmpeg library but I don't know how to use that.

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
Yatender Singh
  • 3,098
  • 3
  • 22
  • 31

1 Answers1

20

I finally figured it out using 'fluent-ffmpeg' library. Here is my code.

const ffmpeg = require('fluent-ffmpeg');
let track = './source.mp3';//your path to source file

ffmpeg(track)
.toFormat('wav')
.on('error', (err) => {
    console.log('An error occurred: ' + err.message);
})
.on('progress', (progress) => {
    // console.log(JSON.stringify(progress));
    console.log('Processing: ' + progress.targetSize + ' KB converted');
})
.on('end', () => {
    console.log('Processing finished !');
})
.save('./hello.wav');//path where you want to save your file

if you are facing

An error occurred: Cannot find ffmpeg

then add the ffmpeg path in system environment variables. Your VSCode still may dont recognise the ffmpeg command so in that case re-start VSCode.

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
Yatender Singh
  • 3,098
  • 3
  • 22
  • 31
  • 2
    Im getting error : `An error occurred: Cannot find ffmpeg`. – Somename Apr 03 '17 at 19:38
  • No error with just `var ffmpeg = require('fluent-ffmpeg');` . Only erroring when I use it. – Somename Apr 03 '17 at 19:39
  • make sure ffmpeg is installed in system and executable from everywhere and second thing is make sure that 'fluent-ffmpeg' npm package is also installed in project. – Yatender Singh Apr 04 '17 at 04:51
  • Both are reinstalled. I added the path in System Environment Variables also (for ffmpeg). Now I'm getting error : ` ENOENTspawn C:\ffmpeg\bin\ffmpeg.exe at exports._errnoException (util.js:1022:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32) at onErrorNT (internal/child_process.js:359:16)` – Somename Apr 04 '17 at 05:14
  • ok do one thing just go to console and try to execute some ffmpeg command. Whatever you r telling it should do the work or if can you please show me your source then I can resolve issue. – Yatender Singh Apr 05 '17 at 07:32
  • https://github.com/fluent-ffmpeg/node-fluent-ffmpeg please refer this link to set properly fluent-ffmpeg library – Yatender Singh Apr 05 '17 at 07:41
  • ffmpeg works from the command .. The issue was `.setFfmpegPath("C:\\ffmpeg\\bin\\ffmpeg.exe")` Now I am able to convert the file. I am trying to figure out .. how to convert the uploaded file from a form. Can you help please? How to access the file from Multer? – Somename Apr 05 '17 at 09:35
  • Download that file locally somewhere and access it directly it's simple. – Yatender Singh Apr 05 '17 at 14:43
  • Do you want me to give sample code? let me know .. just use request module and download at some destination. – Yatender Singh Apr 05 '17 at 14:44
  • I'll be very grateful if you could give a sample code. I've posted the question http://stackoverflow.com/questions/43227600/how-to-access-uploaded-file-from-multer". Please have a look .. I'm very confused as to how to integrate `ffmpeg` in `multer-s3` module. Thanks. – Somename Apr 05 '17 at 21:16
  • Im able to upload the file with `multer` and convert it with `ffmpeg`. That part is working. But its only `multer` and not `multer-s3`. How can I upload the converted `.mp4` to `S3`? Please help. – Somename Apr 06 '17 at 01:55
  • give me ur email i'll forward you the code to upload to s3 – Yatender Singh Apr 06 '17 at 14:01
  • I replied just check :) – Yatender Singh Apr 07 '17 at 06:01
  • so ffmpeg should be insatlled on the node server!!! is there any other way to solve this?? any library that works without installed extra executable on server? – Sunil Garg Jun 23 '22 at 08:23