Slice Videos with ffmpeg

By  on  

Isolating a specified portion of a video is a very common task for those who work within the media, probably using nice GUI tools to slice clips from the full video.  I'm a developer, however, and know how amazing ffmpeg is so I prefer to do my basic video slicing from command line.

Let's look at the following command and break it down:

# Creates 12 second video
./ffmpeg -i input.mp4 -ss 00:00:05 -c copy -t 12 sliced-output.mp4

The -i obviously represents the input file, the ss represents the time to start the slicing at, and the -t represents the number of seconds from the ss to include within the slice.  I'm seeing result quality vary when it comes to -c copy; most times the quality is better with it, but on some rare occasions the quality is better without it.

If you prefer to explicitly cite the hour:minute:second mark which to cut to, use the -to option:

# Creates 2 second video
./ffmpeg -i input.mp4 -ss 00:00:05 -c copy -to 00:00:07 sliced-output.mp4

User interfaces and apps are awesome when doing work manually but aren't always great to automate. Since ffmpeg is a command line utility, automating almost anything with video is reasonably easy if you take the time to learn the tool!

Recent Features

  • By
    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I've even caught myself reading the post...

  • By
    How to Create a RetroPie on Raspberry Pi – Graphical Guide

    Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices.  While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...

Incredible Demos

  • By
    Animated AJAX Record Deletion Using Dojo

    I'm a huge fan of WordPress' method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here's how to achieve that functionality with Dojo JavaScript. The PHP - Content & Header The following snippet goes at the...

  • By
    Dynamically Load Stylesheets Using MooTools 1.2

    Theming has become a big part of the Web 2.0 revolution. Luckily, so too has a higher regard for semantics and CSS standards. If you build your pages using good XHTML code, changing a CSS file can make your website look completely different.

Discussion

  1. dragos

    Love your articles! :) Everything’s explained briefly and on point! :D Thank you.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!