Merging (joining) two videos with cat and Quic ...

Persistent Inappeasable Mind

Calendar

Back April '14 Forward
Mo Tu We Th Fr Sa Su
  1 2 3 4 5 6
7 8 9 10 13
14 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        

Statistics

Last entry: 2014-04-15 10:54
300 entries written
114 comments have been made

Friday, November 5. 2010

Merging (joining) two videos with cat and QuickTime X

Software hints

QuickTime 7 had this great feature of merging two videos together just by dragging a video file from the Finder to another QuickTime video. Unfortunately this is not possible in QuicTime X. But I still wanted to do it without installing additional software and came up with a solution that includes a small hack :).

Assume we have 2 video files named video1.dv and video2.dv in ~/Movies folder that we want to merge.

1.  Open the Terminal and navigate to Movies folder

$ cd Movies

2. Concatenate two files

$ cat video1.dv video2.dv > video3.dv

This step will take a while and the result is a strange (I don't really want to say corrupted as it is just split in two MPEG containers) file, which will still play in most video players (I tried VLC and QuickTime X). This procedure works with transport stream formats (e.g. .dv, .ts, .mp3, .m2ts, etc.)

3. Open the new file in QuickTime X and re-save it 

File -> Save As and select one of the available formats or use

File -> Save for web and choose the desired quality

QuickTime X will re-save the file frame by frame with a proper (e.g. MOV or MP4) container.

It is off course possible to use other software (e.g. ffmpeg) and procedures.

PS: Comments on Mac OS X Hints are worth reading

Edit 22/4/2011:
I found out that it is possible to merge videos with cat and mencoder (mplayer) that rebuilds the index afterwards:

1. Install mencoder

$ sudo port install mplayer

2. merge videos together

2.1 AVI

$ cat movie1.avi movie2.avi > movie_new.avi
$ mencoder -forceidx -oac copy -ovc copy movie_new.avi -o movie.avi

2.1 MPG

$ mencoder -oac copy -ovc copy movie1 movie2 -o movie.mpg


Edit 11/9/2012:

This tip is more a proof of concept than a serious/professional way of joining videos. I still receive emails about this though. If you need something graphical with an UI, still light and opensource (and free as in free speech) try Avidemux. It can also concatenate or append (how they call it) files one after another. See the step 3.


Trackbacks

Weblog: www.deadlock.it
Tracked: Nov 08, 22:21
Weblog: applenewsdaily.wordpress.com
Tracked: Nov 09, 00:15

Comments
Display comments as (Linear | Threaded)

#1 - Matjaž Kljun 2010-11-16 17:35 - (Reply)

Mac OS X Hints has published this hint and has more comments that might be of interest.

http://hints.macworld.com/article.php?story=20101105030030245

#2 - Simon 2010-12-05 10:10 - (Reply)

Odd, it didnt really work for me. I merge two m4v files and it opens just the first part in QT X.. Also, when i try to save that file it only save the first part again, so i end up with video1 with another name. :)

#2.1 - Matjaž Kljun 2010-12-05 14:28 - (Reply)

Interesting. What about the file size of "the merged file". Is it as big as the first file only or does it have a combined size of both files you try to merge?

My m4v files were created with iMovie (from my video camera). But AFAIK the m4v uses a transport stream and cat should work.

#3 - Simon 2010-12-05 14:33 - (Reply)

H.246 codec, a friend sent it to me i think he did it in Premiere.
The size of the merged file is file1+file2, although QTX only plays the first part (and hence, only saves the first part)


Tried merging with QT7Pro (got it off the snow leo disk) but its actually not that good. It inserts few frames of a white "pause" and i cant make him save in the same format so it always encodes it again.

#3.1 - Matjaž Kljun 2010-12-05 14:45 - (Reply)

Most video authoring applications save video as a Program stream. There is a difference between Program stream and Transport stream. I'm really not an expert but these links (sorry I can't make them clickable) should explain the difference:

http://vbrickvip.com/topics/transport_stream.htm
http://en.wikipedia.org/wiki/MPEG_transport_stream
http://en.wikipedia.org/wiki/MPEG_program_stream

As far as I know the h.246 is tipicaly used in MPEG2 TS. But it might be that Premiere saves it as PS which is also possible.

I would try two things:

1. convert videos using QT X (File->Save for web) and try to merge two converted files

or

2. Use some other software (e.g. MPEGStreamClip as suggested on Mac OS X Hints).

Hope this helps you in some way.

#3.2 - Matjaž Kljun 2010-12-05 14:50 - (Reply)

One more thing. What happens if you play "the merged" video in another player like VLC?

#3.2.1 - Simon 2010-12-05 15:38 - (Reply)

It plays exactly the same that is, only the first part.
I'll just call the guy and just tell him to give me the full version in one piece for now because i have deadline, and i'll play with it later when i have some free time.
Thanks for all your help, much appreciated!


Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Can you please write (or copy/paste) this text in the field below: i h a t e s p a m