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?

1 Answer 1



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'

  • Thank you! Is there a way to replace the Real time:00:06:31:04 with Real time: 00h 06m 31s (so there is a space after time:, no more : and frames (latests digits) are removed)?
    – m30l
    Commented Apr 3, 2018 at 16:57
  • Also, is possible to center the timecode (horizontally) without checking how wide is the video (so I don't use 1920/2 = 960). Maybe something like 50% (similar to HTML/CSS 50%)?
    – m30l
    Commented Apr 3, 2018 at 17:01
  • For horizontally centering, add x='(W-tw)/2'. A custom string can be done but it's a bit involved so I'll add it tomorrow.
    – Gyan
    Commented Apr 3, 2018 at 17:09
  • Thanks! I've tested the code and there's an issue with the text size of the timecode, if the video is very big (2K/4K), the timecode is very small. Is there a way to make the timecode 20% of the width of the video?
    – m30l
    Commented Apr 3, 2018 at 17:48
  • Not directly. Add fontsize=H/10 where H is video height. Test and see what expression results in the required footprint.
    – Gyan
    Commented Apr 3, 2018 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.