4

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.

0bserver07
  • 3,390
  • 1
  • 28
  • 56

1 Answers1

2

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.

  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.

Community
  • 1
  • 1
0bserver07
  • 3,390
  • 1
  • 28
  • 56
  • Would creating temp files on the server be heavy in production? I'll look into Amazon Lambda in any case. Thanks for the detailed answer – Marwan Sulaiman Sep 05 '16 at 22:51
  • @MarwanSulaiman , the good thing about temp files are that they can be deleted right after getting them. Maybe if you can access the S3 Video as a complete object, rather than buffer, then no need to download it and combine, it will be just the case for the nodeJS library to access both videos on S3 (buffer manipulation without manual work) – 0bserver07 Sep 05 '16 at 22:53