ffmpeg – put video atop of second and center it while keeping aspect ratio

Issue

I’m trying to put 16:9 video atop of same blurred 1:1 video just like on the photos.
I’m looking a wise guy with ffmpeg knowledge to help me with think of about the command which will:

  1. rescale 16:9 (sharp video) accordingly to blurred one height (keeping the width automatically to ratio)
  2. center the 16:9 (sharp video) to x position = (blurredVideoWidth / 2) – (sharpVideoWidth / 2)

My current comment looks like this:

ffmpeg -y -i ${squareBlurredVideoUri} -i ${square169VideoUri} -filter_complex "[1:v]scale=620:-1[v2];[0:v][v2]overlay=0:0" -codec:a copy ${squareFinalVideoUri}

As you can see scale is hardcoded to 620 which is wrong because we should rescale it accordingly to blurred video height.

Overlay is set to 0:0 which places sharp video to x = 0 and y = 0 and should center it

Thank you in advance.

Current result:
current
Desired result:
desired

Solution

Here is an FFMPEG Command to Generate out put image you want. You dont have to pass 2 image to make Desired Output image

ffmpeg -i test.jpg -vf "[0:v]split=2[blur][vid];[blur]scale=720:720:force_original_aspect_ratio=increase,crop=720:720,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];[vid]scale=720:720:force_original_aspect_ratio=decrease[ov];[bg][ov]overlay='(main_w-overlay_w)/2:(main_h-overlay_h)/2'" output.png

in this command we have used boxblur attribute to make Background Blur using our input file, we have fix 720*720 aspect ratio for now or we can set input’s height (Portrait image) or input’s width (landscape image) to make it square, then we get box height width and overlay height width then devide by 2 (Logical Calculation for Centered image)

Answered By – Vinesh Chauhan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published