0

am using latest version of ffmpeg and i have added image overlay to video and am trying to animate the image overlay on video , its working ok but the overlay movement is not smooth its shaky/glitchy , so any idea how to make the animation smooth

ffmpeg.exe -y -i small.mp4 -loop 1  -i google.png -filter_complex   [1]fade=t=in:st=1:d=1,fade=t=out:st=4.6:d=1[over1];[0:v][over1]overlay=x=20+((t-1)*85):shortest=1:y=66+((t-1)*23.04):enable='between(t,1,5.6)' -c:v libx264 output.mp4

input video : http://techslides.com/demos/sample-videos/small.mp4

image : https://i.imgur.com/yLqJciB.png

output video : https://vimeo.com/286859270

Update : Overlay Factor explanation

x=20+((t-1)*85):shortest=1:y=66+((t-1)*23.04)

85 ? 23.04 ?

85 and 23.04 is x and y shift rate through which i have to reach to destination x_end and y_end from x_start and y_start

x_start = 20 , y_start = 66

x_end = 411 , y_end = 172

x_diff = 391 y_diff = 106

overlay_start_time = 1 overlay_end_time = 5.6

duration = overlay_end_time - overlay_start_time

duration = 5.6 - 1

duration = 4.6

shift_x_rate = x_diff / duration

shift_x_rate = 391 / 4.6 = 85

shift_y_rate = y_diff / duration

shift_y_rate = 106 / 4.6 = 23.04

x = x_start + (t-overlay_start_time)* shift_x_rate

x = 20 + (t-1) * 85

let if t = 5.6

x = 20 + (5.6-1) * 85

x = 411 // destination x

y = y_start + (t-overlay_start_time)* shift_y_rate

y = 66 + (t-1) * 23.04

let if t = 5.6

y = 66 + (5.6-1) * 23.04

y = 171 // destination y

2

There are multiple issues here:

a) although your expressions are continuous and smooth over time, video is a series of discrete frames, so the actual series of time values is quantized. So, the velocity of your motion should be an integral multiple of the video's framerate, in terms of x-pixels/sec and y-pixels/sec. That way, the delta x and y in each frame is constant, thus yielding a straight-line motion. In your case, these differ frame by frame due to truncation.

b) due to chroma subsampling, the overlay's final evaluated position is subject to a further rounding down to an even value. So, calculated (314.6,56.3) will get rounded to (314,56) and (316.8,57.4) will get rounded to (316,56) thus yielding a horizontal motion in that frame even though the expressions' pure delta is sloped. The solution is to tell overlay to output with full chroma sampling, and downconvert later.

These issues are in play during all overlay animation but since your video has a low resolution, the glitch is prominently visible. Your video is 30 fps, so I've set x and y deltas to multiples of that.

So,

ffmpeg.exe -y -i small.mp4 -loop 1 -i google.png -filter_complex [1]fade=t=in:st=0.9:d=1,fade=t=out:st=4.6:d=1[over1];[0:v][over1]overlay=x=20+((t-0.9)*60):shortest=1:y=66+((t-0.9)*30):enable='between(t,0.9,5.6)':format=yuv444,format=yuv420p -c:v libx264 output.mp4
|improve this answer|||||
  • ya overlay is now smooth with framerate *60 with x and *30 with y , i used 68 and 18.6 because i had to reach to specific destination , now with *60 and *30 the overlay will not reach destination , i have updated the question , if you not mind can you have look on it , i explained the two factors how am computing them to reach to destination , i wonder if i have to use framerate it their place how could i reach to destination x y points – user44570 Aug 27 '18 at 17:56

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.