简体   繁体   中英

Extract 5th frame of video & merge into a video using ffmpeg C#

I am trying to extract every 5th frame of a video and try to merge it in another video using ffmpeg.

So far, I have tried 2 separate commands & processes :

  1. For extracting every 5th frame & storing it in a folder.

             

string argumentStrFinal = "-i {0} -vf \"select = not(mod(n\\, 5))\" -vsync vfr {1}/img_%03d.jpg";
                argumentStrFinal = String.Format(argumentStrFinal, inputPath, filePath);
                ProcessStartInfo startInfo5 = new ProcessStartInfo()
                {
                    FileName = ffmpegPath,
                    Arguments = argumentStrFinal,
                    UseShellExecute = false,
                    CreateNoWindow = true
                    //RedirectStandardError = true,
                };

                string outputPathFps = Path.Combine(filePath, "outputtemp_" + DateTime.UtcNow.Ticks + ".avi");
                Process exeProcess5 = Process.Start(startInfo5);

                exeProcess5.WaitForExit();

2.For creating the video from the folder of frame images

  string argumentStrFinalMerge = "-framerate {2} -i {0}\\img_%03d.jpg {1}";
                    argumentStrFinalMerge = String.Format(argumentStrFinalMerge, filePath, outputPath, standardFrameRate);
                    
                    ProcessStartInfo startInfo6 = new ProcessStartInfo()
                    {
                        FileName = ffmpegPath,
                        Arguments = argumentStrFinalMerge,
                        UseShellExecute = false,
                        CreateNoWindow = true
                        //RedirectStandardError = true,
                    };

                    Process exeProcess6 = Process.Start(startInfo6);

The problem is the two different processes are taking longer time so I want to merge this commands in single process.

Please suggest me a way to do it.

Assuming your input is constant framerate (CFR), how about just using a fps filter ?

ffmpeg -i INPUT -vf fps=source_fps/5 OUTPUT

This will pick every 5 frames while maintaining the same playback speed. If you need to change the playback speed, chain a setpts filter to modify the frame interval.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM