fix(video): 解决并发环境下视频片段处理的文件名冲突问题
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good

- 为输出文件名添加时间戳和线程ID后缀,确保唯一性
-为临时文件名添加时间戳和线程ID后缀,防止并发冲突
- 避免因文件名重复导致的视频处理错误
This commit is contained in:
2025-09-26 14:26:09 +08:00
parent 4f1443a3ca
commit 1b2793215f

View File

@@ -299,7 +299,9 @@ public class VideoPieceGetter {
ffmpegTask.setFileList(listByDtRange); ffmpegTask.setFileList(listByDtRange);
ffmpegTask.setDuration(duration); ffmpegTask.setDuration(duration);
ffmpegTask.setOffsetStart(BigDecimal.valueOf(offset, 3)); 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()); ffmpegTask.setOutputFile(outFile.getAbsolutePath());
boolean result = startFfmpegTask(ffmpegTask); boolean result = startFfmpegTask(ffmpegTask);
if (!result) { if (!result) {
@@ -437,7 +439,9 @@ public class VideoPieceGetter {
boolean notOk = task.getFileList().stream().map(file -> { boolean notOk = task.getFileList().stream().map(file -> {
try { try {
if (file.isNeedDownload() || (!file.getName().endsWith(".ts"))) { 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); boolean result = convertMp4ToTs(file, tmpFile);
// 因为是并行转换,没法保证顺序,就直接存里面 // 因为是并行转换,没法保证顺序,就直接存里面
if (result) { if (result) {