3

I'm trying to write a command within FFmpeg that will first overlay one video stream on top of another one. Then I want the overlayed video to move from one pixel coordinate at a known time, and end at another pixel coordinate at a later time.

I'm comfortable with the basics of the -filter_complex, but I cannot figure out how to apply any arithmetic expressions - like the one's referenced here: https://www.ffmpeg.org/ffmpeg-utils.html#Expression-Evaluation

Here's an example of something I'd like to accomplish.

ffmpeg -i [INPUT1] -i [INPUT2] -filter_complex "[0:v][1:v]overlay=shortest=1:x=720:y=0:enable='between(t,10,20)'[overlay];...

In this example the overlay is stationary at pixel coordinate 720x0 from the 10th second to the 20th second.

However, Id like to have it move to a new location in a linear fashion and end at a different pixel coordinate.

For example, during that 10 second overlay, I'd like to have it start at 720x0, but then end at 1000x100.

Is this possible?

occvtech
  • 453
  • 3
  • 10

1 Answers1

10

Is this about what you're looking for?

making a movement

This crappy example has a duration of 6 seconds. The red box appears after 2 seconds and ends 3 seconds later.

Example:

ffmpeg -i bg.mp4 -i fg.mkv -filter_complex \
"[0:v][1:v]overlay=enable='between=(t,10,20)':x=720+t*28:y=t*10[out]" \
-map "[out]" output.mkv
  • Move x from position 720 to 1000 in 10 seconds. That equals 28 pixels/second.

  • y is easy enough.

  • t is the timestamp in seconds.

  • The overlaid video (fg.mkv in this example) will already be 10 seconds into its duration when it appears.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Perfect, thanks! I was originally struggling to understand what the `t*28` area meant - but that makes perfect sense that it is a pixel value changing at a rate of 28 pixels per second. Could this work in a scale filter like: `scale=720+t*2:480`? I would expect that would increase the X pixel value by 2 every second. Is that correct? – occvtech May 22 '15 at 15:35
  • Hey, how would this work if we wanted to use this with a fade in and fade out for the moving element as well? – Navid Khan Feb 28 '20 at 11:02
  • @NavedKhan Probably. See the [fade](https://ffmpeg.org/ffmpeg-filters.html#fade) filter. There are several usages examples on SO. – llogan Feb 28 '20 at 22:26