A reader wrote in asking if I knew how to merge video files. He, like me, has ripped the BBC Shakespeare video box set. These films, of all of Shakespeare’s plays, were made in the late 1970s and early 1980s. While they are not uniformly interesting, many of them are very good. (Amazon.com, Amazon UK)
Some of the plays span multiple discs; this is the case for Othello, Richard III, and a couple of other plays. I’d never bothered to try to figure out how to splice them together, but it does make my video library a bit inconsistent.
Thanks to this article by Bruno Define, I was able to join videos very quickly. This involves a few simple commands in Terminal, using the built-in video tool
(If you don’t have
ffmpeg installed, this article explains how to install it.)
You need to run a command for each of the video files to have
ffmpeg convert the files from .m4v to .ts (MPEG transport stream). You then use
ffmpeg to concatenate the files.
So, for my Richard III, in two parts, I run the following commands:
ffmpeg -i "Richard III part 1.m4v" -c copy -bsf:v h264_mp4toannexb "part1.ts"
ffmpeg -i "Richard III part 2.m4v" -c copy -bsf:v h264_mp4toannexb "part2.ts"
An easy way to run these commands is to type the first part –
ffmpeg -i – drag a file to the Terminal window from the Finder, then copy and paste the second part of each command above.
You run each command separately; Terminal spits out some output, and it will convert each file in less than a minute. Note that these commands, as written, save the output files to the root level of your home folder.
You now have two files, part1.ts and part2.ts. To join them, run this command:
ffmpeg -i concat:"part1.ts|part2.ts" -c copy -bsf:a aac_adtstoasc "Richard III.m4v"
Again, this is fairly quick;
ffmpeg essentially reads the files, and rewrites a joined file. There is no transcoding at all; no loss of quality.
Check the resulting file. When you’re sure it’s okay, delete the .ts files you created in the first steps.