How do I apply a timecode and then I speed up x4 a video with ffmpeg without losing quality? I'm trying to create a .bat file for ffmpeg that:


Applies a timecode overlay (e.g. 00:17:23:02)
Speeds up the video x4 (but AFTER the timecode is applied)
Doesn't "touch" the quality of the original video




This is what I got:

for %%a in ("*.avi") do (
    ffmpeg.exe -i "%%a" -vf "drawtext=fontfile=C\\:/Windows/Fonts/arial.ttf:timecode='00\:00\:00\:00':rate=5:text='Real \time\:':fontsize=46:fontcolor=white:x=30:y=30: box=1: boxcolor=0x00000000@1" -f avi "%%~na_with-time.avi"
)



It works but I can't speed up x4 the video and it also losses a lot of the quality (very pixelated when moving around in the video)

This is what code I could use to speed up x4 the video but I can't get it in the code above (to work):
"setpts=0.25*PTS"

Also this is the quality:

How the video looks before:


After conversion with the ffmpeg .bat code above:


Is there a way to speed-up the video x4 (but with the normal time timecode) and also don't change the quality of the exported video)? 

Also is there a way to make the black box behind the timecode a bit bigger (5 pixels in all directions: left, up, right, down)? Or maybe a stroke effect to the text instead of the black box?
Use

for %%a in ("*.avi") do (
    ffmpeg.exe -i "%%a" -vf "drawtext=fontfile=C\\:/Windows/Fonts/arial.ttf:timecode='00\:00\:00\:00':rate=5:text='Real \time\:':fontsize=46:fontcolor=white:x=30:y=30:box=1:boxcolor=0x00000000@1:boxborderw=5,setpts=0.25*PTS" -c:v libx264 -f avi "%%~na_with-time.avi"
)


Added boxborderw=5 for border width.

Added setpts after the drawtext.

Added encoder explicitly -c:v libx264 - its default settings should produce good images. You can also stick with the default encoder (mpeg4) and just add -q:v 5 for decent quality - the default of 200 kbps is too low.



For a custom timecode string, remove timecode='00\:00\:00\:00':rate=5

and change text to 

text='Real \time\: %{eif\:trunc(t/3600)\:d\:2}h %{eif\:trunc(mod(t/60\,60))\:d\:2}m %{eif\:trunc(mod(t\,60))\:d\:2}s'