fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.97k stars 881 forks source link

Unable to compress mp4 file from buffer to decompressed mp4 buffer for later saving #1198

Closed michalzard closed 1 year ago

michalzard commented 1 year ago

Is there a way that im able to compress mp4 file coming in and return just mp4 of smaller size? i went trough half of stackoverflow and internet and there's no clear answer anywhere

const bufferStream = new stream.PassThrough();
      for (let i = 0; i < req.files.length; i++) {
        const file = req.files[i];
        ffmpeg({
          source: stream.Readable.from(file.buffer, { objectMode: false }),
        })
          .outputOptions(["-movflags isml+frag_keyframe"])
          .toFormat("mp4")
          .writeToStream(bufferStream, { end: true })
          .on("progress", (progress) => console.log(`progress ${progress}`))
          .on("error", (err) => console.log(err))
          .on("end", (err, stdout, stderr) => {
            if (err) console.log("error", err);
            if (stdout) console.log("out", stdout);
            if (stderr) console.log("err", stderr);
            res.status(200).send(stdout);
          });
      }

node:events:491 throw er; // Unhandled 'error' event ^ Error: ffmpeg exited with code 1: pipe:0: Invalid data found when processing input Cannot determine format of input stream 0:0 after EOF Error marking filters as finished Conversion failed!

at ChildProcess.<anonymous> (C:\Users\misop\Desktop\sebi\sebi-auth\node_modules\fluent-ffmpeg\lib\processor.js:182:22) at ChildProcess.emit (node:events:513:28) at ChildProcess._handle.onexit (node:internal/child_process:291:12) Emitted 'error' event on FfmpegCommand instance at: at emitEnd (C:\Users\misop\Desktop\sebi\sebi-auth\node_modules\fluent-ffmpeg\lib\processor.js:424:16) at endCB (C:\Users\misop\Desktop\sebi\sebi-auth\node_modules\fluent-ffmpeg\lib\processor.js:544:13) at handleExit (C:\Users\misop\Desktop\sebi\sebi-auth\node_modules\fluent-ffmpeg\lib\processor.js:170:11) at ChildProcess.<anonymous> (C:\Users\misop\Desktop\sebi\sebi-auth\node_modules\fluent-ffmpeg\lib\processor.js:182:11) at ChildProcess.emit (node:events:513:28) at ChildProcess._handle.onexit (node:internal/child_process:291:12)