This commit is contained in:
xiang 2024-11-03 22:26:17 +08:00
parent 788ae8ab5f
commit 643a1eced1
5 changed files with 96 additions and 35 deletions

View File

@ -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)]

View File

@ -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();
}
}

View File

@ -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
{
/// <summary>
@ -19,33 +22,29 @@ namespace VideoConcat
public Dictionary<int, string[]> videoFolders = [];
public DirectoryInfo Path;
private static string Path = "", ParentPath = "";
public Dictionary<int, A> 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)
{
@ -143,6 +145,7 @@ namespace VideoConcat
}
public static string[] GetAllVideos(string path)
{
return Directory.GetFiles(path, "*.mp4", SearchOption.AllDirectories);
@ -159,16 +162,20 @@ namespace VideoConcat
//string vao = "";
List<string> 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<List<string>> GenerateAllvideos(Dictionary<int, string[]> dict)
private static List<List<string>> GenerateAllvideos(Dictionary<int, string[]> dict)
{
List<List<string>> ls = [];
@ -253,7 +272,7 @@ namespace VideoConcat
static List<List<string>> CalculatePermutations(List<List<string>> inputList)
{
List<List<string>> result = new List<List<string>>();
List<List<string>> result = [];
// 递归计算全排列的辅助函数
void Permute(List<string> currentPermutation, int index)
@ -272,7 +291,9 @@ namespace VideoConcat
}
}
Permute(new List<string>(), 0);
Permute([], 0);
return result;
}

View File

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="3.0.2" />
<PackageReference Include="MaterialDesignXaml.DialogsHelper" Version="1.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="WPFDevelopers" Version="0.0.0.1" />
@ -20,4 +21,10 @@
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<None Update="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

30
log4net.config Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<!-- 将日志以回滚文件的形式写到文件中 -->
<!-- 按日期切分日志文件,并将日期作为日志文件的名字 -->
<appender name="Log4Name" type="log4net.Appender.RollingFileAppender">
<!--不加utf-8编码格式中文字符将显示成乱码-->
<param name="Encoding" value="utf-8" />
<file value="Log/"/>
<appendToFile value="true" />
<rollingStyle value="Date" />
<!--日期的格式,每天换一个文件记录,如不设置则永远只记录一天的日志,需设置-->
<datePattern value="yyyyMMdd'.log'"/>
<!--日志文件名是否为静态-->
<StaticLogFileName value="false"/>
<!--多线程时采用最小锁定-->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<!--布局(向用户显示最后经过格式化的输出信息)-->
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="{'Level':'%-5level','time':'%date{HHmmss}','msg':%message%n}"/>
</layout>
</appender>
<root>
<!-- 控制级别由低到高ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF -->
<!-- 比如定义级别为INFO则INFO级别向下的级别比如DEBUG日志将不会被记录 -->
<!-- 如果没有定义LEVEL的值则缺省为DEBUG -->
<level value="ALL" />
<!-- 按日期切分日志文件,并将日期作为日志文件的名字 -->
<appender-ref ref="Log4Name"/>
</root>
</log4net>