C# 如何在 .Net 中获取视频缩略图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/155314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get a Video Thumbnail in .Net?
提问by Sam Saffron
I'm looking to implement a function that retrieves a single frame from an input video, so I can use it as a thumbnail.
我希望实现一个从输入视频中检索单个帧的函数,因此我可以将其用作缩略图。
Something along these lines should work:
沿着这些路线的东西应该工作:
// filename examples: "test.avi", "test.dvr-ms"
// position is from 0 to 100 percent (0.0 to 1.0)
// returns a bitmap
byte[] GetVideoThumbnail(string filename, float position)
{
}
Does anyone know how to do this in .Net 3.0?
有谁知道如何在 .Net 3.0 中做到这一点?
The correct solution will be the "best" implementation of this function. Bonus points for avoiding selection of blank frames.
正确的解决方案将是此功能的“最佳”实现。避免选择空白帧的奖励积分。
采纳答案by Sam Saffron
I ended up rolling my own stand alone class (with the single method I described), the source can be viewed here. Media browser isGPL but I am happy for the code I wrote for that file to be Public Domain. Keep in mind it uses interop from the directshow.netproject so you will have to clear that portion of the code with them.
我最终滚动了我自己的独立类(使用我描述的单一方法),可以在此处查看源代码。媒体浏览器是GPL,但我很高兴我为该文件编写的代码是公共域。请记住,它使用来自directshow.net项目的互操作,因此您必须使用它们清除该部分代码。
This class will not work for DVR-MS files, you need to inject a direct show filter for those.
此类不适用于 DVR-MS 文件,您需要为这些文件注入直接显示过滤器。
回答by Joel Martinez
This project will do the trick for AVIs: http://www.codeproject.com/KB/audio-video/avifilewrapper.aspx
该项目将为 AVI 提供技巧:http: //www.codeproject.com/KB/audio-video/avifilewrapper.aspx
Anything other formats, you might look into directshow. There are a few projects that might help:
http://sourceforge.net/projects/directshownet/
http://code.google.com/p/slimdx/
任何其他格式,您都可以查看 directshow。有一些项目可能会有所帮助:
http: //sourceforge.net/projects/directshownet/
http://code.google.com/p/slimdx/
回答by GuyWithDogs
There are some libraries at www.mitov.comthat may help. It's a generic wrapper for Directshow functionality, and I think one of the demos shows how to take a frame from a video file.
www.mitov.com上有一些图书馆可能会有所帮助。它是 Directshow 功能的通用包装器,我认为其中一个演示展示了如何从视频文件中获取帧。
回答by Ahmad Behjati
1- Get latest version of ffmpeg.exe from : http://ffmpeg.arrozcru.org/builds/
1- 从以下位置获取最新版本的 ffmpeg.exe:http: //ffmpeg.arrozcru.org/builds/
2- Extract the file and copy ffmpeg.exe to your website
2- 解压文件并将 ffmpeg.exe 复制到您的网站
3- Use this Code:
3- 使用此代码:
Process ffmpeg;
string video;
string thumb;
video = Server.MapPath("first.avi");
thumb = Server.MapPath("frame.jpg");
ffmpeg = new Process();
ffmpeg.StartInfo.Arguments = " -i "+video+" -ss 00:00:07 -vframes 1 -f image2 -vcodec mjpeg "+thumb;
ffmpeg.StartInfo.FileName = Server.MapPath("ffmpeg.exe");
ffmpeg.Start();