If you already have a way to capture each frame, say a a jpg, you can use mencoder or ffmpeg to convert them into a movie. For example, this will take a series of jpg's , like 0000001.jpg, 0000002.jpg, etc
#create a small speed adjusted file
mencoder "mf://*.jpg" -mf fps=60 -o output.avi -ovc lavc -lavcopts vco
or with ffmpeg
ffmpeg -f image2 -i image%d.jpg video.mpg
# This command will transform all the images from the current direct
# (named image1.jpg, image2.jpg, etc...) to a video file named video.
You can google for assemble images to avi ffmpeg
Also see z-charcoal-video-converter for how to use these programs from Perl. In this one, I rip the movie to jpgs and audio, process each frame to a charcoal effect, then recombine them. It does audio too, but you don't need that. It does show how to run the commands thru Perl's system, and handling of the jpg filenames. It's preferrable to put the jpgs in a separate sub directory, since there can be so many of them.
Oops, I just read that you can't save the images to disk first, so that kind of blows my method above away; but if you could somehow feed the frames to ffmpeg in a realtime stream, you may have some luck.
Google for ffmpeg capture streaming frames . In that train of thought, see Webcam Streaming to Perl/Tk with ffmpeg