Forráskód Böngészése

feat: 添加去抖动完善

WANGKANG 9 hónapja
szülő
commit
54848ec64e

+ 21 - 0
taais-admin/src/main/resources/application-dev.yml

@@ -159,3 +159,24 @@ sms:
       template-id: xxxxxxxx
       #您的sdkAppId
       sdk-app-id: 您的sdkAppId
+
+# Sa-Token配置
+sa-token:
+  # token名称 (同时也是cookie名称)
+  token-name: Authorization
+  # token固定超时 设为七天 (必定过期) 单位: 秒
+  timeout: 604800
+  # 多端不同 token 有效期 可查看 LoginHelper.loginByDevice 方法自定义
+  # token最低活跃时间 (指定时间无操作就过期) 单位: 秒
+  active-timeout: 604800
+  # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
+  is-concurrent: true
+  # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
+  is-share: false
+  # token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
+  token-style: uuid
+  # 是否输出操作日志
+  is-log: true
+  # jwt秘钥
+  jwt-secret-key: abcdefghijklmnopqrstuvwxyz
+  is-print: off #关闭控制台banner

+ 2 - 4
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/VideoStable.java

@@ -49,10 +49,8 @@ public class VideoStable extends BaseEntity {
      */
     private Long inputOssId;
 
-    /**
-     * 去抖动的图片集ossID
-     */
-    private Long outputOssId;
+    private String inputPath;
+    private String outputPath;
 
     /**
      * 开始时间

+ 3 - 4
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/bo/VideoStableBo.java

@@ -1,5 +1,6 @@
 package com.taais.biz.domain.bo;
 
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.taais.biz.domain.VideoStable;
 import io.github.linpeilie.annotations.AutoMapper;
 import jakarta.validation.constraints.NotBlank;
@@ -44,10 +45,8 @@ public class VideoStableBo extends BaseEntity{
     @NotNull(message = "输入图片集ossId不能为空")
     private Long inputOssId;
 
-    /**
-     * 去抖动的图片集ossId
-     */
-    private Long outputOssId;
+    private String inputPath;
+    private String outputPath;
 
     /**
      * 开始时间

+ 4 - 5
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/vo/VideoStableImportVo.java

@@ -35,10 +35,6 @@ public class VideoStableImportVo implements Serializable
     @ExcelProperty(value = "输入图片集ossId")
     private Long inputOssId;
 
-     /** 去抖动的图片集路径 */
-    @ExcelProperty(value = "去抖动的图片集ossId")
-    private Long outputOssId;
-
      /** 开始时间 */
     @ExcelProperty(value = "开始时间")
     private Date startTime;
@@ -63,5 +59,8 @@ public class VideoStableImportVo implements Serializable
     @ExcelProperty(value = "逻辑删除标志(0代表存在 1代表删除)")
     private Integer delFlag;
 
-
+    @ExcelProperty(value = "输入路径")
+    private String inputPath;
+    @ExcelProperty(value = "输出路径")
+    private String outputPath;
 }

+ 14 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/vo/VideoStableVo.java

@@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.taais.biz.domain.VideoStable;
 import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Builder;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import java.io.Serial;
@@ -69,4 +70,17 @@ private static final long serialVersionUID = 1L;
     /** 逻辑删除标志(0代表存在 1代表删除) */
     @ExcelProperty(value = "逻辑删除标志(0代表存在 1代表删除)")
     private Integer delFlag;
+
+    @ExcelProperty(value = "输入路径")
+    private String inputPath;
+    @ExcelProperty(value = "输出路径")
+    private String outputPath;
+
+    private Integer  block_size ;
+    private Integer  buffer_size;
+    private Integer  radius;
+    private Double cornerquality;
+    private Integer  cornerminDistance;
+    private Integer  lklevel;
+    private Integer  lkwinSiz;
 }

+ 85 - 23
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/VideoStableServiceImpl.java

@@ -1,6 +1,11 @@
 package com.taais.biz.service.impl;
 
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 import cn.hutool.core.util.ObjectUtil;
@@ -8,8 +13,12 @@ import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.query.QueryWrapper;
 import com.taais.biz.constant.BizConstant;
 import com.taais.biz.domain.bo.VideoStableStartResultBo;
