|
@@ -0,0 +1,61 @@
|
|
|
+package com.iden.bms.service;
|
|
|
+
|
|
|
+import com.iden.common.util.FileUtil;
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wyy
|
|
|
+ * @subject
|
|
|
+ * @creat 2023/2/18
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class StreamService {
|
|
|
+ @Value("${iden.root:#{null}}")
|
|
|
+ private String idenRoot;
|
|
|
+
|
|
|
+ @Value("${stream.root:#{null}}")
|
|
|
+ private String streamRoot;
|
|
|
+ private final Logger logger = LogManager.getLogger(StreamService.class);
|
|
|
+
|
|
|
+ public void transferVideo(){
|
|
|
+ logger.info("StreamService.transferVideo-----------start");
|
|
|
+ //将视频从流媒体同步到schedule目录
|
|
|
+ File flowVideoDirFile = new File(streamRoot);//流媒体存放视频路径
|
|
|
+ if (flowVideoDirFile.isDirectory()) {
|
|
|
+ File[] flowCodeDirs = flowVideoDirFile.listFiles();
|
|
|
+ if (flowCodeDirs != null && flowCodeDirs.length > 0) {
|
|
|
+ for (File flowCodedir : flowCodeDirs) {
|
|
|
+ if (flowCodedir.isDirectory()) {
|
|
|
+ File[] flowVideoFiles = FileUtil.sortByName(flowCodedir.listFiles());
|
|
|
+ if (flowVideoFiles != null && flowVideoFiles.length > 0) {
|
|
|
+ for (File flowVideoFile : flowVideoFiles) {
|
|
|
+ long beginLength = flowVideoFile.length();
|
|
|
+ File targetVideoDir = new File(idenRoot+"data/origin/camera/video/"+flowCodedir.getName());//iden-schedule存放路径
|
|
|
+ logger.info("StreamService.handleVideo ...flowCodedir.getName() == " + flowCodedir.getName());
|
|
|
+ if (!targetVideoDir.exists()) {
|
|
|
+ targetVideoDir.mkdirs();
|
|
|
+ }
|
|
|
+ logger.info("targetVideoDir.getAbsolutePath()-------------"+targetVideoDir.getAbsolutePath());
|
|
|
+ File targetVideoFile = new File(targetVideoDir,flowVideoFile.getName());
|
|
|
+ if(beginLength!=flowVideoFile.length()){
|
|
|
+ continue;
|
|
|
+ }else{
|
|
|
+ flowVideoFile.renameTo(targetVideoFile);//把视频文件移动到最终目录
|
|
|
+ logger.info("视频文件移动完毕----");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("StreamService.transferVideo------ -----end");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|