From 643a1eced182beeb6683472b8de7d80234234ffa Mon Sep 17 00:00:00 2001 From: xiang Date: Sun, 3 Nov 2024 22:26:17 +0800 Subject: [PATCH] update --- AssemblyInfo.cs | 2 ++ MainWindow.xaml.cs | 9 ++--- Video.xaml.cs | 83 +++++++++++++++++++++++++++++----------------- VideoConcat.csproj | 7 ++++ log4net.config | 30 +++++++++++++++++ 5 files changed, 96 insertions(+), 35 deletions(-) create mode 100644 log4net.config diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs index b0ec827..c3f67e4 100644 --- a/AssemblyInfo.cs +++ b/AssemblyInfo.cs @@ -8,3 +8,5 @@ using System.Windows; //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] + +[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)] diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index d2599f9..4a935fe 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -28,17 +28,18 @@ namespace VideoConcat private void BtnLogin_Click(object sender, RoutedEventArgs e) { - Video video = new(); - video.Show(); - if (txtUserName.Text == "admin" && txtPassword.Password == "123456") + + if (txtUserName.Text == "admin" && txtPassword.Password == "&o4Fwag3xYUf") { + Video video = new(); + video.Show(); this.Close(); return; } + MessageBox.Show("用户名或者密码错误!"); txtUserName.Clear(); - //txtUserName.Text = ""; txtPassword.Clear(); } } diff --git a/Video.xaml.cs b/Video.xaml.cs index 2d7bd85..871783a 100644 --- a/Video.xaml.cs +++ b/Video.xaml.cs @@ -1,13 +1,16 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Windows; using System.Windows.Shapes; using WPFDevelopers.Helpers; -using static System.Net.WebRequestMethods; + + using File = System.IO.File; + namespace VideoConcat { /// @@ -19,33 +22,29 @@ namespace VideoConcat public Dictionary videoFolders = []; - public DirectoryInfo Path; + private static string Path = "", ParentPath = ""; public Dictionary AllPublicCombinVideos = []; int GenerateVideoCount = 0; - - + public static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public Video() { InitializeComponent(); - string currentPath = Directory.GetCurrentDirectory(); - - DirectoryInfo ExecParentPath = Directory.GetParent(currentPath) ?? new DirectoryInfo(""); - if (ExecParentPath != null) - { - Path = ExecParentPath; - } + Init(); + } + public static void Init() + { + ParentPath = Directory.GetCurrentDirectory(); + log4net.Config.XmlConfigurator.Configure(); } private async void Button_Click(object sender, RoutedEventArgs e) { - - try { GenerateVideoCount = int.Parse(videoCount.Text); @@ -54,6 +53,7 @@ namespace VideoConcat { MessageBox.Show("请输入正确的数字"); + return; } @@ -91,13 +91,16 @@ namespace VideoConcat private void Check_Folder() { - - if (Path == null) + DirectoryInfo? directory = Directory.GetParent(ParentPath); + if (directory == null) { - WriteTxt("获取相关视频文件目录失败!"); + WriteTxt("获取视频路径失败!"); return; } - WriteTxt("当前目录为:" + Path.FullName); + + Path = directory.FullName; + + WriteTxt("当前目录为:" + Path); videoFolders.Clear(); AllPublicCombinVideos.Clear(); @@ -111,7 +114,6 @@ namespace VideoConcat string currentFolderPath = $"{Path}\\{folder}"; if (Directory.Exists(currentFolderPath)) { - WriteTxt(folder); string[] videos = GetAllVideos(currentFolderPath); if (videos.Length > 0) { @@ -120,7 +122,7 @@ namespace VideoConcat k++; } } - + } return; } @@ -143,6 +145,7 @@ namespace VideoConcat } + public static string[] GetAllVideos(string path) { return Directory.GetFiles(path, "*.mp4", SearchOption.AllDirectories); @@ -158,17 +161,21 @@ namespace VideoConcat //int i = 0; //string vao = ""; List ooootext = []; - - files.ForEach(file => { + + files.ForEach(file => + { ooootext.Add($"file '{file}'"); }); - string tmpConcatFile = $"{outPut}\\{Guid.NewGuid().ToString()}"; + + var random = new Random(); + string tmpConcatFile = $"{outPut}\\{Guid.NewGuid()}{random.Next(100000, 999999)}.aaa"; // 也可以指定编码方式 File.WriteAllLines(tmpConcatFile, ooootext, Encoding.ASCII); - - string StrArg = $"-f concat -safe 0 -i {tmpConcatFile} -c copy -bsf:a aac_adtstoasc -movflags +faststart {StrOutMp4Path}"; + + + string StrArg = $"-f concat -safe 0 -i {tmpConcatFile} -bsf:a aac_adtstoasc -movflags +faststart -c copy {StrOutMp4Path}"; //string StrArg = $"-i {combineFile} -filter_complex \"{vao} concat=n={i}:v=1:a=1 [v][a]\" -map \"[v]\" -map \"[a]\" {StrOutMp4Path}"; @@ -183,19 +190,31 @@ namespace VideoConcat p.WaitForExit();//阻塞等待进程结束 p.Close();//关闭进程 p.Dispose();//释放资源 + if (File.Exists(tmpConcatFile)) + { + try + { + File.Delete(tmpConcatFile); + } + catch + { + + } + } + } private void Output(object sendProcess, DataReceivedEventArgs output) { if (!String.IsNullOrEmpty(output.Data)) { - WriteTxt(output.Data); + log.Info(output.Data, null); } } public void MakeOutPutDir() { - outPut = $"{Path.FullName}\\output"; + outPut = $"{Path}\\output"; if (!Directory.Exists(outPut)) { @@ -214,7 +233,7 @@ namespace VideoConcat Task task = new(() => { DateTime now = DateTime.Now; - Random random = new Random(); + Random random = new(); string randomString = random.Next(100000, 999999).ToString(); string result = now.ToString("yyyyMMddHHmmss") + randomString; CombineMp4WithoutTxt(item, $"{outPut}\\{result}.mp4"); @@ -237,7 +256,7 @@ namespace VideoConcat return lss; } - private List> GenerateAllvideos(Dictionary dict) + private static List> GenerateAllvideos(Dictionary dict) { List> ls = []; @@ -253,7 +272,7 @@ namespace VideoConcat static List> CalculatePermutations(List> inputList) { - List> result = new List>(); + List> result = []; // 递归计算全排列的辅助函数 void Permute(List currentPermutation, int index) @@ -272,7 +291,9 @@ namespace VideoConcat } } - Permute(new List(), 0); + Permute([], 0); + + return result; } diff --git a/VideoConcat.csproj b/VideoConcat.csproj index 06f2158..abf24d8 100644 --- a/VideoConcat.csproj +++ b/VideoConcat.csproj @@ -9,6 +9,7 @@ + @@ -20,4 +21,10 @@ + + + PreserveNewest + + + diff --git a/log4net.config b/log4net.config new file mode 100644 index 0000000..79e928b --- /dev/null +++ b/log4net.config @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file