Overlay A "Bubble Caption" Onto a Video

DESCRIPTION

Ok, this is kind of an overkill, but until I can find a more auotmated way of doing this using something like PiTiVi, I'll have to stick with my bash method using mencoder ,ImageMagick ,ffmpeg and Gimp.  For this example, I'll be using a video file, origvid.avi, that I want to overlay a caption, or as some people call it a "bubble caption" over top of the plain video. Something like a text box pointer for a documentation video.

 

PROECDURE

Ok, so first I use ffmpeg and convert the video from an AVI file, to a sequential number of JPG files:

ffmpeg -i origvid.avi output-%05d.png

...be careful where you run this command, becuase depending on the size of your AVI file, it could create thousands of output-#####.png files in this directory.

Next, open any of those above created PNG files in Gimp. I'll not explain this in detail, as I assume you'll now how to use Gimp. But basically, what you want to do here is create a new layer in the file, and in this new layer create your bubble caption. Then, delete the background (original) layer, so that this bubble caption has a nice transparent background.

Save this new file as a PNG file and call it caption.png

Next we want to use ImageMagick's composite command to overlay this caption.png file, ovetop all the PNG files created above. A simple for command will do that:

for x in output-*.png;
do composite caption.png $x `echo $x-caption | sed 's/\.png//g'`.png;
done

...now we have a whole bunch of PNG files, with the nice bubble caption transparently sitting on top of them. Open a few to check out.

Almost done.

Next we are going to put all the PNG files back together into our new video. We'll use this mencoder command:

mencoder mf://output-*-caption.png -mf type=png -o newvideo.avi -ovc xvid -xvidencopts max_bframes=1:bitrate=700:quant_type=mpeg:vhq=4

That's is....check out your newvideo.avi file, and you should be seeing what you're expecting. Delete all the image files (PNGs), and have fun!