0

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

aman
  • 801
  • 15
  • 34
  • Using -copy you are limited to start a video at a key frame. To start at an exact position you need to reencode it. This has been answered here: https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg – FBergo May 04 '18 at 03:31
  • 1
    Possible duplicate of [Cutting the videos based on start and end time using ffmpeg](https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg) – FBergo May 04 '18 at 03:32
  • I still can't get a perfect method. – aman May 04 '18 at 03:53
  • 1
    This has nothing to do with C++, since it just calls a shell command – Matthias247 May 04 '18 at 04:17
  • So what should I target to get the answer – aman May 04 '18 at 04:19

0 Answers0