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, //(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries) // app, or any theme specific resource dictionaries)
)] )]
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

View File

@ -27,18 +27,19 @@ namespace VideoConcat
} }
private void BtnLogin_Click(object sender, RoutedEventArgs e) private void BtnLogin_Click(object sender, RoutedEventArgs e)
{
if (txtUserName.Text == "admin" && txtPassword.Password == "&o4Fwag3xYUf")
{ {
Video video = new(); Video video = new();
video.Show(); video.Show();
if (txtUserName.Text == "admin" && txtPassword.Password == "123456")
{
this.Close(); this.Close();
return; return;
} }
MessageBox.Show("用户名或者密码错误!"); MessageBox.Show("用户名或者密码错误!");
txtUserName.Clear(); txtUserName.Clear();
//txtUserName.Text = "";
txtPassword.Clear(); txtPassword.Clear();
} }
} }

View File

@ -1,13 +1,16 @@
using System.Diagnostics; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Shapes; using System.Windows.Shapes;
using WPFDevelopers.Helpers; using WPFDevelopers.Helpers;
using static System.Net.WebRequestMethods;
using File = System.IO.File; using File = System.IO.File;
namespace VideoConcat namespace VideoConcat
{ {
/// <summary> /// <summary>
@ -19,33 +22,29 @@ namespace VideoConcat
public Dictionary<int, string[]> videoFolders = []; public Dictionary<int, string[]> videoFolders = [];
public DirectoryInfo Path; private static string Path = "", ParentPath = "";
public Dictionary<int, A> AllPublicCombinVideos = []; public Dictionary<int, A> AllPublicCombinVideos = [];
int GenerateVideoCount = 0; int GenerateVideoCount = 0;
public static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Video() public Video()
{ {
InitializeComponent(); InitializeComponent();
string currentPath = Directory.GetCurrentDirectory(); Init();
DirectoryInfo ExecParentPath = Directory.GetParent(currentPath) ?? new DirectoryInfo("");
if (ExecParentPath != null)
{
Path = ExecParentPath;
} }
public static void Init()
{
ParentPath = Directory.GetCurrentDirectory();
log4net.Config.XmlConfigurator.Configure();
} }
private async void Button_Click(object sender, RoutedEventArgs e) private async void Button_Click(object sender, RoutedEventArgs e)
{ {
try try
{ {
GenerateVideoCount = int.Parse(videoCount.Text); GenerateVideoCount = int.Parse(videoCount.Text);
@ -54,6 +53,7 @@ namespace VideoConcat
{ {
MessageBox.Show("请输入正确的数字"); MessageBox.Show("请输入正确的数字");
return; return;
} }
@ -91,13 +91,16 @@ namespace VideoConcat
private void Check_Folder() private void Check_Folder()
{ {
DirectoryInfo? directory = Directory.GetParent(ParentPath);
if (Path == null) if (directory == null)
{ {
WriteTxt("获取相关视频文件目录失败!"); WriteTxt("获取视频路径失败!");
return; return;
} }
WriteTxt("当前目录为:" + Path.FullName);
Path = directory.FullName;
WriteTxt("当前目录为:" + Path);
videoFolders.Clear(); videoFolders.Clear();
AllPublicCombinVideos.Clear(); AllPublicCombinVideos.Clear();
@ -111,7 +114,6 @@ namespace VideoConcat
string currentFolderPath = $"{Path}\\{folder}"; string currentFolderPath = $"{Path}\\{folder}";
if (Directory.Exists(currentFolderPath)) if (Directory.Exists(currentFolderPath))
{ {
WriteTxt(folder);
string[] videos = GetAllVideos(currentFolderPath); string[] videos = GetAllVideos(currentFolderPath);
if (videos.Length > 0) if (videos.Length > 0)
{ {
@ -143,6 +145,7 @@ namespace VideoConcat
} }
public static string[] GetAllVideos(string path) public static string[] GetAllVideos(string path)
{ {
return Directory.GetFiles(path, "*.mp4", SearchOption.AllDirectories); return Directory.GetFiles(path, "*.mp4", SearchOption.AllDirectories);
@ -159,16 +162,20 @@ namespace VideoConcat
//string vao = ""; //string vao = "";
List<string> ooootext = []; List<string> ooootext = [];
files.ForEach(file => { files.ForEach(file =>
{
ooootext.Add($"file '{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); 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}"; //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.WaitForExit();//阻塞等待进程结束
p.Close();//关闭进程 p.Close();//关闭进程
p.Dispose();//释放资源 p.Dispose();//释放资源
if (File.Exists(tmpConcatFile))
{
try
{
File.Delete(tmpConcatFile);
}
catch
{
}
}
} }
private void Output(object sendProcess, DataReceivedEventArgs output) private void Output(object sendProcess, DataReceivedEventArgs output)
{ {
if (!String.IsNullOrEmpty(output.Data)) if (!String.IsNullOrEmpty(output.Data))
{ {
WriteTxt(output.Data); log.Info(output.Data, null);
} }
} }
public void MakeOutPutDir() public void MakeOutPutDir()
{ {
outPut = $"{Path.FullName}\\output"; outPut = $"{Path}\\output";
if (!Directory.Exists(outPut)) if (!Directory.Exists(outPut))
{ {
@ -214,7 +233,7 @@ namespace VideoConcat
Task task = new(() => Task task = new(() =>
{ {
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
Random random = new Random(); Random random = new();
string randomString = random.Next(100000, 999999).ToString(); string randomString = random.Next(100000, 999999).ToString();
string result = now.ToString("yyyyMMddHHmmss") + randomString; string result = now.ToString("yyyyMMddHHmmss") + randomString;
CombineMp4WithoutTxt(item, $"{outPut}\\{result}.mp4"); CombineMp4WithoutTxt(item, $"{outPut}\\{result}.mp4");
@ -237,7 +256,7 @@ namespace VideoConcat
return lss; 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 = []; List<List<string>> ls = [];
@ -253,7 +272,7 @@ namespace VideoConcat
static List<List<string>> CalculatePermutations(List<List<string>> inputList) 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) void Permute(List<string> currentPermutation, int index)
@ -272,7 +291,9 @@ namespace VideoConcat
} }
} }
Permute(new List<string>(), 0); Permute([], 0);
return result; return result;
} }

View File

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