FFMPEG scaling watermark - ffmpeg

I'm currently using a command to add a watermark + scrolling text and some extra encoding options to a video.
The watermark + scrolling text are made to fit correctly when the video is 1280px (width) but when the original video is any other size (for example 1920px) the watermark + scrolling text gets tiny so i need to scale this.
watermark size= 400x48
Current code i'm using
-i logo.png -filter_complex "[0:v][1:v] overlay=x=(main_w-overlay_w):y=(main_h-overlay_h-4)[out];[out]drawtext=fontsize=20:font=tahoma:alpha=0.5:fontcolor=white:borderw=0.8:bordercolor=black:text=THIS IS MY SCROLLING TEXT :y=line_h-4:x=w-(t-300)*w/40" -keyint_min 20 -vcodec libx264 -c:a copy -b:v 1700k -movflags +faststart
I think that this piece of code scale2ref=400*iw/1280:48*iw/1280 might do the work but i have no clue where exactly to paste this in. I keep on getting errors.

The correct syntax is,
"[1:v][0:v]scale2ref=400*iw/1280:48*iw/1280[wm][vid];[vid][wm]overlay=x=(main_w-overlay_w):y=(main_h-overlay_h-4),drawtext=fontsize=20:font=tahoma:alpha=0.5:fontcolor=white:borderw=0.8:bordercolor=black:text=THIS IS MY SCROLLING TEXT :y=line_h-4:x=w-(t-300)*w/40"
For fontsize, if 20 is acceptable for width 1280, then use expression fontsize='20*main_w/1280'

Related

Overlay image zoom out and move

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"

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

FFmpeg - How to scale a video then apply a watermark?

Im trying to scale a video so that it is always 512 wide where the height changes in proportion to the original video.
Once scaled, I then want to apply a watermark/overlay to the video, therefore the video will scale but the watermark wont.
I am able to achieve each of these separately using the following filters:
Scale
-vf "scale=512:-1"
Watermark
-vf "movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
They work successfully on their own.
However when trying to combine the two, Im having a bit of trouble.
Having both as parameters of course does not work as one will override the other.
Ive tried:
-vf "scale=512:-1,movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
my thinking was that the scale would be applied first then the watermark but all I get is an error
Too many inputs specified for the "movie" filter.
Error opening filters!
Then changing the , to a ; resulted in:
Simple filtergraph 'scale=512:-1;
movie=watermark.png
[watermark]; [in][watermark]
overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]' does not have
exactly one input and output.
Error opening filters!
I presume I need to do something more with filterchains but Im struggling to figure it out.
Any ideas anyone?
Many thanks in advance.
You can use the -filter_complex option with the scale and overlay filters:
ffmpeg -i input.mp4 -i logo.png -filter_complex "[0:v]scale=512:-1[bg];[bg][1:v]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" output
See scale and overlay filter documentation for more info.
No need for the movie source filter as in the other examples.
You can add -c:a copy if you want to stream copy (re-mux) the original audio instead of re-encoding it. This is useful if your input and output container formats are the same.
The example will place the logo in the center. For other placement options:
Upper left with 10 px padding: overlay=10:10
Upper right with 10 px padding: overlay=W-w-10:10
Lower right with 10 px padding: overlay=W-w-10:H-h-10
Lower left with 10 px padding: overlay=H-h-10:10
Thank you to both #DiJuMx and #LordNeckbeard, you both got me closer to my solution. Ive not tried the filter_complex option yet but it certainly looks simpler.
The solution I found to work is:
-vf "movie=watermark.png [watermark]; [in]scale=512:trunc(ow/a/2)*2 [scale]; [scale][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
Note that Ive replaced the -1 in the scale as that had the potential to cause an uneven number of pixels in the height of the video when scaling which would then cause encoding errors.
From what I understand, this might work:
-vf "movie=watermark.png [watermark]; [in] scale=512:-1,[watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
You apply the scale filter to the input "[in]".
Unfortunately I don't have much experience with the filters on ffmpeg so I can't help further. Sorry

Resources