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 :
- For extracting every 5th frame & storing it in a folder.
string argumentStrFinal = "-i {0} -vf \"select = not(mod(n\\, 5))\" -vsync vfr {1}/img_d.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_d.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.
CodePudding user response:
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.