Click or drag to resize

General Samples

//Loop through all frame without saving
using (var videoFrameReader = new VideoFrameReader(@"C:\Video.mp4"))
{
    var frameIndex = 0;

    while (videoFrameReader.Read())
    {
        Console.WriteLine("Coded Frame Number: " + videoFrameReader.CurrentFrameNumber);
        Console.WriteLine("Frame Index: " + frameIndex);

        frameIndex++;
    }
}
//Save every frame
using (var videoFrameReader = new VideoFrameReader(@"C:\Video.mp4"))
{
    var frameIndex = 0;

    foreach (var frame in videoFrameReader)
    {
        using (frame)
            frame.Save(string.Format(@"C:\Frame{0}.jpg", frameIndex), ImageFormat.Jpeg);

        frameIndex++;
    }
}
//Save every 100th frame
using (var videoFrameReader = new VideoFrameReader(@"C:\Video.mp4"))
{
    var frameIndex = 0;

    while (videoFrameReader.Read())
    {
        if (frameIndex % 100 == 0)
            using (var frame = videoFrameReader.GetFrame())
                frame.Save(string.Format(@"C:\Frame{0}.jpg", frameIndex), ImageFormat.Jpeg);

        frameIndex++;
    }
}
using (var videoFrameReader = new VideoFrameReader(@"C:\Video.mp4"))
{
    videoFrameReader.Seek(videoFrameReader.Duration.TotalSeconds / 2);

    if (videoFrameReader.Read())
        Console.WriteLine("Seeked Frame Number: " + videoFrameReader.CurrentFrameNumber);
    else
        Console.WriteLine("Frame read failed!");
}
using (var videoThumbnailer = new VideoThumbnailer(@"C:\Video.mp4"))
{
    //Get the thumbnail with 100x100 maximum size and overlay video duration 
    //on the bottom-right of the thumbnail (like youtube does).
    using (var thumbnail = videoThumbnailer.GenerateThumbnail(100, true))
        thumbnail.Save(@"C:\Thumbnail100WithDuration.jpg", ImageFormat.Jpeg);

    //Get the same thumbnail this time with 300x300 maximum size.
    //Thumbnail frame is already generated on the first call above so you can
    //get different sizes of the thumbnail many times very fast
    using (var thumbnail = videoThumbnailer.GenerateThumbnail(300))
        thumbnail.Save(@"C:\Thumbnail300WithoutDuration.jpg", ImageFormat.Jpeg);
}
using (var videoFrameReader = new VideoFrameReader(@"C:\Video.mp4"))
{
    Console.WriteLine("Info:");
    Console.WriteLine("----------------------------");
    Console.WriteLine("Duration: " + videoFrameReader.Duration);
    Console.WriteLine("Width: " + videoFrameReader.Width);
    Console.WriteLine("Height: " + videoFrameReader.Height);
    Console.WriteLine("CodecName: " + videoFrameReader.CodecName);
    Console.WriteLine("CodecDescription: " + videoFrameReader.CodecDescription);
    Console.WriteLine("CodecTag: " + videoFrameReader.CodecTag);
    Console.WriteLine("BitRate: " + videoFrameReader.BitRate);
    Console.WriteLine("FrameRate: " + videoFrameReader.FrameRate);

    Console.WriteLine();
    Console.WriteLine("Metadata:");
    Console.WriteLine("----------------------------");
    foreach (var entry in videoFrameReader.Metadata)
    {
        Console.WriteLine("Key: " + entry.Key);
        Console.WriteLine("Value: " + entry.Value);
        Console.WriteLine();
    }
}