Quantcast
Channel: Resizing overlay image - Super User
Viewing all articles
Browse latest Browse all 2

Answer by Ricardo Bohner for Resizing overlay image

$
0
0

This is the code I used in my tests, please see if it gets you the expected output

By using 2 images:

In this example I cut the top and bottom part in 2 separate images:

ffmpeg -i Input.mp4 -i Top.jpg -i Bottom.jpg -filter_complex "[1][0]scale2ref=w=iw:h=ow/mdar[top][vid];[2][vid]scale2ref=w=iw:h=ow/mdar[bottom][vid];[top][vid][bottom]vstack=inputs=3[final];[final]scale=iw:-2[final]" -map [final] -map 0:a:0 -shortest -vsync 0 -c:v libx264 "Output.mp4"

This was the resulting video: test.mp4

By using a single image:

In this example I used the image provided by the topic creator.

Considering the following coordinates:

enter image description here

In theory at least form my calculations this should have worked perfectly but I still got some black strip between the video and the bottom part but no big mess...

ffmpeg -i input.mp4 -i img.jpg -filter_complex "[1][0]scale2ref=w=iw:h=ow/mdar[img][vid];[vid][img]scale2ref=h=ih*((533-(53+118))/533)[vid][img];[img][vid]overlay=x=0:y=H*((53)/533)[final];[final]scale=iw:-2[final]" -map 0:a:0 -map [final] -shortest -vsync 0 -c:v libx264 -c:a copy output.mp4

Explaining:

This part sets the image same width and proportional height as video width:"[1][0]scale2ref=w=iw:h=ow/mdar[img][vid];Sets the video height according to the black area:[vid][img]scale2ref=h=ih*((533-(53+118))/533)[vid][img]Positions the video as overlay under the top part of the image:[img][vid]overlay=x=0:y=H*((53)/533)[final]Scales the resulting video to force the height to be divisible by 2 cause mp4 videos return errors if the height is not divisible by 2...:[final]scale=iw:-2[final]" 

Viewing all articles
Browse latest Browse all 2

Trending Articles