meer meer - 1 year ago 356
C# Question

get thumbnail image of video file in 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.

I have try this but not working.

Is that possible using .Net C#?

Answer Source

You can programmatically execute FFmpeg to generate a thumbnail image file. Then open the image file to use it however you wish.

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


    return LoadImage(thumbnail);

static Bitmap LoadImage(string path)
    var ms = new MemoryStream(File.ReadAllBytes(path));
    return (Bitmap)Image.FromStream(ms);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download