Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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 http://ffmpeg.org/ffmpeg-doc.html ) for more information.

share|improve this answer

You could try ffmpeg. See http://www.joeldare.com/wiki/video:cut_video_with_ffmpeg

Cut out pieces of the movie you wish to keep, then join them together to get you final movie (Joining videos: http://ffmpeg.org/faq.html#SEC30)

Documentation on more ffmpeg options available here: http://ffmpeg.org/ffmpeg-doc.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.