| | 1 | = Create a sliding and bouncing overlay = |
| | 2 | |
| | 3 | In this example, the foreground video slides over the background one and bounces on the four edges. The output audio stream selected is the background one. |
| | 4 | |
| | 5 | It can be used "as-is" under Windows. Unix users should replace ending `^` by `\`. The command line below has been splitted to make it more understandable. |
| | 6 | |
| | 7 | {{{ |
| | 8 | ffmpeg -i "background.mp4" -i "foreground.mp4" -filter_complex ^ |
| | 9 | overlay='^ |
| | 10 | if(eq(mod(floor(st(8,t*320)/(W-w)),2),0),^ |
| | 11 | mod(ld(8),W-w),^ |
| | 12 | W-w-mod(ld(8),W-w))^ |
| | 13 | :^ |
| | 14 | if(eq(mod(floor(st(9,t*140)/(H-h)),2),0),^ |
| | 15 | mod(ld(9),H-h),^ |
| | 16 | H-h-mod(ld(9),H-h))^ |
| | 17 | :^ |
| | 18 | eval=frame^ |
| | 19 | :^ |
| | 20 | repeatlast=1^ |
| | 21 | ' ^ |
| | 22 | "OUTPUT.mp4" |
| | 23 | }}} |
| | 24 | |
| | 25 | This example works properly with a 1080p (16/9) background and a 360p (16/9) foreground but can be modified to work with any scale. |
| | 26 | |
| | 27 | The horizontal speed (t*320) and the vertical one (t*140) can be tuned. They are stored in internal variables 8 and 9 to avoid duplicates. |
| | 28 | |
| | 29 | Pay attention to the input durations and use either '''repeatlast''' or '''shortest''' options of the overlay filter. |
| | 30 | |
| | 31 | Have in mind that frames are taken from each input video in timestamp order, hence, if their initial timestamps differ, it is a good idea to pass the two inputs through a '''setpts=PTS-STARTPTS''' filter to have them begin in the same zero timestamp. |