提交 ae13e28e 作者: 方治民

fix: 修复视频封面截取没有使用转换后的文件名追加问题

上级 da209647
...@@ -134,27 +134,14 @@ public class UploadProcessServiceImpl implements UploadProcessService { ...@@ -134,27 +134,14 @@ public class UploadProcessServiceImpl implements UploadProcessService {
// 视频截取首帧可见画面作为封面 // 视频截取首帧可见画面作为封面
if (isSupportiveVideo(suffix)) { if (isSupportiveVideo(suffix)) {
// 使用 ffmpeg 截取视频首帧图片
Path path = Paths.get(tempFile.getParent().toString(), FileUtil.getName(filepath) + ".jpg");
FFmpegBuilder builder = new FFmpegBuilder()
.setInput(tempFile.toString())
.overrideOutputFiles(true)
.addOutput(path.toString())
.setFrames(1)
.done();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
executor.createJob(builder).run();
// 判断封面图是否生成
if (Files.exists(path)) {
// 上传封面图
minio.putObject(path.toFile(), getObjectFolder(filepath));
}
// 大视频文件切片上传(> 5s) // 大视频文件切片上传(> 5s)
if (sec > 5) { if (sec > 5) {
filepath = handleVideoToHls(filepath, tempFile, ffmpeg, ffprobe); filepath = handleVideoToHls(filepath, tempFile, ffmpeg, ffprobe);
} }
// 使用 ffmpeg 截取视频首帧图片
Path path = Paths.get(tempFile.getParent().toString(), FileUtil.getName(filepath) + ".jpg");
handleVideoScreenshot(tempFile.toString(), path.toString(), filepath, ffmpeg, ffprobe);
} }
// 删除为本次上传进行本地处理所创建的整个临时文件夹目录 // 删除为本次上传进行本地处理所创建的整个临时文件夹目录
...@@ -163,6 +150,25 @@ public class UploadProcessServiceImpl implements UploadProcessService { ...@@ -163,6 +150,25 @@ public class UploadProcessServiceImpl implements UploadProcessService {
} }
@SneakyThrows @SneakyThrows
public void handleVideoScreenshot(String in, String out, String object, FFmpeg ffmpeg, FFprobe ffprobe) {
FFmpegBuilder builder = new FFmpegBuilder()
.setInput(in)
.overrideOutputFiles(true)
.addOutput(out)
.setFrames(1)
.done();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
executor.createJob(builder).run();
// 判断封面图是否生成
Path path = Paths.get(out);
if (Files.exists(path)) {
// 上传封面图
minio.putObject(path.toFile(), getObjectFolder(object));
}
}
@SneakyThrows
public String handleVideoToHls(String object, Path path, FFmpeg ffmpeg, FFprobe ffprobe) { public String handleVideoToHls(String object, Path path, FFmpeg ffmpeg, FFprobe ffprobe) {
String originName = FileUtil.getName(object); String originName = FileUtil.getName(object);
String objectFolder = object.replace("/" + originName, ""); String objectFolder = object.replace("/" + originName, "");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论