|
@@ -65,5 +65,45 @@ public class FfmpegUtilServiceImpl implements FfmpegUtilService {
|
|
|
return CommonResponse.create(imageUrl);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CommonResponse<String> fetchKeyFrames1(FetchKeyFramesParam fetchKeyFramesParam) {
|
|
|
+ if (fetchKeyFramesParam == null || StringUtils.isEmpty(fetchKeyFramesParam.getUrl())
|
|
|
+ || StringUtils.isEmpty(fetchKeyFramesParam.getTimestamp())) {
|
|
|
+ return CommonResponse.create(500, "参数错误");
|
|
|
+ }
|
|
|
+ log.info("fetchKeyFramesParam={}", fetchKeyFramesParam);
|
|
|
+ log.info("imagePath={}", imagePath);
|
|
|
+ String imageFolder = imagePath + "/" + "timeTarget";
|
|
|
+ File dir = new File(imageFolder);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ boolean mkdir = dir.mkdir();
|
|
|
+ if (!mkdir) {
|
|
|
+ return CommonResponse.create(500, "服务异常,请重试");
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String imagePath = imageFolder + "/" + UUID.randomUUID() + ".jpg";
|
|
|
+ String target = "long_articles/image";
|
|
|
+
|
|
|
+ FfmpegUtil.getTargetTimeThumbnail1(fetchKeyFramesParam.getUrl(), imagePath, fetchKeyFramesParam.getTimestamp());
|
|
|
+ String imageUrl = OSSUploader.uploadToOSS(target, imagePath);
|
|
|
+ log.info("imageUrl={}", imageUrl);
|
|
|
+ Path pathToDelete = Paths.get(imagePath);
|
|
|
+ try {
|
|
|
+ // 使用 Files.walkFileTree 删除文件夹及其内容
|
|
|
+ Files.walkFileTree(pathToDelete, new SimpleFileVisitor<Path>() {
|
|
|
+ @Override
|
|
|
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
|
|
+ Files.delete(file); // 删除文件
|
|
|
+ return FileVisitResult.CONTINUE;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("del imageFolder error {}", e.getMessage());
|
|
|
+ }
|
|
|
+ return CommonResponse.create(imageUrl);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|