This commit is contained in:
xiang 2024-10-31 22:44:48 +08:00
parent 94d12c1a86
commit d00b3a414b

View File

@ -1,6 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
using static System.Net.WebRequestMethods;
namespace VideoConcat namespace VideoConcat
{ {
@ -9,15 +10,14 @@ namespace VideoConcat
/// </summary> /// </summary>
public partial class Video : Window public partial class Video : Window
{ {
public string text = ""; public string text = "", outPut = "";
public FileSystemInfo[]? Floders { get; set; } public FileSystemInfo[]? Floders { get; set; }
public string[] Heads = []; public string[] Heads = [];
public string[] Tails = []; public string[] Tails = [];
public string[][] Middles = []; public List<string[]> Middles = [];
public DirectoryInfo? Path { get; set; } public DirectoryInfo? Path { get; set; }
public Video() public Video()
{ {
InitializeComponent(); InitializeComponent();
@ -50,44 +50,36 @@ namespace VideoConcat
startButton.IsEnabled = false; startButton.IsEnabled = false;
Array.ForEach(array: Middles, s =>
{
WriteTxt(s);
});
var dateStart = DateTime.Now; //记录用时的起始时间
List<List<string>> fpList = new List<List<string>>();
foreach (var item in await MockIOPerformanceAsync)
await Task.Run(async () =>
{ {
var dateEnd = DateTime.Now; var dateStart = DateTime.Now; //记录用时的起始时间
var timeSpan = dateEnd - dateStart;//记录开票用时
DebugText += item + " " + timeSpan.TotalSeconds + "\r\n";
}
await Task.Run(() =>
{
for (int i = 0; i <= count; i++) for (int i = 0; i <= count; i++)
{
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
processVideoBar.Dispatcher.Invoke(() =>
{
processVideoBar.Value = i;
});
outputTxt.Dispatcher.Invoke(new Action(() => {
{
WriteTxt("正在生成第" + i + "个视频"); await MockIOPerformanceAsync(Middles[i]);
})); //System.Windows.Application.Current.Dispatcher.Invoke(() =>
}); //{
System.Threading.Thread.Sleep(50); // processVideoBar.Dispatcher.Invoke(() =>
// {
// processVideoBar.Value = i;
// });
// outputTxt.Dispatcher.Invoke(new Action(() =>
// {
// WriteTxt("正在生成第" + i + "个视频");
// }));
//});
//System.Threading.Thread.Sleep(50);
} }
startButton.Dispatcher.Invoke(() => startButton.Dispatcher.Invoke(() =>
@ -95,6 +87,9 @@ namespace VideoConcat
startButton.IsEnabled = true; startButton.IsEnabled = true;
}); });
var dateEnd = DateTime.Now;
var timeSpan = dateEnd - dateStart;//记录开票用时
});//ProcessVideo.RunTask(processVideoBar, startButton) });//ProcessVideo.RunTask(processVideoBar, startButton)
} }
@ -138,7 +133,8 @@ namespace VideoConcat
continue; continue;
} }
Middles = Middles.Concat(GetAllVideos($"{Path}\\{folder.Name}")).ToArray(); string[] files = GetAllVideos($"{Path}\\{folder.Name}");
Middles.Add(files);
} }
if (!hasHead) if (!hasHead)
@ -150,6 +146,10 @@ namespace VideoConcat
{ {
WriteTxt("存在名称为tail的文件夹将作为视频结尾"); WriteTxt("存在名称为tail的文件夹将作为视频结尾");
} }
Middles.Insert(0, Heads);
Middles.Add(Tails);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -238,7 +238,7 @@ namespace VideoConcat
public void MakeOutPutDir() public void MakeOutPutDir()
{ {
string outPut = $"{Path}\\output"; outPut = $"{Path}\\output";
if (!Directory.Exists(outPut)) if (!Directory.Exists(outPut))
{ {
@ -246,7 +246,7 @@ namespace VideoConcat
} }
} }
public static async Task<IEnumerable<string>> MockIOPerformanceAsync(List<string> ls) public static async Task<IEnumerable<string>> MockIOPerformanceAsync(string[] ls)
{ {
List<string> lss = new List<string>(); List<string> lss = new List<string>();
List<Task> tasks = new List<Task>(); List<Task> tasks = new List<Task>();