我使用ffmpeg成功为一个视频文件生成了缩略图,现在我想为目录中的每个视频创建缩略图。我该如何读取目录中的所有视频文件并使用ffmpeg为每个视频生成缩略图?
DirectoryIntoThumbNails(@"C:\VideoFolder", "*.mpg")
这段代码是用来将指定文件夹中的所有符合条件(以 .mpg 结尾)的视频文件转换为缩略图。void DirectoryIntoThumbNails(string sDir, string extension)
{
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d, extension))
{
SystemDiagnostics.Process.Start(@"C:\Ffmpeg.exe " + f + commandYouUsedSuccessfullyOnOneFile)
}
//Uncomment this if you want it to be recursive - all sub folders
//DirSearch(d, extension);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
试试这个
using System.IO;
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
filePaths
并为视频生成缩略图...