Split videos using ffmpeg

» »

In this tutorial we go throught the process of using ffmpeg to split videos into shorter segments.

Table of Contents

  1. Split Videos using ffmpeg
  2. Splitting Video
  3. Advantages Using ffmpeg

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.

Splitting Video

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:

  1. The original quality is maintained since no re-encode is done
  2. No manual work is needed; the process is automated using the command line tool
  3. 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