update
This commit is contained in:
parent
fb8eb20b74
commit
b656a17b35
@ -28,14 +28,14 @@ namespace VideoConcat
|
||||
|
||||
private void BtnLogin_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
if (txtUserName.Text == "admin" && txtPassword.Password == "&o4Fwag3xYUf")
|
||||
{
|
||||
Video video = new();
|
||||
Video video = new();
|
||||
video.Show();
|
||||
|
||||
this.Close();
|
||||
return;
|
||||
if (txtUserName.Text == "admin" && txtPassword.Password == "&o4Fwag3xYUf")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MessageBox.Show("用户名或者密码错误!");
|
||||
|
||||
108
Video.xaml.cs
108
Video.xaml.cs
@ -74,24 +74,19 @@ namespace VideoConcat
|
||||
startButton.IsEnabled = false;
|
||||
//GenerateAllvideos(videoFolders);
|
||||
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;
|
||||
});
|
||||
|
||||
});
|
||||
var dateEnd = DateTime.Now;
|
||||
var timeSpan = dateEnd - dateStart;//记录开票用时
|
||||
var timeSpan = dateEnd - dateStart;//记录用时
|
||||
|
||||
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();
|
||||
//int i = 0;
|
||||
//string vao = "";
|
||||
List<string> ooootext = [];
|
||||
|
||||
List<Task> ts = [];
|
||||
files.ForEach(file =>
|
||||
{
|
||||
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
|
||||
ts.Add(Task.Run(() =>
|
||||
{
|
||||
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);
|
||||
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.WriteAllLines(tmpConcatFile, ooootext, Encoding.UTF8);
|
||||
|
||||
File.WriteAllText(tmpConcatFile, string.Join("\n", [.. ooootext]), new System.Text.UTF8Encoding(false));
|
||||
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 = $"-i {combineFile} -filter_complex \"{vao} concat=n={i}:v=1:a=1 [v][a]\" -map \"[v]\" -map \"[a]\" {StrOutMp4Path}";
|
||||
Run_Command(StrArg);
|
||||
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}";
|
||||
Run_Command(StrArg);
|
||||
|
||||
if (File.Exists(tmpConcatFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(tmpConcatFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
if (File.Exists(tmpConcatFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(tmpConcatFile);
|
||||
}
|
||||
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<Task> tasks = [];
|
||||
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++)
|
||||
{
|
||||
|
||||
Task task = new(() =>
|
||||
int index = rd.Next(ls.Count);
|
||||
List<string> lsVideos = ls[index];
|
||||
var iIndex = i;
|
||||
tasks.Add(Task.Run(() =>
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
Random random = new();
|
||||
string randomString = random.Next(100000, 999999).ToString();
|
||||
string result = now.ToString("yyyyMMddHHmmss") + randomString;
|
||||
CombineMp4WithoutTxt(item, $"{outPut}\\{result}.mp4");
|
||||
});
|
||||
|
||||
tasks.Add(task);
|
||||
task.Start();
|
||||
|
||||
if (tasks.Count >= GenerateVideoCount)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Task combineTask = CombineMp4WithoutTxt(lsVideos, $"{outPut}\\{result}.mp4");
|
||||
combineTask.Wait();
|
||||
var dateEnd = DateTime.Now;
|
||||
WriteTxt($"视频{iIndex}拼接完成,用时{(dateEnd - now).TotalSeconds}秒");
|
||||
}));
|
||||
}
|
||||
|
||||
foreach (var item in tasks)
|
||||
{
|
||||
await item;
|
||||
}
|
||||
|
||||
return lss;
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
private static List<List<string>> GenerateAllvideos(Dictionary<int, string[]> dict)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user