SIGN UP MEMBER LOGIN:    
ARTICLE

Get Frames/Images From Video in Asp.Net

Posted by Krishna Garad Articles | ASP.NET Programming January 20, 2011
In this article we will see how to get frames from a running video in ASP.Net.
Reader Level:
Download Files:
 


Introduction:

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.

Login to add your contents and source code to this article
share this article :
post comment
 

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

Posted by stephen aidoo Oct 26, 2011

No it's not possible FrameGrabber only crops the frame and save the frame not video.

Posted by Krishna Garad May 18, 2011

It's possible with FrameGrabber, save frames with .wmv/mpwg videos? PS: greate work :-)

Posted by Luis Fernandes May 15, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor