I'm trying to convert a small part of a screen recording video into a GIF with ffmpeg. I would like to add a seconds counter on it as the frame rate of the GIF file is reduced, so I can guess the time passing from the counter.
Normally, assuming to start at 43 seconds and cutting after 33 seconds, the example video would have been encoded to GIF with:
ffmpeg -i in.mp4 -vf "scale=300:-1,fps=5,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -ss 43 -t 33 out.gif
To print the timecode, I add the following after fps=5,:
drawtext=text='%{pts\:hms}':font='Arial':fontcolor=red:fontsize=14:x=(w-text_w)/2:y=(h-text_h-6),
Doing so, prints a timecode on the output that starts from 00:00:43.000, not from zero. Similarly the timecode option:
drawtext=text='':font='Arial':fontcolor=red:fontsize=14:x=(w-text_w)/2:y=(h-text_h-6):timecode='00\:00\:00\:00':timecode_rate=5,
will ouput 00:00:43:0. There doesn't seem to have a way to use the "output" timecode (that starts from 0); also, I would like to have the seconds only.
How can I do that?
Formatting as seconds
Apparently a way to do it is using the frame number, like so:
that outputs 00, 01, etc. but the values have to be typed directly (hence not calculated by ffmpeg!). The
%{eif\:n/5-43\:d\:2}part is composed like so:nis the current frame number5is the number of frames per seconds (wasfps=5above)43is the number of seconds to subtract (from the start time-ss 43)2means a two-digit output, so 00 instead of 0Formatting as mm:ss
To display minutes and seconds, or if the duration of the video is greater than 60 seconds and you want to display e.g. 83 seconds like 01:23, use this syntax:
Explanation:
%{eif\:(n/5-43)/60\:d\:2}nis the current frame number5is the number of frames per seconds (wasfps=5above)43is the number of seconds to subtract (from the start time-ss 43)/60calculates the minutes from the seconds, e.g. 83 / 60 = 12format as a two-digit output, so 00 instead of 0\::(has to be escaped)%{eif\:mod((n/5-43)\,60)\:d\:2}modcalculates the remainder (see below)nis the current frame number5is the number of frames per seconds (wasfps=5above)43is the number of seconds to subtract (from the start time-ss 43)\,60calculates remainder (seconds) from the minutes, e.g. 83 mod 60 = 232format as a two-digit output, so 00 instead of 0