This commit is contained in:
xiang 2024-11-23 12:15:06 +08:00
parent fb8eb20b74
commit b656a17b35
2 changed files with 56 additions and 60 deletions

View File

@ -27,15 +27,15 @@ 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();
this.Close(); this.Close();
return; return;
if (txtUserName.Text == "admin" && txtPassword.Password == "&o4Fwag3xYUf")
{
} }
MessageBox.Show("用户名或者密码错误!"); MessageBox.Show("用户名或者密码错误!");

View File

@ -74,10 +74,6 @@ namespace VideoConcat
startButton.IsEnabled = false; startButton.IsEnabled = false;
//GenerateAllvideos(videoFolders); //GenerateAllvideos(videoFolders);
var dateStart = DateTime.Now; //记录用时的起始时间 var dateStart = DateTime.Now; //记录用时的起始时间
await Task.Run(async () =>
{
List<List<string>> lists = GenerateAllvideos(videoFolders); List<List<string>> lists = GenerateAllvideos(videoFolders);
@ -89,9 +85,8 @@ namespace VideoConcat
startButton.IsEnabled = true; startButton.IsEnabled = true;
}); });
});
var dateEnd = DateTime.Now; var dateEnd = DateTime.Now;
var timeSpan = dateEnd - dateStart;//记录开票用时 var timeSpan = dateEnd - dateStart;//记录用时
try try
{ {
@ -193,24 +188,34 @@ namespace VideoConcat
} }
public void CombineMp4WithoutTxt(List<string> files, string StrOutMp4Path) public async Task CombineMp4WithoutTxt(List<string> files, string StrOutMp4Path)
{ {
var random = new Random(); var random = new Random();
//int i = 0; //int i = 0;
//string vao = ""; //string vao = "";
List<string> ooootext = []; List<string> ooootext = [];
List<Task> ts = [];
files.ForEach(file => files.ForEach(file =>
{ {
ts.Add(Task.Run(() =>
{
WriteTxt(file + "转换开始");
var dateStart = DateTime.Now;
string tmpOut = $"{Directory.GetCurrentDirectory()}\\temp\\{Guid.NewGuid()}{random.Next(100000, 999999)}.mp4"; string tmpOut = $"{Directory.GetCurrentDirectory()}\\temp\\{Guid.NewGuid()}{random.Next(100000, 999999)}.mp4";
// ffmpeg.exe - i a.mp4 - ac 1 - ar 48000 - vcodec copy a_re.mp4 // ffmpeg.exe - i a.mp4 - ac 1 - ar 48000 - vcodec copy a_re.mp4
Run_Command($"-i \"{file}\" -c:v libx264 -c:a aac {tmpOut}"); Run_Command($"-i \"{file}\" -c:v libx264 -c:a aac {tmpOut}");
ooootext.Add($"file '{tmpOut}'"); ooootext.Add($"file '{tmpOut}'");
var dateEnd = DateTime.Now;
WriteTxt($"{file}转换已完成,用时{(dateEnd - dateStart).TotalSeconds}秒");
}));
}); });
log.Info(ooootext); log.Info(ooootext);
await Task.WhenAll(ts).ContinueWith(t =>
{
string tmpConcatFile = $"{Directory.GetCurrentDirectory()}\\temp\\{Guid.NewGuid()}{random.Next(100000, 999999)}"; string tmpConcatFile = $"{Directory.GetCurrentDirectory()}\\temp\\{Guid.NewGuid()}{random.Next(100000, 999999)}";
// 也可以指定编码方式 // 也可以指定编码方式
//File.WriteAllLines(tmpConcatFile, ooootext, Encoding.UTF8); //File.WriteAllLines(tmpConcatFile, ooootext, Encoding.UTF8);
@ -235,7 +240,7 @@ namespace VideoConcat
} }
} }
});
} }
@ -279,42 +284,33 @@ namespace VideoConcat
} }
} }
public async Task<IEnumerable<string>> MockIOPerformanceAsync(List<List<string>> ls) public async Task MockIOPerformanceAsync(List<List<string>> ls)
{ {
List<string> lss = []; List<string> lss = [];
List<Task> tasks = []; List<Task> tasks = [];
Random rd = new(); Random rd = new();
ls = [.. ls.OrderBy(x => rd.Next())]; //ls = [.. ls.OrderBy(x => rd.Next())];
foreach (var item in ls) for (int i = 0; i < GenerateVideoCount; i++)
{ {
int index = rd.Next(ls.Count);
Task task = new(() => List<string> lsVideos = ls[index];
var iIndex = i;
tasks.Add(Task.Run(() =>
{ {
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
Random random = new(); 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"); Task combineTask = CombineMp4WithoutTxt(lsVideos, $"{outPut}\\{result}.mp4");
}); combineTask.Wait();
var dateEnd = DateTime.Now;
tasks.Add(task); WriteTxt($"视频{iIndex}拼接完成,用时{(dateEnd - now).TotalSeconds}秒");
task.Start(); }));
if (tasks.Count >= GenerateVideoCount)
{
break;
} }
} await Task.WhenAll(tasks);
foreach (var item in tasks)
{
await item;
}
return lss;
} }
private static List<List<string>> GenerateAllvideos(Dictionary<int, string[]> dict) private static List<List<string>> GenerateAllvideos(Dictionary<int, string[]> dict)