|
@@ -1,13 +1,9 @@
|
|
package com.taais.biz.service.impl;
|
|
package com.taais.biz.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.io.IOException;
|
|
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.mybatisflex.core.paginate.Page;
|
|
import com.mybatisflex.core.paginate.Page;
|
|
@@ -29,7 +25,6 @@ import com.taais.system.domain.vo.SysOssVo;
|
|
import com.taais.system.service.ISysOssService;
|
|
import com.taais.system.service.ISysOssService;
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
@@ -38,7 +33,6 @@ import org.apache.http.impl.client.HttpClients;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
-import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.taais.biz.mapper.VideoStableMapper;
|
|
import com.taais.biz.mapper.VideoStableMapper;
|
|
@@ -48,6 +42,7 @@ import com.taais.biz.domain.vo.VideoStableVo;
|
|
import com.taais.biz.service.IVideoStableService;
|
|
import com.taais.biz.service.IVideoStableService;
|
|
|
|
|
|
import static com.taais.biz.domain.table.VideoStableTableDef.VIDEO_STABLE;
|
|
import static com.taais.biz.domain.table.VideoStableTableDef.VIDEO_STABLE;
|
|
|
|
+import static com.taais.biz.service.impl.DataSeqServiceImpl.isImageFile;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 视频去抖动Service业务层处理
|
|
* 视频去抖动Service业务层处理
|
|
@@ -222,8 +217,8 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
String fileName_without_suffix = removeFileExtension(fileName);
|
|
String fileName_without_suffix = removeFileExtension(fileName);
|
|
|
|
|
|
Path path = Paths.get(resourcePath);
|
|
Path path = Paths.get(resourcePath);
|
|
- Path inputPath = path.resolveSibling(fileName_without_suffix + "_images");
|
|
|
|
- Path outputPath = path.resolveSibling(fileName_without_suffix + "_stable");
|
|
|
|
|
|
+ Path inputPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX);
|
|
|
|
+ Path outputPath = path.resolveSibling(fileName_without_suffix + BizConstant.STABLE_SUFFIX);
|
|
|
|
|
|
makeDir(inputPath.toString());
|
|
makeDir(inputPath.toString());
|
|
makeDir(outputPath.toString());
|
|
makeDir(outputPath.toString());
|
|
@@ -304,8 +299,8 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
// inputPath = Paths.get("C:", videoStable.getInputPath());
|
|
// inputPath = Paths.get("C:", videoStable.getInputPath());
|
|
// outputPath = Paths.get("C:", videoStable.getOutputPath());
|
|
// outputPath = Paths.get("C:", videoStable.getOutputPath());
|
|
// } else {
|
|
// } else {
|
|
- inputPath = Paths.get(videoStable.getInputPath());
|
|
|
|
- outputPath = Paths.get(videoStable.getOutputPath());
|
|
|
|
|
|
+ inputPath = Paths.get(videoStable.getInputPath());
|
|
|
|
+ outputPath = Paths.get(videoStable.getOutputPath());
|
|
// }
|
|
// }
|
|
|
|
|
|
// 创建File对象
|
|
// 创建File对象
|
|
@@ -340,6 +335,65 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map<String, String>> getImages(Long inputOdssId) {
|
|
|
|
+ // 检查input_oss_id是否存在
|
|
|
|
+ if (ObjectUtil.isNull(inputOdssId)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ SysOssVo ossEntity = ossService.getById(inputOdssId);
|
|
|
|
+ if (ObjectUtil.isNull(ossEntity)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String filePath = ossEntity.getFileName();
|
|
|
|
+ String localPath = TaaisConfig.getProfile();
|
|
|
|
+ String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
|
|
|
|
+ String unzipPath = resourcePath.substring(0, resourcePath.lastIndexOf(".")) + BizConstant.UNZIP_SUFFIX;
|
|
|
|
+ String resultPath = resourcePath.substring(0, resourcePath.lastIndexOf(".")) + BizConstant.STABLE_SUFFIX;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ List<String> inputImageList = getImageUrls(ossEntity, unzipPath, BizConstant.UNZIP_SUFFIX);
|
|
|
|
+ List<String> outputImageList = getImageUrls(ossEntity, resultPath, BizConstant.STABLE_SUFFIX);
|
|
|
|
+
|
|
|
|
+ HashMap<String,String> nameToUrl1 = new HashMap<>();
|
|
|
|
+ for (String imageUrl : inputImageList) {
|
|
|
|
+ String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
|
|
|
|
+ nameToUrl1.put(name, imageUrl);
|
|
|
|
+ }
|
|
|
|
+ HashMap<String,String> nameToUrl2 = new HashMap<>();
|
|
|
|
+ for (String imageUrl : outputImageList) {
|
|
|
|
+ String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
|
|
|
|
+ nameToUrl2.put(name, imageUrl);
|
|
|
|
+ }
|
|
|
|
+ List<String> inputImageNames = new ArrayList<>(nameToUrl1.keySet());
|
|
|
|
+
|
|
|
|
+ inputImageNames.sort(Comparator.naturalOrder());
|
|
|
|
+
|
|
|
|
+ List<Map<String, String>> resultList = new ArrayList<>();
|
|
|
|
+ for (String inputImageName : inputImageNames) {
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ map.put("inputUrl", nameToUrl1.get(inputImageName));
|
|
|
|
+ map.put("outputUrl", nameToUrl2.get(inputImageName));
|
|
|
|
+ resultList.add(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resultList;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println("getImages error: " + e.getMessage());
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<String> getImageUrls(SysOssVo ossEntity, String path, String suffix) {
|
|
|
|
+ String urlPrefix = ossEntity.getUrl().substring(0, ossEntity.getUrl().lastIndexOf(".")) + suffix;
|
|
|
|
+ // 列出unzipPath下所有图片文件
|
|
|
|
+ File directory = new File(path);
|
|
|
|
+ File[] files = directory.listFiles();
|
|
|
|
+ List<String> imageList = Arrays.asList(files).stream().filter(file -> isImageFile(file)).map(file -> urlPrefix + "/" + file.getName()).toList();
|
|
|
|
+ return imageList;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 递归统计文件夹中的文件数量
|
|
* 递归统计文件夹中的文件数量
|
|
*
|
|
*
|