Converting weather cam images to video with FFmpeg

As of November 2020, I use a Foscam FI9900P as a weather cam. It is configured to upload an image twice a minute to my server over FTP. The latest image is then made available on https://meteodrenthe.nl/#/weercam.

The static image is fine, but I also want to be able to show a time lapse, a video with all stills stitched together. To achieve this, I decided to use FFmpeg on the Linux command line. In their own words, FFmpeg is a ‘complete, cross-platform solution to record, convert and stream audio and video.’ It has an option to input multiple images and convert them to a slide show in video format.

The required minimal documentation can be found here. The below command will take all images for November 1st (the usage of the wildcards depends, of couse, on the format of the images generated by the ip cam) and yield a video file ‘output.mkv’.

cat * _20201101-*.jpg | ffmpeg -f image2pipe -i - output.mkv

Compression
The resulting file is well over 200 MB’s large. This is a bit much! There are a bunch of compression options. Additionally, the video is bit fast. The clouds are flashing by so fast, there’s no time to appreciate what is going on! The default frame rate is 25. Lowering it will lower the number of frames passing by each second and, as a consequence, result in a longer video.

I’ve reduced the frame rate to 10. Obviously, changing it is optional. Much depends on how many frames the camera is already producing. I could also opt to increase the number of stills to 4 per minute. As for compression, adding a codec for video encoding should reduce the file size. I will use H.265.

cat *_20201101-*.jpg | ffmpeg -framerate 10 -f image2pipe -i - -c:v libx265 output.mkv

The file is now less than 150 MB in size. Still a lot.

Serious reduction of file size comes when passing a specific bit rate. I noticed that the bit rate of the resulting file was close to 5000 kbit/s. When playing around with the value, it turns out 800 is more than enough. That additional option would slash file size by a factor of roughly 6.

The final command looks like this:

cat *_20201101-*.jpg | ffmpeg -framerate 10 -f image2pipe -i - -c:v libx265 -b:v 800k output.mkv

Now the file size is reduced to roughly 25 MB. This is workable, I think. I might even increase the bit rate a bit.

Next up will be triggering command automatically. This will probably be a daily job. Since I already have a Java application responsible for more processes, I think I will keep everything in one place and let Java fire the command. Before I do this, I will need to decide how to host the video files. More on that in a next post.