获得在C#中的视频文件的缩略图 [英] Get thumbnail image of video file in C#
本文介绍了获得在C#中的视频文件的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要显示在我的网站上列出的视频缩略图,我想从一个视频(从一个特定的时间)获取一个单帧并显示为缩略图。
I want to display thumbnails for videos listed on my site, I want to fetch a single frame from a video (from a particular time) and display them as thumbnails.
我也试试这个的http:// ramcrishna。 blogspot.com/2008/09/playing-videos-like-youtube-and.html 但不工作。
I have try this http://ramcrishna.blogspot.com/2008/09/playing-videos-like-youtube-and.html but is not working.
这是可能的使用.NET C#?
Is that possible using .NET C#?
推荐答案
您可以通过编程执行 FFmpeg的生成缩略图文件。然后打开图像文件,但是你想使用它。
You can programmatically execute FFmpeg to generate a thumbnail image file. Then open the image file to use it however you wish.
下面是一些示例code:
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);
}
这篇关于获得在C#中的视频文件的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文