Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a buffer object as Ffmpeg's source input

I'm using node.js as a web server (fluent-ffmpeg as the ffmpeg library).

  1. I have two videos on amazon s3, when I retrieve them, they come as Buffer objects.

  2. I'd like to retrieve them, combine them, and send them to the client, without having to save them as files.

like image 637
Marwan Sulaiman Avatar asked Sep 02 '25 10:09

Marwan Sulaiman


1 Answers

There is a case where you can store the buffers into memory, and read from memory to combine both of them. But this have some serious implications and not advised to do:

  1. Memory leak after dealing with multiple buffers.
  2. Converting 2 buffers simultaneity can can be very slow on a singleton app.

The Alternative is:

  1. Write the buffer stream to a temp directory using ffmpeg-stream .

  2. Afterwards combine the temporary files fluent-ffmpeg.

    • examples
  3. Example of creating temp files with nodeJS node-tmp

related questions: 1. Merge Multiple Videos using node fluent ffmpeg

  • Another suggestion:

If this is a huge set of videos, aka album to be combined (like 2Gb per video), services like AWS Lambda could essentially help. Since the service stores buffers, and doesn't fail to run multiple jobs.

like image 111
0bserver07 Avatar answered Sep 04 '25 05:09

0bserver07