如何同时将视频上传到 s3 为其创建缩略图并使用 nodejs 将其保存到同一存储桶中的另一个文件夹? [英] How can I upload a video to s3 at the same time create a thumbnail for the same and save it to another folder in the same bucket using nodejs?
问题描述
我目前正在使用 multer
将视频带到我的后端,然后我使用 ffmpeg
生成缩略图,同时上传视频.我阅读了 s3 presigned url
的文档,它与缩略图无关.而我当前的代码正在使用 multer
.我想摆脱它,因为 API 需要花费大量时间,当然还会增加我的服务器负载.
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.
推荐答案
所以这对我有用->首先安装@ffmpeg-installer 和@ffprobe-installer 这样你就不必手动安装它们并将这两个库的路径传递给 fluent-ffmpeg 以便它可以用于取出视频细节(我需要它来根据进来的视频使屏幕截图大小动态)const ffmpeg = require('fluent-ffmpeg');
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
})
})
这篇关于如何同时将视频上传到 s3 为其创建缩略图并使用 nodejs 将其保存到同一存储桶中的另一个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!