我正在开发一个程序,该程序扫描放置文件夹中的文件,并将它们注册到另一个需要文件持续时间的系统。到目前为止,我能找到的最佳解决方案是使用 MediaInfo 从标头获取持续时间,但由于某种原因,它往往需要几秒钟才能返回结果。
假设我有 1,000 个文件路径的列表,并且我想获取每个文件路径的持续时间,但获取持续时间需要 15 秒。对列表进行线性迭代只需要 4 个多小时,甚至并行运行 8 个任务也需要半个小时。根据我的测试,这将是最好的情况。
我尝试过使用 MediaInfo DLL 以及调用 .exe,两者似乎都有相似的处理时间。
DLL代码:
MediaInfo MI;
public Form1()
{
InitializeComponent();
MI = new MediaInfo();
}
private void button1_Click(object sender, EventArgs e)
{
MI.Open(textBox1.Text);
MI.Option("Inform", "Video;%Duration%");
label2.Text = MI.Inform();
MI.Close();
}
Run Code Online (Sandbox Code Playgroud)
可执行代码:
Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "MediaInfo.exe",
Arguments = $"--Output=Video;%Duration% \"{textBox1.Text}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
StringBuilder line = new StringBuilder();
proc.Start(); …Run Code Online (Sandbox Code Playgroud)