Commit 94d831a8e8add7832064c8a04b0e3fbb9dc13c20
1 parent
858ae0f0
只保留录像合并功能
Showing
6 changed files
with
24 additions
and
106 deletions
src/main/java/top/panll/assist/config/StartConfig.java deleted
100755 → 0
| 1 | -package top.panll.assist.config; | |
| 2 | - | |
| 3 | -import net.bramp.ffmpeg.FFmpeg; | |
| 4 | -import net.bramp.ffmpeg.FFprobe; | |
| 5 | -import org.slf4j.Logger; | |
| 6 | -import org.slf4j.LoggerFactory; | |
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | -import org.springframework.beans.factory.annotation.Value; | |
| 9 | -import org.springframework.boot.CommandLineRunner; | |
| 10 | -import org.springframework.core.annotation.Order; | |
| 11 | -import org.springframework.stereotype.Component; | |
| 12 | -import top.panll.assist.dto.UserSettings; | |
| 13 | -import top.panll.assist.service.FFmpegExecUtils; | |
| 14 | -import top.panll.assist.service.VideoFileService; | |
| 15 | - | |
| 16 | -import java.io.*; | |
| 17 | -import java.nio.charset.StandardCharsets; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * 用于启动检查环境 | |
| 21 | - */ | |
| 22 | -@Component | |
| 23 | -@Order(value=1) | |
| 24 | -public class StartConfig implements CommandLineRunner { | |
| 25 | - | |
| 26 | - private final static Logger logger = LoggerFactory.getLogger(StartConfig.class); | |
| 27 | - | |
| 28 | - @Value("${server.port}") | |
| 29 | - private String port; | |
| 30 | - | |
| 31 | - @Autowired | |
| 32 | - private UserSettings userSettings; | |
| 33 | - | |
| 34 | - @Autowired | |
| 35 | - private VideoFileService videoFileService; | |
| 36 | - | |
| 37 | - | |
| 38 | - @Override | |
| 39 | - public void run(String... args) { | |
| 40 | - String record = userSettings.getRecord(); | |
| 41 | - if (!record.endsWith(File.separator)) { | |
| 42 | - userSettings.setRecord(userSettings.getRecord() + File.separator); | |
| 43 | - } | |
| 44 | - | |
| 45 | - File recordFile = new File(record); | |
| 46 | - if (!recordFile.exists()){ | |
| 47 | - logger.warn("[userSettings.record]路径不存在,开始创建"); | |
| 48 | - boolean mkResult = recordFile.mkdirs(); | |
| 49 | - if (!mkResult) { | |
| 50 | - logger.info("[userSettings.record]目录创建失败"); | |
| 51 | - System.exit(1); | |
| 52 | - } | |
| 53 | - }else { | |
| 54 | - if ( !recordFile.isDirectory()) { | |
| 55 | - logger.warn("[userSettings.record]路径是文件,请修改为目录"); | |
| 56 | - System.exit(1); | |
| 57 | - } | |
| 58 | - if (!recordFile.canRead()) { | |
| 59 | - logger.error("[userSettings.record]路径无法读取"); | |
| 60 | - System.exit(1); | |
| 61 | - } | |
| 62 | - if (!recordFile.canWrite()) { | |
| 63 | - logger.error("[userSettings.record]路径无法写入"); | |
| 64 | - System.exit(1); | |
| 65 | - } | |
| 66 | - } | |
| 67 | - } | |
| 68 | -} |
src/main/java/top/panll/assist/config/WebMvcConfig.java
| ... | ... | @@ -17,7 +17,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { |
| 17 | 17 | |
| 18 | 18 | @Override |
| 19 | 19 | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| 20 | - File file = new File(userSettings.getRecord()); | |
| 20 | + File file = new File(userSettings.getRecordTempPath()); | |
| 21 | 21 | registry.addResourceHandler("/download/**").addResourceLocations("file://" + file.getAbsolutePath() + "/"); |
| 22 | 22 | super.addResourceHandlers(registry); |
| 23 | 23 | } | ... | ... |
src/main/java/top/panll/assist/dto/UserSettings.java
| ... | ... | @@ -13,12 +13,9 @@ public class UserSettings { |
| 13 | 13 | private String id; |
| 14 | 14 | |
| 15 | 15 | @Value("${userSettings.record}") |
| 16 | - private String record; | |
| 16 | + private String recordTempPath = "./recordTemp"; | |
| 17 | 17 | |
| 18 | - @Value("${userSettings.recordDay:7}") | |
| 19 | - private int recordDay; | |
| 20 | - | |
| 21 | - @Value("${userSettings.recordTempDay:-1}") | |
| 18 | + @Value("${userSettings.recordTempDay:7}") | |
| 22 | 19 | private int recordTempDay; |
| 23 | 20 | |
| 24 | 21 | @Value("${userSettings.ffmpeg}") |
| ... | ... | @@ -38,14 +35,6 @@ public class UserSettings { |
| 38 | 35 | this.id = id; |
| 39 | 36 | } |
| 40 | 37 | |
| 41 | - public String getRecord() { | |
| 42 | - return record; | |
| 43 | - } | |
| 44 | - | |
| 45 | - public void setRecord(String record) { | |
| 46 | - this.record = record; | |
| 47 | - } | |
| 48 | - | |
| 49 | 38 | public String getFfmpeg() { |
| 50 | 39 | return ffmpeg; |
| 51 | 40 | } |
| ... | ... | @@ -62,20 +51,9 @@ public class UserSettings { |
| 62 | 51 | this.ffprobe = ffprobe; |
| 63 | 52 | } |
| 64 | 53 | |
| 65 | - public int getRecordDay() { | |
| 66 | - return recordDay; | |
| 67 | - } | |
| 68 | - | |
| 69 | - public void setRecordDay(int recordDay) { | |
| 70 | - this.recordDay = recordDay; | |
| 71 | - } | |
| 72 | 54 | |
| 73 | 55 | public int getRecordTempDay() { |
| 74 | - if (recordTempDay == -1) { | |
| 75 | - return recordDay; | |
| 76 | - }else { | |
| 77 | - return recordTempDay; | |
| 78 | - } | |
| 56 | + return recordTempDay; | |
| 79 | 57 | } |
| 80 | 58 | |
| 81 | 59 | public void setRecordTempDay(int recordTempDay) { |
| ... | ... | @@ -89,4 +67,12 @@ public class UserSettings { |
| 89 | 67 | public void setThreads(int threads) { |
| 90 | 68 | this.threads = threads; |
| 91 | 69 | } |
| 70 | + | |
| 71 | + public String getRecordTempPath() { | |
| 72 | + return recordTempPath; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public void setRecordTempPath(String recordTempPath) { | |
| 76 | + this.recordTempPath = recordTempPath; | |
| 77 | + } | |
| 92 | 78 | } | ... | ... |
src/main/java/top/panll/assist/service/FileManagerTimer.java
| ... | ... | @@ -39,7 +39,7 @@ public class FileManagerTimer { |
| 39 | 39 | // @Scheduled(fixedDelay = 2000) //测试 20秒执行一次 |
| 40 | 40 | @Scheduled(cron = "0 0 0 * * ?") //每天的0点执行 |
| 41 | 41 | public void execute(){ |
| 42 | - if (userSettings.getRecord() == null) { | |
| 42 | + if (userSettings.getRecordTempPath() == null) { | |
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | 45 | |
| ... | ... | @@ -51,7 +51,7 @@ public class FileManagerTimer { |
| 51 | 51 | lastTempCalendar.add(Calendar.DAY_OF_MONTH, -recordTempDay); |
| 52 | 52 | lastTempDate = lastTempCalendar.getTime(); |
| 53 | 53 | logger.info("[录像巡查]移除合并任务临时文件 {} 之前的文件", formatter.format(lastTempDate)); |
| 54 | - File recordTempFile = new File(userSettings.getRecord()); | |
| 54 | + File recordTempFile = new File(userSettings.getRecordTempPath()); | |
| 55 | 55 | if (recordTempFile.exists() && recordTempFile.isDirectory() && recordTempFile.canWrite()) { |
| 56 | 56 | File[] tempFiles = recordTempFile.listFiles(); |
| 57 | 57 | if (tempFiles != null) { | ... | ... |
src/main/java/top/panll/assist/service/VideoFileService.java
| ... | ... | @@ -46,7 +46,7 @@ public class VideoFileService { |
| 46 | 46 | private final SimpleDateFormat simpleDateFormatForTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 47 | 47 | |
| 48 | 48 | public List<File> getAppList(Boolean sort) { |
| 49 | - File recordFile = new File(userSettings.getRecord()); | |
| 49 | + File recordFile = new File(userSettings.getRecordTempPath()); | |
| 50 | 50 | if (recordFile.isDirectory()) { |
| 51 | 51 | File[] files = recordFile.listFiles((File dir, String name) -> { |
| 52 | 52 | File currentFile = new File(dir.getAbsolutePath() + File.separator + name); |
| ... | ... | @@ -63,7 +63,7 @@ public class VideoFileService { |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public SpaceInfo getSpaceInfo(){ |
| 66 | - File recordFile = new File(userSettings.getRecord()); | |
| 66 | + File recordFile = new File(userSettings.getRecordTempPath()); | |
| 67 | 67 | SpaceInfo spaceInfo = new SpaceInfo(); |
| 68 | 68 | spaceInfo.setFree(recordFile.getFreeSpace()); |
| 69 | 69 | spaceInfo.setTotal(recordFile.getTotalSpace()); |
| ... | ... | @@ -116,7 +116,7 @@ public class VideoFileService { |
| 116 | 116 | logger.debug("获取[app: {}, stream: {}, statime: {}, endTime: {}]的视频", app, stream, |
| 117 | 117 | startTimeStr, endTimeStr); |
| 118 | 118 | |
| 119 | - File recordFile = new File(userSettings.getRecord()); | |
| 119 | + File recordFile = new File(userSettings.getRecordTempPath()); | |
| 120 | 120 | File streamFile = new File(recordFile.getAbsolutePath() + File.separator + app + File.separator + stream + File.separator); |
| 121 | 121 | if (!streamFile.exists()) { |
| 122 | 122 | logger.warn("获取[app: {}, stream: {}, statime: {}, endTime: {}]的视频时未找到目录: {}", app, stream, |
| ... | ... | @@ -223,7 +223,7 @@ public class VideoFileService { |
| 223 | 223 | fileList.add(file); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - File recordFile = new File(userSettings.getRecord() ); | |
| 226 | + File recordFile = new File(userSettings.getRecordTempPath() ); | |
| 227 | 227 | MergeOrCutTaskInfo mergeOrCutTaskInfo = new MergeOrCutTaskInfo(); |
| 228 | 228 | mergeOrCutTaskInfo.setId(taskId); |
| 229 | 229 | mergeOrCutTaskInfo.setApp(videoTaskInfo.getApp()); |
| ... | ... | @@ -238,7 +238,7 @@ public class VideoFileService { |
| 238 | 238 | mergeOrCutTaskInfo.setPercentage("1"); |
| 239 | 239 | // 处理文件路径 |
| 240 | 240 | String recordFileResultPath = recordFile.getAbsolutePath() + File.separator + taskId + ".mp4"; |
| 241 | - Path relativize = Paths.get(userSettings.getRecord()).relativize(Paths.get(recordFileResultPath)); | |
| 241 | + Path relativize = Paths.get(userSettings.getRecordTempPath()).relativize(Paths.get(recordFileResultPath)); | |
| 242 | 242 | try { |
| 243 | 243 | Files.copy(fileList.get(0).toPath(), Paths.get(recordFileResultPath)); |
| 244 | 244 | } catch (IOException e) { |
| ... | ... | @@ -260,7 +260,7 @@ public class VideoFileService { |
| 260 | 260 | mergeOrCutTaskInfo.setPercentage("1"); |
| 261 | 261 | |
| 262 | 262 | // 处理文件路径 |
| 263 | - Path relativize = Paths.get(userSettings.getRecord()).relativize(Paths.get(result)); | |
| 263 | + Path relativize = Paths.get(userSettings.getRecordTempPath()).relativize(Paths.get(result)); | |
| 264 | 264 | mergeOrCutTaskInfo.setRecordFile(relativize.toString()); |
| 265 | 265 | if (videoTaskInfo.getRemoteHost() != null) { |
| 266 | 266 | mergeOrCutTaskInfo.setDownloadFile(videoTaskInfo.getRemoteHost() + "/download.html?url=download/" + relativize); |
| ... | ... | @@ -376,7 +376,7 @@ public class VideoFileService { |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | public boolean collection(String app, String stream, String type) { |
| 379 | - File streamFile = new File(userSettings.getRecord() + File.separator + app + File.separator + stream); | |
| 379 | + File streamFile = new File(userSettings.getRecordTempPath() + File.separator + app + File.separator + stream); | |
| 380 | 380 | boolean result = false; |
| 381 | 381 | if (streamFile.exists() && streamFile.isDirectory() && streamFile.canWrite()) { |
| 382 | 382 | File signFile = new File(streamFile.getAbsolutePath() + File.separator + type + ".sign"); |
| ... | ... | @@ -390,7 +390,7 @@ public class VideoFileService { |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | public boolean removeCollection(String app, String stream, String type) { |
| 393 | - File signFile = new File(userSettings.getRecord() + File.separator + app + File.separator + stream + File.separator + type + ".sign"); | |
| 393 | + File signFile = new File(userSettings.getRecordTempPath() + File.separator + app + File.separator + stream + File.separator + type + ".sign"); | |
| 394 | 394 | boolean result = false; |
| 395 | 395 | if (signFile.exists() && signFile.isFile()) { |
| 396 | 396 | result = signFile.delete(); | ... | ... |
src/main/resources/all-application.yml
| ... | ... | @@ -29,9 +29,9 @@ server: |
| 29 | 29 | # [根据业务需求配置] |
| 30 | 30 | user-settings: |
| 31 | 31 | # [可选 ] zlm配置的录像路径,不配置则使用当前目录下的record目录 即: ./record |
| 32 | - record: /media/lin/Server/ZLMediaKit/dev/ZLMediaKit/release/linux/Debug/www/record | |
| 32 | + record-temp-path: ./recordTemp | |
| 33 | 33 | # [可选 ] 录像保存时长(单位: 天)每天晚12点自动对过期文件执行清理, 不配置则不删除 |
| 34 | - recordDay: 7 | |
| 34 | + record-temp-day: 7 | |
| 35 | 35 | # [可选 ] 录像下载合成临时文件保存时长, 不配置默认取值recordDay(单位: 天)每天晚12点自动对过期文件执行清理 |
| 36 | 36 | # recordTempDay: 7 |
| 37 | 37 | # [必选 ] ffmpeg路径 | ... | ... |