Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay timelapse video on solid background colour using ffmpeg

Tags:

ffmpeg

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?

like image 662
hamchapman Avatar asked Jul 27 '14 22:07

hamchapman


2 Answers

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:

  • image demuxer documentation
  • overlay filter documentation
  • How to position overlay with ffmpeg?
like image 161
llogan Avatar answered Jan 04 '23 05:01

llogan


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.

like image 35
Mark Setchell Avatar answered Jan 04 '23 05:01

Mark Setchell