Warm tip: This article is reproduced from serverfault.com, please click

How can I resize an overlay image with ffmpeg?

发布于 2020-11-27 13:25:03

I am trying to add an overlay to a video using the following command

ffmpeg -y -i "$videoPath" -i "$overlayPath" -filter_complex "[0:v] [1:v] overlay=$overlayPosition" -pix_fmt yuv420p -c:a copy "$outputPath" 

However, I would like to be able to resize the overlay I am about to apply to some arbitrary resolution (no care for keeping proportions). However, although I followed a couple of similar solutions from SO (like FFMPEG - How to resize an image overlay?), I am not quite sute about the meaning of the parameters or what I need to add it in my case.

I would need to add something like (?)

[1:v]scale=360:360[z] [1:v]overlay=$overlayPosition[z]

This doesn't seem to work so I'm not sure what I should be aiming for.

I would appreciate any assistance, perhaps with some explanation.

Thanks!

Questioner
Andrei Dascalu
Viewed
11
martinr92 2020-11-28 22:11:57

You have found all parts. Let's bring them together:

ffmpeg -i "$videoPath" -i "$overlayPath" -filter_complex "[1:v]scale=360:360[z];[0:v][z]overlay[out]" -map "[out]" -map "0:a" "$outputPath"

For explanation: We're executing here two filter within the "filter_complex" parameter separated by a semicolon ";".

First we scale the second video input ([1:v]) to a new resolution and store the output in variable "z" (you can put here any name). Second we bring the first input video ([0:v]) and the overlay ([z]) together and store the output in variable "out".

Now it's time to tell ffmpeg what he should pack into our output file: -map "[out]" (for the video) -map "0:a" (for the audio of the first input file)