Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an long mpeg movie and I want to cut out a lot of material from the beginning and end, and certain patches in the middle. Is there a way I can easily do this from the linux command line?

share|improve this question
up vote 7 down vote accepted

The tool for the job is mpgtx (if not installed try, e.g., sudo apt-get install mpgtx).

Let's suppose your file is called input.mpg and you want to create output.mpg Here are some common tasks

Select segments from a mpeg movie, create a new mpeg movie out of them

//Grabs seconds 10-20, 42 through 52, then 1:23 through 1:33 and make a new mpeg movie

mpgtx -j input.mpg [0:10-0:20] [0:42-0:52] [1:23-1:33] -o output.mpg

Note: mpgtx -j is equivalent to mpgjoin. Note: You need to install it via sudo apt-get install mpgtx

Select from the beginning or end of an mpeg movie

//Get the first 20 seconds, secs 42 through 52, then 1:23 through the end***

mpgtx -j input.mpg [-0:20] [0:42-0:52] [1:23-] -o output.mpg

Split an mpeg movie into several files of custom lengths

//Splits out minutes 1-2 and 3-4 into two files (out-1.mpg and out-2.mpg)

mpgtx -s input.mpg [1:00-2:00] [3:00-4:00] -b out

Break an mpeg movie into equal length pieces

//Splits a movie into 5 equal length parts called out-1.mpg, out-2.mpg, ..., out-5.mpg

mpgtx -5 input.mpg -b out

Concatenate or join multiple mpeg video files from the command line

mpgtx -j file1.mpg file2.mpg file3.mpg -o output.mpg

Re-encoding a file if the timings are off

You may find that the timings are not very accurate because of the way that mpgtx works (which is on a group of pictures basis). I have found that reencoding the mpeg at a constant bitrate leads to files which then can be split very precisely with the above method. A simple re-encoding call is as follows.

//Re-encode at a constant bit rate of 2250k

ffmpeg -i input.mpg -b 2250k -minrate 2250k -maxrate 2250k -bufsize 1000k output.mpg

Note. ffmpeg can do much of what mpgtx can do, but the latter makes it much easier to specify multiple cuts (and you can give the input in start and end times, as opposed to start and durations). However, ffmpeg is a great companion. I find that converting AVIs to mpeg with ffmeg, then doing the splitting with mpgtx is the quickest means to get the job done.

See the man pages for mpgtx and ffmpeg (as well as its online help page ) for more information.

share|improve this answer

You could try ffmpeg. See

Cut out pieces of the movie you wish to keep, then join them together to get you final movie (Joining videos:

Documentation on more ffmpeg options available here:

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .