diff --git a/Models/VideoModel.cs b/Models/VideoModel.cs index ad8cf1d..644cc91 100644 --- a/Models/VideoModel.cs +++ b/Models/VideoModel.cs @@ -23,12 +23,24 @@ namespace VideoConcat.Models private string _folderPath = ""; private string _auditImagePath = ""; private bool _canStart = false; + private bool _isCanOperate=false; private bool _isStart = false; private ObservableCollection _FolderInfos = []; private ObservableCollection _concatVideos = []; private Dispatcher _dispatcher; - public static int Index= 0; + public static int Index = 0; + + + public bool IsCanOperate + { + get => _isCanOperate; + set + { + _isCanOperate = value; + OnPropertyChanged(); + } + } public bool IsStart { @@ -93,10 +105,10 @@ namespace VideoConcat.Models { public int Index { set; get; } public string FileName { set; get; } = ""; - public int Size { set; get; } - public double Seconds { set; get; } - public int Status { set; get; } - public int Progress { set; get; } + public string Size { set; get; } = ""; + public int Seconds { set; get; } + public string Status { set; get; } = ""; + public string Progress { set; get; } = ""; } public ObservableCollection FolderInfos @@ -207,6 +219,7 @@ namespace VideoConcat.Models { CanStart = false; } + IsCanOperate = !IsStart; } public VideoModel() diff --git a/ViewModels/VideoViewModel.cs b/ViewModels/VideoViewModel.cs index 077244d..39f9b9d 100644 --- a/ViewModels/VideoViewModel.cs +++ b/ViewModels/VideoViewModel.cs @@ -8,6 +8,7 @@ using FFMpegCore; using FFMpegCore.Enums; using static VideoConcat.Models.VideoModel; using System.Windows.Threading; +using System.Windows; namespace VideoConcat.ViewModels { @@ -36,6 +37,7 @@ namespace VideoConcat.ViewModels ConcatVideos = [], MaxNum = 0, CanStart = false, + IsStart = false, BtnOpenFolderCommand = new Command() { @@ -87,13 +89,14 @@ namespace VideoConcat.ViewModels VideoModel.Dispatcher.Invoke(() => { VideoModel.ConcatVideos.Clear(); + VideoModel.IsStart = true; }); MessageBox.Show("开始合并视频"); if (Directory.Exists($"{VideoModel.FolderPath}\\output") == false) { Directory.CreateDirectory($"{VideoModel.FolderPath}\\output"); } - VideoModel.IsStart = true; + //开始时间 DateTime startTime = DateTime.Now; @@ -174,33 +177,16 @@ namespace VideoConcat.ViewModels string _tempFileName = $"{DateTime.Now:yyyyMMddHHmmss}{random.Next(100000, 999999)}.mp4"; string _outPutName = Path.Combine($"{VideoModel.FolderPath}", "output", _tempFileName); ; - //int _size = 0; - double _duration = 0; - var temporaryVideoParts = combination.Select(_ => + var temporaryVideoParts = combination.Select((_videoPath) => { - string _tempPath = Path.GetDirectoryName(_) ?? ""; - - IMediaAnalysis _mediaInfo =FFProbe.Analyse(_); - _duration += _mediaInfo.Duration.TotalSeconds; - - + string _tempPath = Path.GetDirectoryName(_videoPath) ?? ""; //GlobalFFOptions.Current.TemporaryFilesFolder - return Path.Combine(_tempPath, $"{Path.GetFileNameWithoutExtension(_)}{FileExtension.Ts}"); + return Path.Combine(_tempPath, $"{Path.GetFileNameWithoutExtension(_videoPath)}{FileExtension.Ts}"); }).ToArray(); + bool _isSuccess = false; - VideoModel.Dispatcher.Invoke(() => - { - VideoModel.ConcatVideos.Add(new ConcatVideo() - { - Index = VideoModel.ConcatVideos.Count + 1, - FileName = _tempFileName, - Size = 100, - Seconds = _duration, - Status = 1, - Progress = 100, - }); - }); + try { @@ -219,6 +205,21 @@ namespace VideoConcat.ViewModels //bool _isSuccess = FFMpeg.Join(_outPutName, [.. combination]); + VideoModel.Dispatcher.Invoke(() => + { + IMediaAnalysis _mediaInfo = FFProbe.Analyse(_outPutName); + FileInfo fileInfo = new(_outPutName); + + VideoModel.ConcatVideos.Add(new ConcatVideo() + { + Index = VideoModel.ConcatVideos.Count + 1, + FileName = _tempFileName, + Size = $"{fileInfo.Length / 1024 / 1024}MB", + Seconds = ((int)_mediaInfo.Duration.TotalSeconds), + Status = _isSuccess ? "拼接成功" : "拼接失败", + Progress = "100%", + }); + }); if (_isSuccess && VideoModel.AuditImagePath != "") diff --git a/Views/Video.xaml b/Views/Video.xaml index c62beb2..935f0f6 100644 --- a/Views/Video.xaml +++ b/Views/Video.xaml @@ -38,12 +38,12 @@ -