using System.Windows.Input; using VideoConcat.Models; using MessageBox = System.Windows.MessageBox; using VideoConcat.Common.Tools; using System.IO; using Microsoft.Expression.Drawing.Core; using FFMpegCore; using FFMpegCore.Enums; using static VideoConcat.Models.VideoModel; using System.Windows.Threading; using System.Windows; using VideoConcat.Services.Video; namespace VideoConcat.ViewModels { public class ExtractWindowViewModel { private ExtractWindowModel _extractWindowModel; public List ConcatVideos { get; set; } = []; public ExtractWindowModel ExtractWindowModel { get { return _extractWindowModel; } set { _extractWindowModel = value; } } public ExtractWindowViewModel() { ExtractWindowModel = new ExtractWindowModel { CanStart = false, IsStart = false, IsCanOperate = true, BtnOpenFolderCommand = new Command() { DoExcue = obj => { FolderBrowserDialog folderBrowserDialog = new(); if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { ExtractWindowModel.FolderPath = folderBrowserDialog.SelectedPath; LogUtils.Info($"获取视频文件夹,视频路径:{ExtractWindowModel.FolderPath}"); ListFolder(); } } }, BtnStartVideoConcatCommand = new Command() { DoExcue = obj => { ExtractWindowModel.HelpInfo = ""; Task.Run(action: () => { ExtractWindowModel.videos.ForEach(async (video) => { // 实例化并调用 var remover = new VideoProcess(); // 删除4秒处的帧(需根据实际帧位置调整) string _tmpPath = Path.GetDirectoryName(video) ?? ""; string _tmpFileName = $"抽帧视频-{Path.GetFileName(video)}"; await VideoProcess.RemoveFrameRandomeAsync(video, $"{_tmpPath}\\{_tmpFileName}"); }); }); ExtractWindowModel.HelpInfo = "全部完成!"; } } }; } private void ListFolder() { DirectoryInfo dir = new(ExtractWindowModel.FolderPath); try { DirectoryInfo dirD = dir as DirectoryInfo; //获取文件夹下所有视频文件 ExtractWindowModel.videos = Directory.GetFiles(dirD.FullName, "*.mp4"); ExtractWindowModel.SetCanStart(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } }