When I did reencodings with frame intrepolations I used construction to remove several frames from the end:
trim(0,framecount-10)Insert it into the end of your script.
10 is empirical value. The value can be from 1 to 20. It depends on threads count and smoothing factor.
It helped me to avoid encoder hangs.