+import com.taais.biz.utils.ZipUtils;
+import com.taais.common.core.config.TaaisConfig;
+import com.taais.common.core.constant.Constants;
 import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.utils.MapstructUtils;
+import com.taais.common.core.utils.StringUtils;
 import com.taais.common.json.utils.JsonUtils;
 import com.taais.common.orm.core.page.PageQuery;
 import com.taais.common.core.core.page.PageResult;
@@ -18,8 +27,13 @@ import com.taais.system.domain.vo.SysOssVo;
 import com.taais.system.service.ISysOssService;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -30,11 +44,6 @@ import com.taais.biz.domain.bo.VideoStableBo;
 import com.taais.biz.domain.vo.VideoStableVo;
 import com.taais.biz.service.IVideoStableService;
 
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
 import static com.taais.biz.domain.table.VideoStableTableDef.VIDEO_STABLE;
 
 /**
@@ -66,8 +75,6 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
             (videoStableBo.getName()));
         queryWrapper.and(VIDEO_STABLE.INPUT_OSS_ID.eq
             (videoStableBo.getInputOssId()));
-        queryWrapper.and(VIDEO_STABLE.OUTPUT_OSS_ID.eq
-            (videoStableBo.getOutputOssId()));
         queryWrapper.and(VIDEO_STABLE.START_TIME.eq
             (videoStableBo.getStartTime()));
         queryWrapper.and(VIDEO_STABLE.END_TIME.eq
@@ -143,6 +150,27 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
         return this.save(videoStable);// 使用全局配置的雪花算法主键生成器生成ID值
     }
 
+    public static String removeFileExtension(String fileName) {
+        int lastDotIndex = fileName.lastIndexOf('.');
+        if (lastDotIndex == -1) {
+            return fileName; // 如果没有找到'.',则返回原文件名
+        }
+        return fileName.substring(0, lastDotIndex);
+    }
+
+    public static void makeDir(String path) {
+        File folder = new File(path);
+        if (!folder.exists()) {
+            folder.mkdirs();
+        } else {
+            try {
+                FileUtils.cleanDirectory(folder);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
     /**
      * 修改视频去抖动
      *
@@ -175,26 +203,60 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
     public CommonResult start(Long id) {
         VideoStable videoStable = getById(id);
 
+        SysOssVo inputOssEntity = ossService.getById(videoStable.getInputOssId());
+
+        String filePath = inputOssEntity.getFileName();
+        String localPath = TaaisConfig.getProfile();
+        String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+
+        String fileName = StringUtils.substringAfterLast(filePath, "/");
+        String fileName_without_suffix = removeFileExtension(fileName);
+
+        Path path = Paths.get(resourcePath);
+        Path inputPath = path.resolveSibling(fileName_without_suffix + "_images");
+        Path outputPath = path.resolveSibling(fileName_without_suffix + "_stable");
+
+        makeDir(inputPath.toString());
+        makeDir(outputPath.toString());
+
+        ZipUtils.unzip(resourcePath, inputPath.toString());
+
+        videoStable.setInputPath(inputPath.toString());
+        videoStable.setOutputPath(outputPath.toString());
+
+        videoStable.setStartTime(new Date());
+
+        boolean flag = sendMsg(videoStable);
+        if (flag) {
+            videoStable.setStatus(BizConstant.VideoStatus.RUNNING);
+        } else {
+            videoStable.setEndTime(new Date());
+            videoStable.setStatus(BizConstant.VideoStatus.FAILED);
+        }
+
+        updateById(videoStable);
+        return CommonResult.success("start video_stable success");
+    }
+
+    public boolean sendMsg(VideoStable videoStable) {
         log.info("start video_stable_url: {}", video_stable_url);
-        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
-            HttpPost request = new HttpPost(video_stable_url);
-            // 设置请求体
-            System.out.println(JsonUtils.toJsonString(videoStable));
-            StringEntity entity = new StringEntity(JsonUtils.toJsonString(videoStable), "UTF-8");
-            entity.setContentType("application/json");
-            request.setEntity(entity);
+
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        HttpPost request = new HttpPost(video_stable_url);
+        // 设置请求体
+        System.out.println(JsonUtils.toJsonString(videoStable));
+        StringEntity entity = new StringEntity(JsonUtils.toJsonString(videoStable), "UTF-8");
+        entity.setContentType("application/json");
+        request.setEntity(entity);
+
+        try {
             CloseableHttpResponse response = httpClient.execute(request);
             String responseBody = EntityUtils.toString(response.getEntity());
-            System.out.println(responseBody);
-
-            videoStable.setStatus(BizConstant.VideoStatus.RUNNING);
-            updateById(videoStable);
-            return CommonResult.success("start video_stable success");
+            log.info("responseBody -> " + responseBody);
+            return true;
         } catch (Exception e) {
-            videoStable.setStatus(BizConstant.VideoStatus.FAILED);
-            updateById(videoStable);
-            e.printStackTrace();
-            return CommonResult.fail("start video_stable error -> " + e.getMessage());
+            log.error("sendMsg error", e);
+            return false;
         }
     }
 

+ 58 - 6
taais-modules/taais-biz/src/main/java/com/taais/biz/utils/ZipUtils.java

@@ -1,10 +1,9 @@
 package com.taais.biz.utils;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
 import java.util.zip.ZipOutputStream;
 
 public class ZipUtils {
@@ -20,11 +19,11 @@ public class ZipUtils {
         File sourceFolder = new File(sourceFolderPath);
         if (!sourceFolder.exists() || !sourceFolder.isDirectory()) {
             throw new IllegalArgumentException(
-                    "Source folder does not exist or is not a directory: " + sourceFolderPath);
+                "Source folder does not exist or is not a directory: " + sourceFolderPath);
         }
 
         try (FileOutputStream fos = new FileOutputStream(zipFilePath);
-                ZipOutputStream zos = new ZipOutputStream(fos)) {
+             ZipOutputStream zos = new ZipOutputStream(fos)) {
 
             File[] files = sourceFolder.listFiles();
             if (files != null) {
@@ -50,4 +49,57 @@ public class ZipUtils {
             zos.closeEntry();
         }
     }
+
+    public static boolean unzip(String zipFilePath, String targetDirectory) {
+        AtomicBoolean flag = new AtomicBoolean(true);
+        try {
+            // 创建目标目录
+            File destDir = new File(targetDirectory);
+            if (!destDir.exists()) {
+                destDir.mkdirs();
+            }
+
+            // 创建ZipFile对象
+            ZipFile zipFile = new ZipFile(zipFilePath);
+
+
+            // 遍历ZIP文件中的所有条目
+            zipFile.stream().forEach(entry -> {
+                // System.out.println("解压文件: " + entry.getName());
+                try {
+                    String entryName = entry.getName();
+                    File entryFile = new File(targetDirectory + File.separator + entryName);
+
+                    // 如果是目录,创建目录
+                    if (entry.isDirectory()) {
+                        entryFile.mkdirs();
+                    } else {
+                        // 创建父目录
+                        File parentDir = entryFile.getParentFile();
+                        if (!parentDir.exists()) {
+                            parentDir.mkdirs();
+                        }
+                        // 解压文件
+                        try (InputStream inputStream = zipFile.getInputStream(entry);
+                             FileOutputStream outputStream = new FileOutputStream(entryFile)) {
+                            byte[] buffer = new byte[1024];
+                            int len;
+                            while ((len = inputStream.read(buffer)) > 0) {
+                                outputStream.write(buffer, 0, len);
+                            }
+                        }
+                    }
+                } catch (IOException e) {
+                    flag.set(false);
+                    e.printStackTrace();
+                }
+            });
+
+            System.out.println("解压完成: " + targetDirectory);
+        } catch (IOException e) {
+            flag.set(false);
+            e.printStackTrace();
+        }
+        return flag.get();
+    }
 }