1

So when specifying a video-filter to display current video-time in 'hms' layout, the filter appends a millisecond value after the seconds-field. I want to eliminate the milliseconds portion.

So far, my invoked cmd looks like:

ffplay myfile.mp4 -vf "drawtext=text='%{pts \: hms}':fontsize=20:fontcolor=white: box=1: boxcolor=black"

i.e. instead of: 00:00:01.001 I want just 00:00:01 to display.

[One might have thought that there would exist an 'hmsm' for the former, and that 'hms' would be the latter, but it just doesn't work that way.] (sigh)

Leon
  • 31,443
  • 4
  • 72
  • 97
David
  • 2,253
  • 5
  • 23
  • 29

1 Answers1

4

According to the documentation:

hms stands for a formatted [-]HH:MM:SS.mmm timestamp with millisecond accuracy.

And there's no way to customize this timestamp format. At least not for the hms format.
The same documentation:

If the format is set to localtime or gmtime, a third argument may be supplied: a strftime() format string. By default, YYYY-MM-DD HH:MM:SS format will be used.

So text='%{pts\:gmtime}' without any additional arguments puts out 1970-01-01 00:00:00 (Unix epoch).

To have it put out 00:00:00 set the 2nd argument to 0 and the 3rd to %H:%M:%S.

As the pts function can take up to 3 arguments, make sure you escape the colons twice on Windows and three times on Unix to prevent %M and %S from being interpreted as a possible 4th or 5th argument.

Windows:

ffplay -vf "drawtext=text='%{pts\:gmtime\:0\:%H\\\:%M\\\:%S}':x=1:y=1:fontsize=20:fontcolor=white:box=1:boxcolor=black:boxborderw=2" myfile.mp4

Unix:

ffplay -vf "drawtext=text='%{pts\:gmtime\:0\:%H\\\\\:%M\\\\\:%S}':x=1:y=1:fontsize=20:fontcolor=white:box=1:boxcolor=black:boxborderw=2" myfile.mp4

Compared to your initial command I've also added :x=1:y=1 and :boxborderw=2. It adds a small border around the text and positions the text nicely centered.
It's a matter of taste of course. You can remove it if you don't like it.

Reino
  • 3,203
  • 1
  • 13
  • 21
  • Thx for all your info Reino. Unfortunately, that doesn't resolve my issue. (That said, tho, you can have the bounty...if I can find the button where I grant it to you). I've concluded that what I'm trying to do, just isn't possible. (Those 'gmtime' examples aren't applicable to me, as I am not trying to display any of those 'time-of-day' related items, but rather the 'timestamp' object that is the elapsed time value of a video...i.e. the current-position (before the duration-time occurs). – David May 10 '21 at 18:19
  • @Dave `text='%{pts\:gmtime\:0\:%H\\\:%M\\\:%S}'` should give you exactly that; the current elapsed time formated as `HH:MM:SS`. Or do I not understand what you're actually looking for? – Reino May 10 '21 at 20:44