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

@ -28,14 +28,14 @@ namespace VideoConcat
private void BtnLogin_Click(object sender, RoutedEventArgs e) private void BtnLogin_Click(object sender, RoutedEventArgs e)
{ {
Video video = new();
if (txtUserName.Text == "admin" && txtPassword.Password == "&o4Fwag3xYUf")
{
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,24 +74,19 @@ 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); await MockIOPerformanceAsync(lists);
await MockIOPerformanceAsync(lists); startButton.Dispatcher.Invoke(() =>
startButton.Dispatcher.Invoke(() =>
{ {
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,49 +188,59 @@ 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 =>
{ {
string tmpOut = $"{Directory.GetCurrentDirectory()}\\temp\\{Guid.NewGuid()}{random.Next(100000, 999999)}.mp4"; ts.Add(Task.Run(() =>
// ffmpeg.exe - i a.mp4 - ac 1 - ar 48000 - vcodec copy a_re.mp4 {
WriteTxt(file + "转换开始");
var dateStart = DateTime.Now;
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
Run_Command($"-i \"{file}\" -c:v libx264 -c:a aac {tmpOut}");
ooootext.Add($"file '{tmpOut}'");
var dateEnd = DateTime.Now;
WriteTxt($"{file}转换已完成,用时{(dateEnd - dateStart).TotalSeconds}秒");
}));
Run_Command($"-i \"{file}\" -c:v libx264 -c:a aac {tmpOut}");
ooootext.Add($"file '{tmpOut}'");
}); });
log.Info(ooootext); log.Info(ooootext);
await Task.WhenAll(ts).ContinueWith(t =>
{
string tmpConcatFile = $"{Directory.GetCurrentDirectory()}\\temp\\{Guid.NewGuid()}{random.Next(100000, 999999)}";
// 也可以指定编码方式
//File.WriteAllLines(tmpConcatFile, ooootext, Encoding.UTF8);
string tmpConcatFile = $"{Directory.GetCurrentDirectory()}\\temp\\{Guid.NewGuid()}{random.Next(100000, 999999)}"; File.WriteAllText(tmpConcatFile, string.Join("\n", [.. ooootext]), new System.Text.UTF8Encoding(false));
// 也可以指定编码方式
//File.WriteAllLines(tmpConcatFile, ooootext, Encoding.UTF8);
File.WriteAllText(tmpConcatFile, string.Join("\n", [.. ooootext]), new System.Text.UTF8Encoding(false));
string StrArg = $"-f concat -safe 0 -i {tmpConcatFile} -c copy {StrOutMp4Path}"; string StrArg = $"-f concat -safe 0 -i {tmpConcatFile} -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}";
Run_Command(StrArg); Run_Command(StrArg);
if (File.Exists(tmpConcatFile)) if (File.Exists(tmpConcatFile))
{ {
try try
{ {
File.Delete(tmpConcatFile); File.Delete(tmpConcatFile);
} }
catch catch
{ {
}
}
}
}
});
} }
@ -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)