问题描述
我目前正在使用 multer
将视频带到我的后端,然后我使用 ffmpeg
生成缩略图,同时上传视频。我阅读了与缩略图无关的 s3 presigned url
文档。而我当前的代码正在使用 multer
。我想摆脱它,因为 API 需要花费大量时间,当然还会增加我的服务器负载。
解决方法
所以这对我有用 -> 首先安装@ffmpeg-installer 和@ffprobe-installer 这样你就不必手动安装它们并将这两个库的路径传递给 fluent-ffmpeg 以便它可以用于取出视频细节(我需要它使屏幕截图大小根据进来的视频动态变化) 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
})
})