4

I want to split up a video into 2 equal parts.

The problem is that video could be any duration. E.g. 3 seconds, 3.5 seconds or more.

I could only find a solution to split up a video if you know exact duration.

Is it possible to achieve the same result for a video with variable duration?

With FFmpeg on Windows.

SharpAffair
  • 111
  • 2
  • 8
  • 1
    Windows or some kind of *nix? – Michael Harvey Mar 31 '19 at 19:36
  • @MichaelHarvey Windows. – SharpAffair Mar 31 '19 at 19:41
  • There are free products on Windows which can do video split into equal parts, other than FFmpeg. For example: [Bandicut Video Splitter](https://www.bandicam.com/video-splitter/) and [SolveigMM Video Splitter](http://www.solveigmm.com/en/howto/how-to-slice-video-by-time-size-or-parts-with-video-splitter/). Let me know if you are interested in such an alternative solution. – harrymc Apr 15 '19 at 06:50
  • You can extract/calculate the whole video time then divide it by 2 and use the result with the correct format for the `-ss` and `-to` options (in the two `ffmpeg` invocations: extract the first half, extract the second one) . You can even use the number of frames...for example you can count it with `ffmpeg -i input.mkv -map 0:v:0 -c copy -f null -` then with `grep` and `awk` select the output...divide by 2 etc etc... – Hastur Apr 15 '19 at 22:06
  • Even more efficiently with the segment `-f segment -segment_time ` then the time... you have only to extract it in advance. OS depending... – Hastur Apr 15 '19 at 22:15
  • Do you just need the `ffmpeg` commands to do this, or is this a two-in-one question and do you expect the answer to also include batch scripting? (I know the commands, but not the batch.) – llogan Apr 16 '19 at 17:32

1 Answers1

1

You can split up video files by this command :

ffmpeg -i largefile.mp4 -t 00:50:00 -c copy smallfile1.mp4 -ss 00:50:00 -c copy smallfile2.mp4

Find the current duration of the file with this:

ffmpeg -i inputfile 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//

Now calculate the half of it and put the value in previous code.

I can Create a script in bash But you are using windows. however, you can use a bash script if you are using Windows 10.

  • This splits the file at 50 minutes from the start, not in half. – Disenchanted Lurker Apr 16 '19 at 09:12
  • 1
    The output from `ffmpeg` is not meant to be machine parsed. [Use `ffprobe` instead](https://trac.ffmpeg.org/wiki/FFprobeTips#Formatcontainerduration) ([more examples](https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds/945604#945604)). Doing so will also allow you to omit `grep`, `cut`, and `sed`. – llogan Apr 16 '19 at 17:27