avatar

ShīnChvën ✨

Effective Accelerationism

Powered by Druid

Cut and Merge Videos Using FFmpeg: A Developer's Guide

Mon Aug 17 2020

Introduction

As a developer, I often find myself turning to the command line for tasks that can easily be accomplished without GUI tools. Video editing is one such task. FFmpeg is a powerful command-line utility that allows you to manipulate multimedia data in various ways, including cutting and merging videos.

In this post, I'll show you how to perform basic video cutting and merging operations using FFmpeg.

Cut Video Using FFmpeg

Cutting a video means extracting a specific portion from it. You can cut by timestamp or by frame number using FFmpeg.

Cut by Timestamp

ffmpeg -ss 00:00:30.0 -i input.wmv -t 00:00:10.0 -c copy output.wmv

Cut by Frame Number

ffmpeg -ss 30 -i input.wmv -t 10 -c copy output.wmv

Note: The order of arguments is crucial for successful cutting. Always follow this pattern: -ss <START_TIME> -i <INPUT_FILE> -t <END_TIME> [other options]. Failure to do so may result in corrupted output. For more details, consult the Official Documentation.

For additional insights on video cutting, refer to the FFmpeg wiki on Seeking.

Merge Videos Using FFmpeg

Merging videos means combining multiple video files into one.

Create File List

First, create a text file that lists the videos you want to merge:

echo file file1.mp4 >  mylist.txt
echo file file2.mp4 >> mylist.txt
echo file file3.mp4 >> mylist.txt

Concatenate Videos

Execute the following command to merge the listed files:

ffmpeg -f concat -i mylist.txt -c copy output.mp4

For more information on merging videos, refer to the FFmpeg wiki on Concatenation.

Conclusion

FFmpeg is a versatile tool for basic video editing tasks like cutting and merging videos. Its command-line nature makes it a preferred choice for developers who are comfortable with terminal commands.

Happy video editing!