diff mbox series

[FFmpeg-devel,2/2] avutil/timecode: use timecode fps for number of frame digits

Message ID 20220410181200.3181-2-cus@passwd.hu
State Accepted
Commit 0d666200d30be1643aa46fa67073f257c11937ac
Headers show
Series [FFmpeg-devel,1/2] avformat/mov: fix timecode with high frame rate content | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Marton Balint April 10, 2022, 6:12 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavutil/timecode.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index a37d725fc7..b93f05b4b8 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -104,7 +104,7 @@  char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
 {
     int fps = tc->fps;
     int drop = tc->flags & AV_TIMECODE_FLAG_DROPFRAME;
-    int hh, mm, ss, ff, neg = 0;
+    int hh, mm, ss, ff, ff_len, neg = 0;
 
     framenum += tc->start;
     if (drop)
@@ -119,9 +119,10 @@  char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
     hh = framenum / (fps*3600LL);
     if (tc->flags & AV_TIMECODE_FLAG_24HOURSMAX)
         hh = hh % 24;
-    snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%02d",
+    ff_len = fps > 10000 ? 5 : fps > 1000 ? 4 : fps > 100 ? 3 : fps > 10 ? 2 : 1;
+    snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%0*d",
              neg ? "-" : "",
-             hh, mm, ss, drop ? ';' : ':', ff);
+             hh, mm, ss, drop ? ';' : ':', ff_len, ff);
     return buf;
 }