Extracting a video clip from the command line

I had to extract a small clip from a very long video and I wanted to do it from the command line (of course!).

To do that we will use avconv (it is part of libav, an open source audio and video tools). It is a very fast audio and video converter that can be used to extract a clip from a video.

To install it in debian based distros:

$ sudo apt-get install libav-tools

In RedHat based distros there isn’t any source with a decent RPM package so the simplest way is build it from source.

In OS X there is a command called avconvert but its functionality is very limited. There is very good answer in Superuser about how to install libav/avconv in OS X.

Once you have avconv in your system let’s say you would like to take a 50 second clip starting at 25 minutes and 30 seconds from a video called original_video.mp4 then you would run the following command:

avconv -ss 00:25:30 -t 00:00:50 -i original_video.mp4 -codec copy video_clip.mp4

That would create a new video called video_clip.mp4 which duration would be 50 seconds and the clip would be the content of the original_video.mp4 from 00:25:30 to 00:26:20.

The option -ss seeks in the input file to position; -t exists after avconv has been running for duration seconds; -i is the input filename; -codec selects a decoder but the value copy is a special value to indicate that the stream is not to be reencoded.

As you can see in aconv manual it has a lot of capabilities.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields