How to combine/concatenate mp4 videos

In a project similar to the Blender Defender, I am using a Linksys WVC54GCA webcam to monitor my devious cats. The camera has built-in motion detection, and can automatically FTP video files of detected motion to a location of your choice. Unfortunately, the area I’m monitoring has a good deal of exposure to outside lighting, meaning that each day I get hundreds of little videos as light plays across the room.

While messing with the motion sensitivity settings is next on my list, my immediate reaction was to figure out a way to combine the videos. The WVC54GCA lets you use a few different formats, but I chose mp4 since that seemed like the most open format. Some Google searching told me that I needed to use ffmpeg to convert the mp4s to mpg format which is supposedly “concatenatable”.

So first I converted all my mp4s to mpgs (assuming they are stored in a directory called movie_dir):

find movie_dir -name "*.mp4" -exec ffmpeg -i {} -sameq {}.mpg \;

Many posts I found then said that all one needed to do was just cat the mpg files together and you’d end up with one long mpg. That sounded great, but in practice it produced an mpg that caused both QuickTime and VLC to either choke, skip past chunks of video, or otherwise be weird. Going back to the Internet, I found that the solution was to use ffmpeg again to produce a single video:

cat movie_dir/*.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy big_movie.mpg

And this I can enjoy 30 boring minutes of watching the light level change, waiting for that one moment when the cats try to sneak up on the couch. Now I know how a security guard feels.

This entry was posted in HOW-TOs. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *