Script to make a video slideshow from a bunch of pictures
I wanted to create a video slideshow out of a bunch of pictures. The several GUIs I tried were all disappointing: they duplicated the same picture across many frames, resulting in a large file. Instead, I wanted each picture to use a single frame, and the frames to move very slowly (e.g. 4 seconds per frame, or 0.25 FPS).
Mencoder has a feature to do this, and it lets you specify the output format, resolution, and FPS. For example, we can do:
mencoder mf://*.JPG -mf w=640:h=480:fps=0.25 \
-ovc lavc -lavcopts vcodec=mpeg4 \
-o output.avi
There are two annoying limitations (my version is
SVN-r1.0~rc3+svn20090426-4.4.3
):
-
It does not support images of different resolutions.
-
It gets confused by EXIF orientation tags, which are used by most cameras nowadays.
This can result in a cryptic error message:
Unsupported PixelFormat 38 0.00fps Trem: 0min 1mb A-V:0.000 [366:0]
Unsupported PixelFormat 38
VDec: vo config request - 640 x 480 (preferred colorspace: Unknown 0x0000)
The selected video_out device is incompatible with this codec.
Try appending the scale filter to your filter list,
e.g. -vf spp,scale instead of -vf spp.
Luckily, the convert
tool from ImageMagick comes to our rescue. To resize an
image to the desired resolution, we can do:
convert orig.jpg \
-auto-orient -resize 640x480 -gravity center \
-background black -extent 640x480 \
result.jpg
The -auto-orient
bit rotates the image to neutralize the EXIF orientation
tag. The -background black -extent 640x480
bit pads the image with black.
This is useful if the aspect ratios don't match, for example if the original
image is in portrait, but the desired resolution is in landscape.
The final result: a quick-and-dirty script to resize all images and create the video slideshow: mk_slideshow.sh. It is not the most user-friendly (it could take resolution and FPS as command-line parameters, for example), but it gets the job done.
Bonus tip:
To see the EXIF orientation tag of a JPEG image, we can use the identify
command from ImageMagick:
identify -verbose image.jpg |grep Orientation
If it is anything other than TopLeft
(or 1
), mencoder will get confused.
Have fun making lolcat slideshows ;-)