Is your video too long for upload to Twitter or Instagram? Do you want to export just a specific clip? Using video editors to trim videos requires reencoding the entire video. Instead I will show you how to instantly trim your videos and even maintain embedded subtitle tracks.

Background

A few days ago I created a post on easily adding subtitles to your videos. Today I wanted to verify that Twitter correctly shows these subtitles, but I discovered that my video was too long. Having played with FFmpeg I suspected that there may be a more efficient way for trimming videos than using a video editor. Be prepared to have your mind blown! 🤯

Requirements

FFmpeg

You will need the open-source FFmpeg tool.

FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created.

Please follow the installation instructions here. On Mac, simply use Homebrew with brew install ffmpeg

Instantly trim videos

The following command reads the source video and copies all streams contained within (video, audio, subtitles) to the output. The various time parameters ensure only a specific part of the original video is written to the output. The video and audio streams are not reencoded. The time required for reencoding would directly depend on the duration of the video, however we are simply copying parts of the video. For this reason the following operation is near instant. A huge time saving over workflows involving video editors.