You can programmatically execute FFmpeg to generate a thumbnail image file. Then open the image file to use it however you wish.
Here is some sample code:
public static Bitmap GetThumbnail(string video, string thumbnail)
{
var cmd = "ffmpeg -itsoffset -1 -i " + '"' + video + '"' + " -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 " + '"' + thumbnail + '"';
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = "/C " + cmd
};
var process = new Process
{
StartInfo = startInfo
};
process.Start();
process.WaitForExit(5000);
return LoadImage(thumbnail);
}
static Bitmap LoadImage(string path)
{
var ms = new MemoryStream(File.ReadAllBytes(path));
return (Bitmap)Image.FromStream(ms);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…