VideoConcat/Video.xaml.cs
2024-10-30 20:22:01 +08:00

111 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.Win32;
using System.IO;
using System.Windows;
namespace VideoConcat
{
/// <summary>
/// Video.xaml 的交互逻辑
/// </summary>
public partial class Video : Window
{
public string text = "";
public Video()
{
InitializeComponent();
Check_Folder();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
startButton.IsEnabled = false;
await Task.Run(() =>
{
for (int i = 0; i <= 100; i++)
{
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
processVideoBar.Dispatcher.Invoke(() =>
{
processVideoBar.Value = i;
});
outputTxt.Dispatcher.Invoke(new Action(() =>
{
WriteTxt("正在生成第" + i + "个视频");
}));
});
System.Threading.Thread.Sleep(50);
}
startButton.Dispatcher.Invoke(() =>
{
startButton.IsEnabled = true;
});
});//ProcessVideo.RunTask(processVideoBar, startButton)
}
private void Check_Folder()
{
string currentPath = Directory.GetCurrentDirectory();
DirectoryInfo? parentPathInfo = Directory.GetParent(currentPath);
if (parentPathInfo == null)
{
WriteTxt("获取相关视频文件目录失败!");
return;
}
WriteTxt("当前目录为:" + parentPathInfo.FullName);
try
{
Boolean hasHead = false;
Boolean hasTail = false;
DirectoryInfo dirD = parentPathInfo as DirectoryInfo;
FileSystemInfo[] folders = dirD.GetDirectories();//获取文件夹下所有文件和文件夹
//对单个FileSystemInfo进行判断如果是文件夹则进行递归操作
foreach (FileSystemInfo folder in folders)
{
WriteTxt($"{folder.Name}");
if (folder.Name == "head")
{
hasHead = true;
}
if (folder.Name == "tail")
{
hasTail = true;
}
}
if (!hasHead)
{
WriteTxt("存在名称为head的文件夹将作为视频开头");
}
if (!hasTail)
{
WriteTxt("存在名称为tail的文件夹将作为视频结尾");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
private void WriteTxt(string str)
{
text += str + "\r\n";
outputTxt.Text = text;
scrowText.ScrollToEnd();
}
}
}