The folliwng should basically have an image appear on frame 438, and then the same image move to a different position on frame 339, then basically disappear for the rest of the video.

ffmpeg -i C:\src\assets\video\base.mp4 -r 25 -i C:\card.png -y \
    -filter_complex [1:v]setpts=PTS-STARTPTS+(1/TB)[1v]; \
    [0:v][1v]overlay=x=0:y=0:enable='between(t,438/25,439/25)'[1v]; \
    [0:v][1v]overlay=x=300:y=300:enable='between(t,439/25,440/25)'[2v]; \
    [1v][2v]concat=n=2:v=1:a=0[out] -map [out] -map 0:a -ss 17 C:\temp\j7kthb0v\composit.mp4

I can't seem to get the actual command correct or output anything that resembles what I need.

I know I'm close, I can get one frame overlayed, but I can't get more than that.



ffmpeg -i C:\src\assets\video\base.mp4 -i C:\card.png -y \
       -filter_complex "[0:v][1:v]overlay=x='if(eq(n,439),300,0)':y='if(eq(n,439),300,0)':enable='eq(n,438)+eq(n,439)'[out]" \
       -map [out] -map 0:a -ss 17 C:\temp\j7kthb0v\composit.mp4

You may need to escape the commas in filters depending on your shell i.e. n,438 -> n\,438

  • That's awesome, thankyou, much simpler than multiple overlays – Shannon Hochkins Jun 26 '18 at 5:45
  • I didn't ask this in the original post, but I'm using this solution for animation, I want to basically specify a position for X & Y, based on a frame number. I can achieve this doing nested if else hell. but is there a nicer way? – Shannon Hochkins Jun 26 '18 at 6:55
  • Not really. The filter isn't meant for animation like that. You can simplify it somewhat like this: x='0*eq(n,438)+300*eq(n,439)+X*eq(n,567)+...' – Gyan Jun 26 '18 at 7:25
  • I've been playing around with the variable n, in overlay if I were to do: overlay=x='( 605 + -0.8023952095808383 * n)':y='( 406 + -0.4365269461077843 * n)':enable='between(t,438/25,605/25)', does this mean the n would equal 0 and incremented for every frame it's visible for ? (605 - 438) – Shannon Hochkins Jun 26 '18 at 7:41
  • Those expressions mean the overlay starts at (605,406). With each frame, (0.80,0.43) is subtracted and then rounded. But it's only visible (at the computed positions) between times 17.56 and 24.20 – Gyan Jun 26 '18 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.