使用ffmpeg在纯背景颜色上叠加timelapse视频 [英] Overlay timelapse video on solid background colour using ffmpeg
问题描述
我有一个名为homescreen000001.png
,homescreen000002.png
等的主页屏幕截图,我正在尝试使用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.
我想要一个白色背景,所以我一直在尝试使用ffmpeg进行如下设置:
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
这里whitebg.png
是2px x 2px png的白色背景,仅此而已.
Here whitebg.png
is 2px x 2px png with a white background, and that's it.
此ffmpeg命令产生的视频非常小(文件大小),只是一个白色背景.
This ffmpeg command produces a really tiny (in file size) video that's just a white background.
谁能解释我如何使用ffmpeg将图像作为延时视频覆盖在白色背景上?
Can anyone explain how I can overlay the images as a time-lapse video over a white background using ffmpeg?
推荐答案
您可以使用颜色过滤器作为背景:
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
另请参阅:
- image demuxer documentation
- overlay filter documentation
- How to position overlay with ffmpeg?
这篇关于使用ffmpeg在纯背景颜色上叠加timelapse视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!