How do I get a Video Thumbnail in .Net?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 15:40:30

问题


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?

The correct solution will be the "best" implementation of this function. Bonus points for avoiding selection of blank frames.


回答1:


I ended up rolling my own stand alone class (with the single method I described), the source can be viewed here. Media browser is GPL 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.net project so you will have to clear that portion of the code with them.

This class will not work for DVR-MS files, you need to inject a direct show filter for those.




回答2:


This project will do the trick for AVIs: 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/




回答3:


1- Get latest version of ffmpeg.exe from : http://ffmpeg.arrozcru.org/builds/

2- Extract the file and copy ffmpeg.exe to your website

3- Use this Code:

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();



回答4:


There are some libraries at www.mitov.com that 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.




回答5:


This is also worth to see:

http://www.codeproject.com/Articles/13237/Extract-Frames-from-Video-Files



来源:https://stackoverflow.com/questions/155314/how-do-i-get-a-video-thumbnail-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!