How do I apply a timecode and then I speed up x4 a video with ffmpeg without losing quality?
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'