How can I join multiple .mpg movie files?

16

7

I create a lot of these small clips on my digital camera. These are in .mpg format and before I share them with others, I would love to just join, clip a few seconds here and there.

I use Google Picassa to create new start and end points, but I dont know a good way to join mpgs yet.

Whats the best free software i can use for this?

Kapsh

Posted 2009-09-19T00:24:32.290

Reputation: 417

Answers

25

mpg files are the easiest to join. You can actually copy them together. In Windows you use

copy/b file1.mpg+file2.mpg+file3.mpg newfile.mpg

In Linux, I use cat:

cat file1.mpg file2.mpg file3.mpg >> newfile.mpg

Joshua K

Posted 2009-09-19T00:24:32.290

Reputation: 771

The >> in the linux command should have been >. I tried to edit it, but SE's web interface wouldn't let me, because my edit wasn't enough characters. – Ben Crowell – 2016-12-19T22:55:44.940

@BenCrowell 'should have' is speculative. The >> will append to an existing file or create a new one, which might be useful while the single > will destroy the existing target. It's up to the user and both work and serve a purpose. – Joshua K – 2017-12-01T22:52:07.777

on ubuntu 18 the final file only contains the content of the first file – Guus – 2018-07-17T18:03:33.260

@Guus i'm still using 16. It would seem REALLY strange for that behavior to have changed. I'll check after I update and update my answer if necessary. – Joshua K – 2018-07-18T15:40:45.613

1Worked for me with a 4-parter. The time stamp of the final version is messed up, but it plays through just fine. – FreeMan – 2018-07-24T22:44:06.750

1I tried doing this, and it claimed the copy was successful, but the video only lasts as long as the last video's length, even though it appears to start at the first video copied. Why is this, and what can I do to fix it? – nhinkle – 2010-11-05T03:54:55.903

And it's a pity this doesn't work with .mp4 (being a container format) - you get a file as large as it needs to be, but that only plays the first file – PandaWood – 2011-02-01T22:26:28.953

Valid point, but he wants to clip some parts out. – John T – 2009-09-19T04:47:22.810

1Thanks, this worked great. I can still use Picassa to clip the parts and then use the copy command to join multiple clips. – Kapsh – 2009-09-25T14:44:55.030

9

Recent versions of ffmpeg can do this via its concat demuxer, which should be more reliable than using cat or copy. First, create a file called inputs.txt, containing

file /path/to/input1.mpg
file /path/to/input2.mpg
file /path/to/input3.mpg

Then use the following ffmpeg command:

ffmpeg -f concat -i inputs.txt -c copy output.mpg

See here for more information.

evilsoup

Posted 2009-09-19T00:24:32.290

Reputation: 10 085

I tried this but the audio was removed/not present in the resulting clip. – Peter Mitrano – 2018-01-18T03:51:48.837

2

For Linux Avidemux is quite good:

For Windows there is

There are also more low level tools that work directly on the MPEG stream such as:

Those might be good for lossless cutting, but give much less freedom.

Grumbel

Posted 2009-09-19T00:24:32.290

Reputation: 3 100

1Avidemux for windows is also quite good, I find it better than VirtualDub. – ansgri – 2013-06-14T08:00:13.413

1

Join/encode/convert to your heart's content with MediaCoder.

Tutul

Posted 2009-09-19T00:24:32.290

Reputation: 478

1

How about Windows Movie Maker or Windows Live Movie Maker? (depending on your version of windows, which it seems you are using by your other questions).

John T

Posted 2009-09-19T00:24:32.290

Reputation: 149 037

1Good point... But seriously, a superuser would probably use something more professional :D – Julian F. Weinert – 2015-06-29T14:24:00.623

0

I have used copy/b & that joins the files OK but it does something to the header that messes with the time code. But then I ran the entire file through XMedia Recode using just video copy (not convert) & audio copy with the same extension & that seemed to straighten it out: http://forum.videohelp.com/threads/375401-How-to-cut-any-video-with-Xmedia-Recode

Max

Posted 2009-09-19T00:24:32.290

Reputation: 1

Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change. – DavidPostill – 2017-01-26T09:37:32.210

0

If you simply copy them together using the command line as suggested above, the duration will not be reported correctly in your media player, but it still may work. Don't trust the duration reported by your player - check manually.

When ripping and combining videos from DVD, If I rip without re-encoding, I get mpg files which I can combine with the copy command, and then even though VLC doesn't report the duration correctly, Handbrake "sees" the correct duration, and the final re-encoded mp4 files play correctly and display the correct duration.

Glaurung

Posted 2009-09-19T00:24:32.290

Reputation: 71

The Technology has changed and improved since 7 years don't you think? – yass – 2017-03-28T21:15:04.137