I'm creating a C++ program which manipulates a video in many different ways. The manipulation are created through the system() in C++ with the installed video editing libraries of MP4Box and FFMPEG. One of my procedure is not giving me the correct outcome and I need help in it.
I have a 1080p quality video, excluding audio, in .mp4 format. The video is 1 minutes OR 60 seconds long. I want this video to be split into 5 seconds parts. So in return I will have 12 video files with 5 seconds duration exactly.
So far I'm using this system (My Code):
#include <iostream>
#include <windows.h>
#include <list>
#include <string>
using namespace std;
int main()
{
int media_duration = 60;
for (int time = 0; time <= media_duration; time += 5)
{
system(("cd C:\\Users\\amans\\Documents\\video && ffmpeg -i 1080p.mp4 -ss " + to_string(time) + " -to " + to_string(time + 5) + " -c copy " + to_string((time + 5) / 5) + ".mp4").c_str());
}
cin.get();
return 0;
}
In my code above I have created a loop which splits the 1080p file in 12 different files BUT they are not in the duration of 5 seconds. Some of the files have a duration of 1 second while other files have 3 or 4 seconds duration. I'm using FFMPEG to split the video.
Can someone give me another method or help me fix my current method? Please comment below. Thanks