With MP4 I used this command
ffmpeg -i INPUT.mp4 -vf ass=SUBS.ass -c:v libx264 -preset ultrafast -crf 22 -c:a copy OUTPUT.mp4
which has helped to increase the speed.
But there are some problems with WebM format, I tried to use this command which didn't help
ffmpeg -i INPUT.mp4 -vf ass=SUBS.ass -c:v vp9 -crt 22 -c:a copy OUTPUT.mp4