---
title: "Extract frame from video in C#"  
description: "You can extract frames from a video in C# using the AForge.NET, OpenCV (Emgu.CV), or FFmpeg libraries. Below are different methods based on these libr"  
author: "Ravi Vishwakarma"  
published: 2025-02-09  
updated: 2025-02-10  
canonical: https://www.mindstick.com/articles/338467/extract-frame-from-video-in-c-sharp  
category: "c#"  
tags: ["c#", "core framework", ".net core"]  
reading_time: 3 minutes  

---

# Extract frame from video in C#

You can extract frames from a video in C# using the **AForge.NET**, **OpenCV (Emgu.CV)**, or **FFmpeg** libraries. Below are different methods based on these libraries:

#### Method 1: Using OpenCV (Emgu.CV)

`Emgu.CV` is a .NET wrapper for `OpenCV` and is one of the easiest ways to process videos and extract frames.

## Steps:

1. Install the **Emgu.CV** [NuGet package](https://www.mindstick.com/forum/155814/what-is-nuget-package-management):\ `Install-Package Emgu.CV`
2. Use the following [C# code](https://www.mindstick.com/forum/12767/asp-dot-net-is-not-calling-c-sharp-code) to extract frames from a video:

## C# Code Using Emgu.CV

```cs
using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
class Program
{
    static void Main()
    {
        string videoPath = "sample.mp4";  // Path to video file
        string outputFolder = "Frames";   // Output folder for extracted frames

        if (!System.IO.Directory.Exists(outputFolder))
            System.IO.Directory.CreateDirectory(outputFolder);

        using (var capture = new VideoCapture(videoPath))
        {
            int frameIndex = 0;
            Mat frame = new Mat();

            while (capture.Grab())
            {
                capture.Retrieve(frame); // Get frame

                if (!frame.IsEmpty)
                {
                    string framePath = $"{outputFolder}/frame_{frameIndex}.jpg";
                    frame.Bitmap.Save(framePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Console.WriteLine($"Saved: {framePath}");
                    frameIndex++;
                }
            }
        }

        Console.WriteLine("Frames extracted successfully.");
    }
}

```

#### How It Works?

- Opens the [video file](https://answers.mindstick.com/qa/94846/why-can-t-i-open-my-video-file-on-android).
- Loops through each frame and saves it as an image.
- Saves frames in the specified folder.

#### Method 2: Using FFmpeg (Fast & Efficient)

If you want a simple [approach](https://yourviews.mindstick.com/view/81036/coronavirus-pandemic-approach-in-dictatorship-of-hungary) without using [C# libraries](https://www.mindstick.com/forum/161613/how-do-you-zip-a-folder-and-all-its-contents-using-built-in-c-sharp-libraries), you can use **FFmpeg**.

## Steps:

1. **[Download and Install](https://answers.mindstick.com/qa/50784/how-to-troubleshoot-your-iphone-7-that-won-t-download-and-install-apps-other-issues) FFmpeg** from ffmpeg.org.
2. **Run FFmpeg Command** from C#:

## C# Code Using FFmpeg

```cs
using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        string videoPath = "sample.mp4";
        string outputFolder = "Frames";

        if (!System.IO.Directory.Exists(outputFolder))
            System.IO.Directory.CreateDirectory(outputFolder);

        string ffmpegCmd = $"-i \"{videoPath}\" \"{outputFolder}/frame_%04d.jpg\"";

        ProcessStartInfo processInfo = new ProcessStartInfo
        {
            FileName = "ffmpeg",
            Arguments = ffmpegCmd,
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };

        Process process = new Process { StartInfo = processInfo };
        process.Start();
        process.WaitForExit();

        Console.WriteLine("Frames extracted successfully.");
    }
}
```

#### How It Works?

- Calls `FFmpeg` from C# to extract frames.
- Saves frames as `frame_0001.jpg`, `frame_0002.jpg`, etc.

#### Method 3: Using AForge.NET (Basic)

AForge.NET is another option but is slower than OpenCV.

Steps:

1. Install **AForge.Video.FFMPEG** via NuGet:\ `Install-Package AForge.Video.FFMPEG`
2. Use the following C# code:

## C# Code Using AForge

```cs
using System;
using System.Drawing;
using AForge.Video.FFMPEG;

class Program
{
    static void Main()
    {
        string videoPath = "sample.mp4";
        string outputFolder = "Frames";

        if (!System.IO.Directory.Exists(outputFolder))
            System.IO.Directory.CreateDirectory(outputFolder);

        VideoFileReader reader = new VideoFileReader();
        reader.Open(videoPath);

        for (int i = 0; i < reader.FrameCount; i++)
        {
            Bitmap frame = reader.ReadVideoFrame();
            if (frame != null)
            {
                string framePath = $"{outputFolder}/frame_{i}.jpg";
                frame.Save(framePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                Console.WriteLine($"Saved: {framePath}");
                frame.Dispose();
            }
        }

        reader.Close();
        Console.WriteLine("Frames extracted successfully.");
    }
}
```

#### Which Method Should You Use?

| Method | Pros | Cons |
| --- | --- | --- |
| **OpenCV (Emgu.CV)** | Fast, powerful, real-time | Requires OpenCV |
| **FFmpeg** | Very fast, no extra coding needed | Requires FFmpeg installed |
| **AForge.NET** | Simple, easy to use | Slower than OpenCV |

## Best Choice?

✅ Use `Emgu.CV` for real-time [processing](https://www.mindstick.com/forum/12859/how-to-processing-textual-inputs-in-the-client-side)

✅ Use `FFmpeg` for the fastest frame [extraction](https://www.mindstick.com/articles/157209/data-science-for-effective-interpretation-and-extraction-of-meaningful-data)

✅ Use `AForge.NET` if you need a lightweight solution

Let me know if you need further details! 🚀

---

Original Source: https://www.mindstick.com/articles/338467/extract-frame-from-video-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
