Building video incrementally from incoming jpeg images

3

2

Is it possible to append one jpeg frame (or a small number of frames) to a video while retaining good image quality and compression? I have a script that downloads a jpeg image from a webcam every 30 seconds. I can build a video out of these frames using ffmpeg or mencoder, e.g.:

ffmpeg -f image2 -i %d.jpg out.swf

I'd like to keep this video up to date as new frames come in, but don't want to keep the computer busy re-encoding the entire video so frequently. I also worry about ffmpeg/mencoder doing something intelligent with only a single frame of new data - e.g. will it try to make each new frame a keyframe (making the video unnecessarily large)?

Any insight on how to do this sensibly would be greatly appreciated.

Kevin Ivarsen

Posted 2009-12-28T02:22:14.327

Reputation: 299

Answers

1

Why do you want to build it one frame at a time? How does that help you? Why not have your script rebuild the video every 15 minutes (30 frames) or something more reasonable like that?

SWF is an unusual file format for video output. In general, no, you can't add a single frame to the end of SWF (or FLV) movies because it requires a stateful compressor--the compressor would have to remain in RAM and remember the state of the last keyframe and all interframe compression done since then in order to encode the next frame.

If for some reason you absolutely need to add one frame to the end of your in-progress video, use MPEG 1. MPEG 1 video is just a sequence of single frames with no interframe compression, so you can have FFMPEG compress each JPEG and just cat it onto the end of the work in progress. Of course the result will be a huge poorly-compressed file by modern standards.

CarlF

Posted 2009-12-28T02:22:14.327

Reputation: 8 576

1I wanted to build the video one frame (or a few frames) at a time as a way to keep the video up to date without constantly swamping the CPU. This project may expand to include several video feeds, so I wanted to keep efficiency in mind. The video is being used for cloud monitoring at an astronomical observatory, which is why I wanted to keep it as up to date as possible. Most likely, I'll compromise by making two videos - a frequently updated one with just the last 30 minutes of data, and a less frequently updated one with the last 24 hours. I was just curious if frame-at-a-time was possible. – Kevin Ivarsen – 2009-12-28T17:44:26.683

You can run a script to combine the last 300 JPEG images into a 30 second FLV video (at 10 frames per second) every 15 minutes. You can also write a Flash SWF file that will play all the movies from a given hour or day, in sequence, so that to the viewer it looks like a single movie. No swamping. If you want to be fancy, write a script that combines all the movies from a given day into a single longer movie once very 24 hours at a low-traffic time like 2:00 am. – CarlF – 2009-12-29T06:59:10.713

0

If it's that few frames, convert them into an animated gif instead of a movie (with ImageMagick, for example).

That's how www.weather.gov animates radar imagery.

Camille Goudeseune

Posted 2009-12-28T02:22:14.327

Reputation: 1 361