Jump to content

Need help understanding this C# code

Shammikit

i want to generate a image from video using C#. dont know how to get this done,so i checked online and found this code below but im having trouble understanding it.if anyone could explain what it does in a simple way as im not very good in programming it would be very helpful.thanks

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
    };

    process.Start();
    process.WaitForExit(5000);

    return LoadImage(thumbnail);
}

static Bitmap LoadImage(string path)
{
    var ms = new MemoryStream(File.ReadAllBytes(path));
    return (Bitmap)Image.FromStream(ms);
}

source: https://stackoverflow.com/questions/15702031/get-thumbnail-image-of-video-file-in-c-sharp

Link to comment
Share on other sites

Link to post
Share on other sites

Basically, the code is running FFmpeg from the command line using the Process class.

 

Here is some documentation to explain the Process classes in more detail

 

FFmpeg is generating an image from the specified video (ie: the video parameter) and saving it to the specified location (ie: the thumbnail parameter) which you can then load into your application (ie: the code in the LoadImage method).

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×