In this tutorial we go throught the process of using ffmpeg to split videos into shorter segments.
Table of Contents
Split Videos using ffmpeg
Here's how to split videos using the free ffmpeg binary:
ffmpeg -i source.mp4 -c copy -map 0 -segment_time 00:05:00 -f segment -reset_timestamps 1 result_%03d.mp4
This solution does not cut at exactly five minutes, but the next frame after that time. This menas that we get correctly trimmed clips each time, without errors.
The flag -reset_timestamps means that ffmpeg also resets the timestamps of each clip — otherwise, sometimes only the first of the output clips can be played when the timestamps don't align with the trimmed segments.
Sometimes you have really lengthy videos that you just want to split into several shorter clips, but this can be a cumbersome task that is not only repetitive but also very demanding on resources — whether you're using your CPU or GPU to re-encode your videos, you're wasting resources on something that is not really needed.
Advantages Using ffmpeg
The ffmpeg approach has three major advantages over doing it manually in a video conversion application:
- The original quality is maintained since no re-encode is done
- No manual work is needed; the process is automated using the command line tool
- ffmpeg is free of charge and supports multiple platforms
ffmpeg can be installed using homebrew on macOS or apt on Ubuntu;
- macOS: brew install ffmpeg
- Ubuntu: sudo apt install ffmpeg