ffmpeg creating gif from images, add watermark dur

2019-09-16 20:12发布

问题:

I'm successfully creating animations from a series of static png's. I also want to add a watermark, but I'm having some issues when trying to add the watermark source.

Using this generates the animations fine:

ffmpeg -v warning -framerate 4 -i /tmp/img-%d.png -i /tmp/img-palette.png -lavfi "paletteuse" -y -loop 0 -vcodec libx264 -crf 25 -pix_fmt yuv420p -hide_banner /tmp/output.mp4

When I add the following to specify the watermark source (transparent png) an error is generated:

-i /tmp/logo.png -filter_complex "overlay=x=(main_w-100):(main_h-50)"

Full command:

ffmpeg -v warning -framerate 4 -i /tmp/logo.png -filter_complex "overlay=x=(main_w-100):(main_h-50)" -i /tmp/img-%d.png -i /tmp/img-palette.png -lavfi "paletteuse" -y -loop 0 -vcodec libx264 -crf 25 -pix_fmt yuv420p -hide_banner /tmp/output.mp4

Error:

video:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Do I need to generate the animation first, then apply the watermark to that artifact or is there a way to combine everything together during the creation process?

回答1:

Use

ffmpeg -v warning -framerate 4 -i /tmp/img-%d.png -i /tmp/img-palette.png -i /tmp/logo.png -filter_complex "[0][2]overlay=x=(main_w-100):(main_h-50)[v];[v][1]paletteuse" -y -vcodec libx264 -crf 25 -pix_fmt yuv420p -hide_banner /tmp/output.mp4

Specify all inputs upfront. You can only specify one filter_complex. -lavfi is an alias for filter_complex.