diff --git a/Models/VideoModel.cs b/Models/VideoModel.cs index 81856ef..b8ff960 100644 --- a/Models/VideoModel.cs +++ b/Models/VideoModel.cs @@ -22,9 +22,22 @@ namespace VideoConcat.Models private string _folderPath = ""; private string _auditImagePath = ""; private bool _canStart = false; + private bool _isStart = false; private ObservableCollection _FolderInfos = []; + private ObservableCollection _concatVideos = []; + public bool IsStart + { + get => _isStart; + set + { + _isStart = value; + OnPropertyChanged(); + SetCanStart(); + } + } + public int Num { get => _num; @@ -45,7 +58,7 @@ namespace VideoConcat.Models OnPropertyChanged(); } } - + public int MaxNum { get => _maxNum; @@ -63,6 +76,17 @@ namespace VideoConcat.Models public List VideoPaths { set; get; } } + + public struct ConcatVideo + { + public string FileName { set; get; } + public int Size { set; get; } + public int Seconds { set; get; } + public int Status { set; get; } + public int Progress { set; get; } + + } + public ObservableCollection FolderInfos { get { return _FolderInfos; } @@ -82,6 +106,17 @@ namespace VideoConcat.Models } } + + public ObservableCollection ConcatVideos + { + get { return _concatVideos; } + set + { + _concatVideos = value; + OnPropertyChanged(); + } + } + public string FolderPath { get { return _folderPath; } @@ -143,7 +178,7 @@ namespace VideoConcat.Models public void SetCanStart() { - if (Num > 0 && Num <= MaxNum) + if (Num > 0 && Num <= MaxNum && IsStart == false) { CanStart = true; } diff --git a/ViewModels/VideoViewModel.cs b/ViewModels/VideoViewModel.cs index 1c35ba1..50bfde8 100644 --- a/ViewModels/VideoViewModel.cs +++ b/ViewModels/VideoViewModel.cs @@ -5,7 +5,6 @@ using VideoConcat.Common.Tools; using System.IO; using Microsoft.Expression.Drawing.Core; using FFMpegCore; -using FFMpegCore.Arguments; namespace VideoConcat.ViewModels { @@ -28,6 +27,7 @@ namespace VideoConcat.ViewModels VideoModel = new VideoModel { FolderInfos = [], + ConcatVideos = [], MaxNum = 0, CanStart = false, BtnOpenFolderCommand = new Command() @@ -77,6 +77,8 @@ namespace VideoConcat.ViewModels { Task.Run(action: () => { + MessageBox.Show("开始合并视频"); + VideoModel.IsStart = true; //开始时间 DateTime startTime = DateTime.Now; @@ -116,17 +118,20 @@ namespace VideoConcat.ViewModels { taskList.Add(Task.Run(() => { + try { - if (Directory.Exists($"{VideoModel.FolderPath}/output") == false) + if (Directory.Exists($"{VideoModel.FolderPath}\\output") == false) { - Directory.CreateDirectory($"{VideoModel.FolderPath}/output"); + Directory.CreateDirectory($"{VideoModel.FolderPath}\\output"); } - string _outPutName = $"{VideoModel.FolderPath}/output/{random.Next(100000, 999999)}.mp4"; + string _outPutName = $"{VideoModel.FolderPath}\\output\\{DateTime.Now:yyyyMMddHHmmss}{random.Next(100000, 999999)}.mp4"; + string _outPutNameImg = $"{VideoModel.FolderPath}\\output\\{DateTime.Now:yyyyMMddHHmmss}{random.Next(100000, 999999)}.mp4"; bool _isSuccess = FFMpeg.Join(_outPutName, [.. combination]); + if (_isSuccess && VideoModel.AuditImagePath != "") { // 使用 FFMpegCore 执行添加图片到视频的操作 @@ -134,9 +139,9 @@ namespace VideoConcat.ViewModels { // 配置 FFmpeg 二进制文件位置(如果 FFmpeg 不在系统路径中) // GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "path/to/ffmpeg/bin" }); - string _outPutNameImg = $"{VideoModel.FolderPath}/output/{random.Next(100000, 999999)}.mp4"; + string _customArg = "-filter_complex \"[0:v][1:v] overlay=0:H-h\" "; // 使用 FFMpegArguments 构建命令 bool _isCoverSuccess = FFMpegArguments .FromFileInput(_outPutName) @@ -144,7 +149,7 @@ namespace VideoConcat.ViewModels .OutputToFile( _outPutNameImg, true, - options => options.WithCustomArgument("-filter_complex \"[0:v][1:v] overlay=0:0\" ") + options => options.WithCustomArgument(_customArg) ) .ProcessSynchronously(); @@ -175,6 +180,8 @@ namespace VideoConcat.ViewModels //结束时间 DateTime endTime = DateTime.Now; LogUtils.Info($"所有视频拼接完成,用时{(endTime - startTime).TotalSeconds}秒"); + VideoModel.IsStart = false; + MessageBox.Show("所有视频拼接完成"); }); }); } diff --git a/Views/Video.xaml b/Views/Video.xaml index 0a696bb..9f53147 100644 --- a/Views/Video.xaml +++ b/Views/Video.xaml @@ -40,7 +40,7 @@