Assuming you have FFmpeg (http://ffmpeg.org/) installed, you should be able to run the following command. (It helps to have ffmpeg on your path, or call it absolutely from your script.)
ffmpeg -y -i ./path/to/video.mpg -f mjpeg -ss 00:00:05 -vframes 1 ./path/to/thumbnail.jpg
- The -f flag forces the output to "mjpeg". You can view a list of available formats by with "ffmpeg -formats".
- The -ss flag denotes the position in the video (HH:MM:SS[.xxx] format). I'm sure there's a way to get the total length of the video (if you're doing video conversions before this, you should be able to get it by parsing STDERR).