8

I've got a load of screenshots of a homepage that are named homescreen000001.png, homescreen000002.png, etc and I'm trying to create a time-lapse video of these images using ffmpeg.

I've got it working in general when I run the following:

ffmpeg -f image2 \
       -i ~/Desktop/homescreen%06d.png \
       -r 0.5 \
       -s 1440x900 \ 
       -b:v 1M \
       -vcodec libx264 \ 
       -pix_fmt yuv420p \
       ~/Desktop/timelapse.mp4

However, it turns out that some of the images have transparent backgrounds so the background is showing up as black on those images.

I'd like a white background so I've been trying to set that up using ffmpeg as follows:

ffmpeg -f image2 \
       -loop 1 \
       -i ~/Desktop/whitebg.png \
       -i ~/Desktop/homescreen%06d.png \
       -filter_complex overlay \ 
       -r 0.5 \
       -s 1440x900 \ 
       -b:v 1M \
       -vcodec libx264 \ 
       -pix_fmt yuv420p \
       ~/Desktop/timelapse.mp4

Here whitebg.png is 2px x 2px png with a white background, and that's it.

This ffmpeg command produces a really tiny (in file size) video that's just a white background.

Can anyone explain how I can overlay the images as a time-lapse video over a white background using ffmpeg?

hamchapman
  • 2,901
  • 4
  • 22
  • 37

2 Answers2

20

You can use the color filter as a background:

ffmpeg -f lavfi -i color=c=white:s=1920x1080:r=24 -framerate 24 -i input_%04d.png -filter_complex "[0:v][1:v]overlay=shortest=1,format=yuv420p[out]" -map "[out]" output.mp4

Also see:

llogan
  • 121,796
  • 28
  • 232
  • 243
1

You can replace the transparent pixels with white ones using ImageMagick like this:

convert in.png -alpha off out.png

or for a whole directory (with output files in a subdirectory called output) like this:

mkdir output
for i in *.png; do
   convert "$i" -alpha off output/"$i"
done

Please make a backup first!

ImageMagick is here though it is already installed on many Linux distros.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • While I like the general idea, this command does not produce white backgrounds. At least not anymore. Use the following instead: `convert "$i" -background white -alpha remove -alpha off output/"$i"` Found [here](https://stackoverflow.com/a/8437562/3821986). – Nicolas Reibnitz May 12 '21 at 23:14