Video Editing using Mplayer/Mencoder and MjpegTools

The Background

The digital camera I use is the Canon Powershot A40, which has a mode for recording short video clips with sound. I was looking for a way to edit these on Linux, and came across a very good page that got me started. I wanted to be able to combine the video clips in to a longer sequence, and the tools to do this are Mplayer and MjpegTools. I use RedHat 7.3, and all the tools needed are available in RPM format either via the project websites or FreshRPMs.

Getting the camera to talk to the Linux system is easy, using the gphoto2 package, though you need a later version than the default one on RH7.3, which you can get from the sourceforge project page.

The Details

I wanted to join the video clips with a transition, which is relatively easy to do with the video, but dealing with the audio is more cumbersome. Here is the script I wrote to combine two clips with a 1 second (20 frame) fade transition between the clips. The audio is also faded slightly to make the transition less abrupt. sox is used to process the audio, which is available with the standard RH7.3 release.

The script is hopefully self-explanatory, but basically the procedure is to split off the video from the audio, then create a transition by blending the last 20 frames of the first file with the first 20 from the second file. The two original clips are also trimmed to remove these 20 frames, then the three clips are re-combined.

For the audio, a similar process is done, except that you have to go to a raw format to combine the two faded/trimmed clips together.

Finally, the video and audio streams are combined to output an MJPEG format file. This can be changed to output a DivX file if required, for example.

The resulting combined file can be viewed with mplayer or xine. I haven't tried it with anything under windows but it should work, though you might need to download a suitable codec for Windows Media Player. You can use the script to join multiple clips simply by joining the joined clips, though you might want to turn off the yuvdenoise filter for subsequent passes to prevent any unnecessary degradation.

Here are some other small scripts which will rotate or denoise your video clips.

The Final Touch

If you've got a DVD player, the best way of showing these clips is on the TV instead of getting people to crowd round the PC. Here is a script which uses two more Linux utilities (vcdimager and cdrdao) to turn the video clips into an SVCD which can be played on most DVD players. You can put multiple clips on to a single CD, which then appear as separate tracks when played. The quality is surprisingly good, since the resolution is a reasonable match for that which can be displayed on a TV.


Still Images on VCD

Ok so now you want to look at all those still images you've taken, but it would be better to show them on the TV rather than getting everybody to crowd around the computer. This actually turns out to be quite easy, because all you have to do is make a short video clip which consists of a number of repeated frames of the still image, and then make this into a VCD as above.

To cope with images in portrait format, some resizing and padding is required, but this can all be done easily with the ImageMagick tools. I put it all into a script still_vcd to make things easier.


If you find any of this useful, I'd be grateful if you'd drop me a line at info@psys.co.uk. Thanks.