This commit is contained in:
xiangbing 2026-01-10 19:26:09 +08:00
parent e4fe1c61e2
commit 21796d79b6

View File

@ -1,4 +1,4 @@
using FFMpegCore; using FFMpegCore;
using FFMpegCore.Enums; using FFMpegCore.Enums;
using Microsoft.Expression.Drawing.Core; using Microsoft.Expression.Drawing.Core;
using System.IO; using System.IO;
@ -125,9 +125,10 @@ namespace VideoConcat.ViewModels
string originalFileName = Path.GetFileNameWithoutExtension(currentVideo); string originalFileName = Path.GetFileNameWithoutExtension(currentVideo);
string extension = Path.GetExtension(currentVideo); string extension = Path.GetExtension(currentVideo);
// 生成唯一的文件名:原文件名_序号_方案.扩展名 // 生成唯一的文件名:原始名称+方案号+生成日期+序号
string modeSuffix = ExtractWindowModel.ExtractFrameMode == Models.ExtractFrameMode.DeleteFrame ? "方案1" : "方案2"; string modeSuffix = ExtractWindowModel.ExtractFrameMode == Models.ExtractFrameMode.DeleteFrame ? "方案1" : "方案2";
string _tmpFileName = $"{originalFileName}_{currentIndex:D4}_{modeSuffix}{extension}"; string dateStr = DateTime.Now.ToString("yyyyMMdd");
string _tmpFileName = $"{originalFileName}_{modeSuffix}_{dateStr}_{currentIndex:D4}{extension}";
string outPath = Path.Combine(_tmpPath, "out"); string outPath = Path.Combine(_tmpPath, "out");
LogUtils.Info($"准备创建输出目录:{outPath}"); LogUtils.Info($"准备创建输出目录:{outPath}");
@ -208,8 +209,7 @@ namespace VideoConcat.ViewModels
if (totalDuration < 20 && ExtractWindowModel.ExtractFrameMode == Models.ExtractFrameMode.DeleteFrame) if (totalDuration < 20 && ExtractWindowModel.ExtractFrameMode == Models.ExtractFrameMode.DeleteFrame)
{ {
string videoName = Path.GetFileName(currentVideo); string errorMsg = $"视频时长太短:{currentVideo}{totalDuration:F2}秒需要至少20秒";
string errorMsg = $"视频时长太短:{videoName}{totalDuration:F2}秒需要至少20秒";
LogUtils.Error(errorMsg); LogUtils.Error(errorMsg);
errorMessages.Add(errorMsg); errorMessages.Add(errorMsg);
@ -291,7 +291,7 @@ namespace VideoConcat.ViewModels
string outputSizeStr = $"{outputMB:F2}MB"; string outputSizeStr = $"{outputMB:F2}MB";
string durationStr = $"{taskDuration.TotalSeconds:F1}s"; string durationStr = $"{taskDuration.TotalSeconds:F1}s";
successMessages.Add($"{originalFileName} (第{currentIndex}个) - 成功"); successMessages.Add($"{currentVideo} (第{currentIndex}个) - 成功");
LogUtils.Info($"处理成功:{currentVideo} -> {outputPath}, 大小={outputMB:F2}MB, 耗时={taskDuration.TotalSeconds:F2}秒"); LogUtils.Info($"处理成功:{currentVideo} -> {outputPath}, 大小={outputMB:F2}MB, 耗时={taskDuration.TotalSeconds:F2}秒");
// 更新表格行 // 更新表格行
@ -315,7 +315,7 @@ namespace VideoConcat.ViewModels
else if (success) else if (success)
{ {
LogUtils.Warn($"处理返回成功但文件不存在:{outputPath}"); LogUtils.Warn($"处理返回成功但文件不存在:{outputPath}");
string errorMsg = $"{originalFileName} (第{currentIndex}个) - 返回成功但文件不存在"; string errorMsg = $"{currentVideo} (第{currentIndex}个) - 返回成功但文件不存在";
errorMessages.Add(errorMsg); errorMessages.Add(errorMsg);
ExtractWindowModel.Dispatcher.Invoke(() => ExtractWindowModel.Dispatcher.Invoke(() =>
@ -337,7 +337,7 @@ namespace VideoConcat.ViewModels
} }
else else
{ {
string errorMsg = $"{originalFileName} (第{currentIndex}个) - 处理失败"; string errorMsg = $"{currentVideo} (第{currentIndex}个) - 处理失败";
LogUtils.Error($"{errorMsg} -> {outputPath}"); LogUtils.Error($"{errorMsg} -> {outputPath}");
errorMessages.Add(errorMsg); errorMessages.Add(errorMsg);
@ -363,8 +363,7 @@ namespace VideoConcat.ViewModels
{ {
// 在异常处理中重新获取文件名等信息 // 在异常处理中重新获取文件名等信息
string originalFileNameForError = Path.GetFileNameWithoutExtension(currentVideo); string originalFileNameForError = Path.GetFileNameWithoutExtension(currentVideo);
string videoName = Path.GetFileName(currentVideo); string errorMsg = $"抽帧异常:{currentVideo} (第{currentIndex}个) - {ex.Message}";
string errorMsg = $"抽帧异常:{videoName} (第{currentIndex}个) - {ex.Message}";
LogUtils.Error($"抽帧失败:{currentVideo} (第{currentIndex}个)", ex); LogUtils.Error($"抽帧失败:{currentVideo} (第{currentIndex}个)", ex);
errorMessages.Add(errorMsg); errorMessages.Add(errorMsg);
@ -374,13 +373,14 @@ namespace VideoConcat.ViewModels
string displayFileNameForError = originalFileNameForError.Length > 15 ? originalFileNameForError.Substring(0, 12) + "..." : originalFileNameForError.PadRight(15); string displayFileNameForError = originalFileNameForError.Length > 15 ? originalFileNameForError.Substring(0, 12) + "..." : originalFileNameForError.PadRight(15);
string modeSuffixForError2 = ExtractWindowModel.ExtractFrameMode == Models.ExtractFrameMode.DeleteFrame ? "方案1" : "方案2"; string modeSuffixForError2 = ExtractWindowModel.ExtractFrameMode == Models.ExtractFrameMode.DeleteFrame ? "方案1" : "方案2";
string dateStrForError2 = DateTime.Now.ToString("yyyyMMdd");
ExtractWindowModel.Dispatcher.Invoke(() => ExtractWindowModel.Dispatcher.Invoke(() =>
{ {
var taskItem = new Models.ExtractTaskItem var taskItem = new Models.ExtractTaskItem
{ {
Index = currentIndex.ToString(), Index = currentIndex.ToString(),
FileName = displayFileNameForError, FileName = displayFileNameForError,
FullFileName = $"{originalFileNameForError}_{currentIndex:D4}_{modeSuffixForError2}{Path.GetExtension(currentVideo)}", FullFileName = $"{originalFileNameForError}_{modeSuffixForError2}_{dateStrForError2}_{currentIndex:D4}{Path.GetExtension(currentVideo)}",
Status = "异常", Status = "异常",
OriginalSize = "--", OriginalSize = "--",
OutputSize = "--", OutputSize = "--",