(with expression) - (3)¶
Watch on youtube.com- doc
https://ffmpeg.org/ffmpeg-filters.html#overlay-1, https://ffmpeg.org/ffmpeg-filters.html#crop, (ffmpeg-utils)3. Expression Evaluation
You can also pass expressions to “crop” in ffmpeg. Therefore, using “crop” also makes it a bit more complicated.
Perhaps you would want to do something similar when you use “scale”. Unfortunately you can not use timestamps to “scale”, so you might be disappointed.
00:00:00#! /bin/sh
pref="`basename $0 .sh`"
img="adult-beautiful-beauty-206593.jpg"
dur=20
#
ffmpeg -y -i "${img}" -filter_complex "
color=black:size=1920x1080,loop=loop=-1:size=2,setsar=1[bg];
[0:v]
scale=-1:1080,pad=1920:1080:(ow-iw)/2:0:color=0x000033,
loop=loop=-1:size=2,
crop='1120:630:(sin(t)+1)/2*(iw-ow):(cos(t/0.625)+1)/2*(ih-oh)',
setsar=1[iv];
[bg][iv]
overlay='x=(sin(t)+1)/2*(W-w):y=(cos(t/0.625)+1)/2*(H-h)'
[v]
" -map '[v]' -an -shortest -t ${dur} ${pref}-out.mp4
#! /bin/sh
pref="`basename $0 .sh`"
img="adult-beautiful-beauty-206593.jpg"
dur=20
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" -y \
-i "${img}" -filter_complex "
color=black:size=1920x1080,loop=loop=-1:size=2,setsar=1[bg];
[0:v]
scale=-1:1080,pad=1920:1080:(ow-iw)/2:0:color=0x000033,
loop=loop=-1:size=2,
crop='1120:630:round((sin(t)+1)/2*(iw-ow)):round((cos(t/0.625)+1)/2*(ih-oh))',
setsar=1[iv];
[bg][iv]
overlay='x=round((sin(t)+1)/2*(W-w)):y=round((cos(t/0.625)+1)/2*(H-h))'
[v]
" -map '[v]' -an -shortest -t ${dur} ${pref}-out.mp4
#! /bin/sh
pref="`basename $0 .sh`"
img="adult-beautiful-beauty-206593.jpg"
dur=20
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" -y \
-i "${img}" -filter_complex "
color=black:size=1920x1080,loop=loop=-1:size=2,setsar=1[bg];
[0:v]
scale=-1:1080,pad=1920:1080:(ow-iw)/2:0:color=0x000033,
loop=loop=-1:size=2,
crop='1120:630:round((cos(t)+1)/2*(iw-ow)):round((sin(t/0.625)+1)/2*(ih-oh))',
setsar=1[iv];
[bg][iv]
overlay='x=round((sin(t)+1)/2*(W-w)):y=round((cos(t/0.625)+1)/2*(H-h))'
[v]
" -map '[v]' -an -shortest -t ${dur} ${pref}-out.mp4
Using `crop’ to scroll the image¶
By the way, because you can use the expressions in x, y of `crop’, you can also use (not overlay but) `crop’ to scroll the image:
#! /bin/sh
tdur=40
pbdur=${pbdur:-3} # pause before scrolling
padur=${padur:-3} # pause after scrolling
#
ffmpeg -y -i unix.png -filter_complex "
[0:v]
scale=1280:-1
,loop=-1:size=2,trim=0:${tdur},setpts=PTS-STARTPTS,setsar=1
,crop='
w=1280:
h=720:
x=0:
y=min(max(0, t - ${pbdur}), (${tdur} - ${pbdur} - ${padur})) / (${tdur} - ${pbdur} - ${padur}) * (ih-oh)
'
" unix.mp4