How to Edit or Trim a WebM File Using FFmpeg?

This article provides a quick, practical guide on how to edit and trim WebM video files using the powerful command-line tool FFmpeg. You will learn the exact commands needed to cut a video by specifying start and duration times, slice a segment using precise timestamps, and perform these actions quickly without losing video quality. Whether you need to shorten a clip for a website or extract a specific scene, these command-line techniques will streamline your workflow.

Basic Trimming Using Duration

If you know exactly where you want your clip to start and how long it should last, you can use the -ss (start time) and -t (duration) flags. This method is incredibly efficient for quick cuts.

To cut a WebM file by specifying a duration, use the following command structure:

ffmpeg -i input.webm -ss 00:00:10 -t 30 -c copy output.webm

In this command:

Precise Trimming Using End Times

Alternatively, you might want to specify a strict start time and a strict end time rather than a duration. For this scenario, use the -to flag instead of -t.

ffmpeg -i input.webm -ss 00:01:15 -to 00:02:30 -c copy output.webm

This command extracts the segment starting at 1 minute and 15 seconds and ends exactly at 2 minutes and 30 seconds.

Accurate Cutting with Re-encoding

While -c copy is fast, it relies on “keyframes.” If you try to cut at a timestamp that isn’t a keyframe, the video might freeze or show a black screen for the first few seconds. If you need frame-accurate editing where the cut happens exactly on the millisecond you specified, you must let FFmpeg re-encode the WebM file using the VP9 video codec and Opus audio codec.

ffmpeg -i input.webm -ss 00:00:12.500 -to 00:00:18.200 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus output.webm