In this article we will see how to get frames from a running video in ASP.Net. To run the video I used the third party control as AspNetVideo.Net3, which required only the path of a video file to play the video.
For getting the first frame from the video file I used JockerSoft.Media library which has a set of methods for operations like crop the frame, save the frame from video file. This JockerSoft.Media has the following methods.
public static Bitmap GetFrameFromVideo(string videoFile, double percentagePosition);
public static Bitmap GetFrameFromVideo(string videoFile, double percentagePosition, Size target);
public static Bitmap GetFrameFromVideo(string videoFile, double percentagePosition, out double streamLength, Size target);
public static Size GetVideoSize(string videoFile);
public static void SaveFrameFromVideo(string videoFile, double percentagePosition, string outputBitmapFile);
public static void SaveFrameFromVideo(string videoFile, double percentagePosition, string outputBitmapFile, Size target);
public static void SaveFrameFromVideo(string videoFile, double percentagePosition, string outputBitmapFile, out double streamLength, Size target);
public static void SaveFramesFromVideo(string videoFile, double[] positions, string outputBitmapFiles);
For getting frame I used the Bitmap return type method GetFrameFromVideo() which takes the videofiles path and the percentage for frame and return the bitmap object. You can save also this bitmap and this JockerSoft provide method for getting and saving the frame on specified location also.
Using Code:
I'm just calling the methods of JockerSoft.Media library; for getting a frame from a video you can call this like
// Path of the video and frame storing path
string _videopath = Server.MapPath("~/Video/search.AVI");
string _imagepath = Server.MapPath("~/Frames/CropedImage.jpg");
// Getting Frame From Video only not storing.
Bitmap bmp = FrameGrabber.GetFrameFromVideo(_videopath, 0.2d);
//Storing return bmp from FrameGrabber Class.
bmp.Save(_imagepath, System.Drawing.Imaging.ImageFormat.Gif);
You get the frame and can also save the frame to a specified location that requires the path of video and the image path.
// Path of the video and frame storing path
string _videopath = Server.MapPath("~/Video/search.AVI");
string _imagepath = Server.MapPath("~/Frames/CropedImage.jpg");
FrameGrabber.SaveFrameFromVideo(_videopath, 0.2d, _imagepath);
bmp.Save(_imagepath, System.Drawing.Imaging.ImageFormat.Gif);
You can get more than one frame also with SaveFramesFromVideo(string videoFile, double[] positions, string outputBitmapFiles) which takes video file, position array and output file path for storing those frames on the specified location.
Conclusion:
In this way you can use the JockerSoft.Media and can crop the frames from video and can save those frames.
Comments and doubts are heartly welcome.

Winanjaya AmijoyoPosted Aug 16, 2019, 9:14 AM
Hi, nice article!.. can I run this on Net Core 2.2?.. plan to deploy on Linux CentOS 7, need your advice.. thanks
Amit JoshiPosted Nov 1, 2012, 4:30 PM
How can we crop a thumnail for a mp4 video format.PLease help me, its urgent.. :(
christian nonamePosted Jun 22, 2012, 3:52 AM
Hi.. I have tried to use this tool. It looks really cool. But I getting an error: "video not found" when calling keepFrameGrabber.GetFrameFromVideo(_videopath, 0.2d); I have tried MPEG-4 and .Avi.. and I KNOW the videos are located in the rigth path... Anybody got any ide what the problem is?
stephen aidooPosted Oct 26, 2011, 1:31 AM
hello thank you for such a great article. but i was wondering how to do this in vb since. am working on a project that requires the user to upload a video file to the website . but will like to just get a frame image from that video and showcase that thumbnail. the website was done with asp/vb. pls help. thanks
Luis FernandesPosted May 15, 2011, 10:02 AM
It's possible with FrameGrabber, save frames with .wmv/mpwg videos? PS: greate work :-)