diff --git a/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java b/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java index 09448641..2fd4da1a 100644 --- a/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java +++ b/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java @@ -299,7 +299,9 @@ public class VideoPieceGetter { ffmpegTask.setFileList(listByDtRange); ffmpegTask.setDuration(duration); ffmpegTask.setOffsetStart(BigDecimal.valueOf(offset, 3)); - File outFile = new File(deviceId.toString() + "_" + faceSampleId + ".mp4"); + // 使用时间戳和线程ID确保输出文件名唯一性,避免并发冲突 + String uniqueSuffix = System.currentTimeMillis() + "_" + Thread.currentThread().getId(); + File outFile = new File(deviceId.toString() + "_" + faceSampleId + "_" + uniqueSuffix + ".mp4"); ffmpegTask.setOutputFile(outFile.getAbsolutePath()); boolean result = startFfmpegTask(ffmpegTask); if (!result) { @@ -437,7 +439,9 @@ public class VideoPieceGetter { boolean notOk = task.getFileList().stream().map(file -> { try { if (file.isNeedDownload() || (!file.getName().endsWith(".ts"))) { - String tmpFile = file.getName() + ".ts"; + // 使用时间戳和线程ID确保临时文件名唯一性,避免并发冲突 + String uniqueSuffix = System.currentTimeMillis() + "_" + Thread.currentThread().getId(); + String tmpFile = file.getName() + "_" + uniqueSuffix + ".ts"; boolean result = convertMp4ToTs(file, tmpFile); // 因为是并行转换,没法保证顺序,就直接存里面 if (result) {