微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在将视频上传到 s3 的同时为其创建缩略图并将其保存到使用 nodejs 的同一存储桶中的另一个文件夹中?

如何解决如何在将视频上传到 s3 的同时为其创建缩略图并将其保存到使用 nodejs 的同一存储桶中的另一个文件夹中?

我目前正在使用 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
     })

}) 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。