Overlay image zoom out and move - ffmpeg

I have a video with an image overlay. The picture is set nearly full screen for the first 10 seconds, and aftwerwards I need to zoom out the image to a smaller size and place it in the bottom left corner for the rest of the video.
At the moment I split the input image and overlay it twict to the video, without transitions, one for the "big" picture and one for the "small" picture and it works fine.
What I would like to make is a "zoom out and moove" effect to make it smoother from the big central picture to the small one.
This is my current complex filter:
-i "video.mp4"
-i "img.jpg"
-filter_complex "[1:v]split=2[img10][img20];[img10]scale=1469:856[img11];[img20]scale=293:171[img21];[0:v][img11]overlay=(main_w-overlay_w)/2:(main_h - overlay_h)/2:enable='between(t,0,10)',fade=out:st=9:d=1:alpha=1[vid];[vid][img21]overlay=10:(main_h-overlay_h-40):enable='gte(t,10)'"
-crf 18 -c:a copy "out.mp4"
How can I make it as a single image overlay with zoom out + move effect?

Using ffmpeg version 4.3 or newer, you can animate the scale parameter. And then animate the overlay parameter.
ffmpeg
-i "video.mp4"
-loop 1 -i "img.jpg"
-filter_complex "[1:v]scale=w='if(between(t,10,14),1469-(1469-293)*(t-10)/4,if(lt(t,10),1469,293))':h='if(between(t,10,14),856-(856-171)*(t-10)/4,if(lt(t,10),856,171))':eval=frame[img];[0:v][img]overlay=x='if(between(t,10,14),(W-w)/2-((W-w)/2-10)*(t-10)/4,if(lt(t,10),(W-w)/2,10))':y='if(between(t,10,14),(H-h)/2-((H-h)/2-(H-h-40))*(t-10)/4,if(lt(t,10),(H-h)/2,H-h-40))':shortest=1"
-crf 18 -c:a copy "out.mp4"

Related

Adding an image in the padding area of the video instead of black color using FFMPEG

I have some videos of resolution 1280 X 720 with black padding area in both left and right side around the display area of all videos. I want to display a static image in padding area of video instead of solid black color. I am working with FFMPEG library but can't find any way to do so. Can you please help me regarding this?
Thank You!
Use the cropdetect filter to determine crop parameters to remove the black. See Remove black bars using ffmpeg for an example of how to get the crop parameters.
Crop the black area and overlay the video over the image:
ffmpeg -i video.mp4 -i background.jpg -filter_complex "[0]crop=404:720:438:0[vid];[1][vid]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -c:a copy output.mp4
Well, after trying some commands I made a command to do so and its working for me.
ffmpeg -loop 1 -i image.jpg -i video.mp4 -filter_complex "[1:v]scale=1280:720:force_original_aspect_ratio=decrease:-1[fg];[0:v][fg]overlay=(W-w)/2:(H-h)/2:shortest=1" output.mp4

add an image as water mark for video with opacity size adjustment and opacity

I'm trying to add watermark for video but as any video editor I also want options of all opacity size and position I found for both opacity and position the below command does it but I missing with scaling the image
ffmpeg -i test.mp4 -i test1.png -filter_complex "[1]format=rgba,colorchannelmixer=aa=0.25[logo];[0][logo]overlay=50:50" -c:a copy output.mp4
Insert a scale filter after the ccm filter.
format=rgba,colorchannelmixer=aa=0.25,scale=W:H

ffmpeg scale down video dynamically (squeeze-back) or zoompan out to smaller than original

I have 2 videos, I'm trying to overlay one on top of the other, and have it shrink down in an animated fashion until it appears like a picture-in-picture setup. Then, after a few seconds it should scale back up.
This is what I am trying to achieve (these would be videos, not images):
This is the closest I've been able to get, but, crucially, zoompanning "out" (as opposed to "in") does not appear to work; so, of course, this does not work:
ffmpeg -i bg.mov -i top.mov -filter_complex "[0:v]zoompan=z='pzoom-0.1':d=1, setpts=PTS-STARTPTS[top]; [1:v]setpts=PTS-STARTPTS+2/TB, scale=1920x1080, format=yuva420p,colorchannelmixer=aa=1.0[bottom]; [top][bottom]overlay=shortest=0" -vcodec libx264 out.mp4
Is this achievable with ffmpeg?
Use the scale filter with animation, available since v4.3.
Here's something to get you started. This will expand the top layer from 480 px height to 1080 height in 2 seconds and then back to 480 px in 2 seconds.
ffmpeg -i bg.mov -i top.mov -filter_complex "[0:v]scale=1920x1080,setpts=PTS-STARTPTS[bg]; [1:v]setpts=PTS-STARTPTS+2/TB, scale=-1:'480+600*abs(sin((t-2)*2*PI/8))':eval=frame[top]; [bg][top]overlay" -vcodec libx264 out.mp4

How to add zoom transition effects using FFmpeg to a variable number of images?

How can I add add zoom transition effects using FFmpeg to a variable number of images?
I am able to create video from a variable number of images but I am not sure how to add zoom in and out transition effects between images:
ffmpeg -framerate 1/5 -i img%03d.jpeg -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
I found this,
https://superuser.com/questions/1189246/ffmpeg-image-slideshow-with-zoompan-and-fade-in-out/1190199
But problem is that images are hard coded in that example and I am not sure how to make it work for a variable number of images?

how to mirror + add logo to video?

how to mirror + add logo to video?
How to mirror video, then add logo to video using ffmpeg?
To flip a video horizontally, you can use -vf hflip (or vflip for vertical flipping).
To add a watermark of any image to a video is more complex, especially if you want to position it:
-i logo.png -filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2"
There are a lot of things you can do with the overlay filter, check the documentation. It gets extremely complex if you also want to scale the overlay, so make sure your logo file is the right size before that.
However, you cannot mix -vf and -filter_complex, so the flipping has to become part of the complex filter. So, for your desired result, you'd have to do this (assuming you want the logo to be at position 10/10):
ffmpeg -i input.mp4 -i logo.png -filter_complex "hflip[flipped];[flipped]overlay=x=10:y=10" out.mp4

Resources