2017-05-11

Extract Video Frame Using FFmepg with C#

I have so many videos in harddrive need to indexed it and get it sorted. And last month I got the ideal uploading video images to Google Photo.

So I want to extract every frame of video every half minute. Here is how I do with C#.


Define function to call FFmepg

public static void Ffmpeg(string fileName)
    {

        string outFile = fileName.Substring(0, fileName.Length - 5);
        string cmdParams = String.Format("-hide_banner -i {0} -vf fps=1/30 {1}%03d.jpg", 
            fileName, outFile);  //fps=1/30 means every 30 seconds extract a frame

        string exePath = @"C:\Users\rockymay\OneDrive\RipAlbumUrl\ffmpeg.exe";
        
        using (Process p = new Process())
        {
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = exePath;
            p.StartInfo.Arguments = cmdParams;
            p.Start();
            p.WaitForExit();

            
        }
}



Then call out function in Main


class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Now);//Now time

            Console.WriteLine("Select your video file full path");
            string path = Console.ReadLine();
            Ffmpeg(path);
        }
    }


Thanks to :
https://www.codeproject.com/Articles/774093/Another-FFmpeg-exe-Csharp-Wrapper

No comments:

Post a Comment

Setup VNC on Ubuntu 20.04

  sudo apt update sudo apt install xfce4 xfce4-goodies sudo apt install tigervnc-standalone-server sudo apt install tightvncserver vncserver...