0

I am currently using multer which brings the video to my backend and after that I generate a thumbnail using ffmpeg and at the same time upload the video. I read the documentation for s3 presigned url which has nothing to do with thumbnails. And my current code is using multer. Which I want to get rid of because API is taking a lot of time and of course increasing my server load.

albo
  • 41
  • 7
  • 1
    The api taking along time to load a video could be due to the file size, ideally you'd want to compress a video before uploading it, also I would say thumbnails will be fine in the same bucket together with the videos since you won't be loading one without the other I assume separating them into 2 buckets probably would have very little to none impact on loading speed. Please post your code so maybe I can have a better understanding. – Erykj97 Jan 30 '21 at 18:50
  • @Erykj97 Thanks, I didnt realize the videos were too big so I told the my friend to compress it more before sending me at backend. Also I found a solution for my question will be posting that in couple of hrs. – albo Feb 26 '21 at 09:56

1 Answers1

0

So this worked for me -> Firstly install @ffmpeg-installer and @ffprobe-installer so that you don't have to install these manually and pass the path of these 2 libraries into fluent-ffmpeg so that it can be used for taking out video details(I needed it to make the screenshot size dynamic as per the video coming in) const ffmpeg = require('fluent-ffmpeg');

const ffmpeg = require('fluent-ffmpeg');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffprobePath = require('@ffprobe-installer/ffprobe').path;
ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg.setFfprobePath(ffprobePath);

//EXTRACT VIDEO DETAILS USING ffprobe (I am using multer)
ffmpeg.ffprobe('path_to_file', (err, data)=>{
    // take out height and width and decrease it (depending on your requirement)
    ffmpeg('path_to_file')
    .screenshots({
    timestamps: ["00:01"],
    filename: `${filename}.jpeg`,
    folder: "to/wherever/you/want",
    count: 1,
    size: `${width}x${height}`,//getting this from ffprobe
     }).on("end", ()=> {
         //upload file in 'to/wherever/you/want'(thumbnail) to s3
         //upload the video as well to s3
     })

}) 
albo
  • 41
  • 7