I use FFMPEG to print a frame counter on my videos, but I have two issues:
- The text stutters
- I'd like to have the possibility to have the number zero-padded (I.E. write
001
002
003
instead of1
2
3
).
Code:
@echo off
:again
cd /D %~p1
ffmpeg ^
-i "%~nx1" ^
-vf "drawtext=fontfile=arialbd.ttf: text='Frame \: %%{n}': start_number=1: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: fontsize=40: box=1: boxcolor=black@0.4: boxborderw=8" ^
-c:a copy ^
"%~p1%~n1_framenumbered.mov"
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 10 seconds.[0m
timeout /t 10
Solutions:
- use `text='Frame : %{eif:n:d:3}' to get the zero-padded frame count (thanks to this answer)
- use a monospace font (courrier new is common on Windows)
- the script was failing to load the font, use the full path instead but without the drive (thanks to this answer):
- Do:
/Windows/Fonts/courbd.ttf
- Don't
C:/Windows/Fonts/courbd.ttf
nor use\
- Do: