Score:1

Using ffmpeg to cut up video at multiple points

cn flag

I have a video that is a football game. I would like to cut the time before the game, during half time and finally the end of the game.

Total Clip Length 1h 51m or 111m

Ideally the cuts and time are as follows:

+------------+-------------+---------------------+
| Start Time | Finish Time |    Clip Duration    |
+------------+-------------+---------------------+
| 1:30       |   47:30     |  47:30              |
| 53:00      |   100:00    |  47                 |
+------------+-------------+---------------------+

However my video finishes at

ffmpeg -ss 00:01:30 -i Tripod_Camera.mp4 -t 00:47:30 -ss 00:53:00 -t 00:47:00 -c copy VideoClip.mp4
24601 avatar
in flag
have you consider using a tool such as `LosslessCut` to perform this task? See [this reference](https://www.maketecheasier.com/extract-clips-video-losslesscut/?utm_source=newsletter&utm_medium=email&utm_campaign=07092020)
vanadium avatar
cn flag
@24601 ffmpeg can do this perfectly, and the command given indeed does that losslessly. It is a matter of finding the correct command options to do it in one go.
cn flag
@vanadium ye correct. I just don't know when or how! :/
llogan avatar
jp flag
How accurate do you need the cuts to be? Because if you can accept cutting only on keyframes then you can do this without re-encoding. Refer to [Checking keyframe interval?](https://stackoverflow.com/a/18088156/) to see keyframe frequency.
cn flag
It doesn't need to be tight at all actually. Considering I've allot of lea way on either side of the times. Its more that I could not work out how to pass `2 cuts` as it were to one FFMPEG command.
andrew.46 avatar
in flag
Some direction here: https://superuser.com/questions/681885/how-can-i-remove-multiple-segments-from-a-video-using-ffmpeg
Score:2
jp flag
  1. Make input.txt containing the timestamps (in seconds) to cut:

    file 'input.mp4'
    inpoint 90
    outpoint 2850
    file 'input.mp4'
    inpoint 3180
    outpoint 6000
    
  2. Run ffmpeg to concatenate with the concat demuxer:

    ffmpeg -f concat -i input.txt -c copy output.mp4
    
  • This will stream copy, so no re-encoding occurs meaning the whole process will be fast and quality will be preserved. However, cuts will be made on keyframes, so it may not be accurate enough. If greater accuracy is needed you'll have to use a much slower method such as using the (a)trim, (a)setpts, and concat filters which requires re-encoding.

  • If you get A/V desync then get timestamps of keyframes, use keyframe timestamps as your inpoint, but add 0.001 to each inpoint timestamp in input.txt.

cn flag
Thank you :D This does work perfectly! I have to ask, does it have to be a file? Or could I do it directly in the terminal?
llogan avatar
jp flag
@JamieHutber Kind of. See [FFmpeg Wiki: Concatenate](http://trac.ffmpeg.org/wiki/Concatenate).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.