diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-10-04 16:53:56 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-10-04 17:43:24 +0300 |
commit | c919ce3aa9684b88849d5628e629c3a1ac87e40b (patch) | |
tree | e2bf241e5f7de13b4d8a85c28e9c7e91dbfa9e9c /source/blender/blenlib/intern/timecode.c | |
parent | 123b64f818da77dfaf3783d88f5c6be8bbd99a87 (diff) |
Fix (unreported) broken export of timecodes in SubRip VSE exporter.
Would write 1.04 seconds as `00:00:01,40` instead of `00:00:01,040`...
Anyway, we already have BLI API for timecodes, much better to add
SubRip timecode format there, heavily simplifies code.
To be backported to final 2.76.
Diffstat (limited to 'source/blender/blenlib/intern/timecode.c')
-rw-r--r-- | source/blender/blenlib/intern/timecode.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/timecode.c b/source/blender/blenlib/intern/timecode.c index 4ae9249ec0d..e755a7ae52c 100644 --- a/source/blender/blenlib/intern/timecode.c +++ b/source/blender/blenlib/intern/timecode.c @@ -72,20 +72,20 @@ size_t BLI_timecode_string_from_time( time = -time; } - if (time >= 3600) { + if (time >= 3600.0f) { /* hours */ /* XXX should we only display a single digit for hours since clips are * VERY UNLIKELY to be more than 1-2 hours max? However, that would * go against conventions... */ hours = (int)time / 3600; - time = (float)fmod(time, 3600); + time = fmodf(time, 3600); } - if (time >= 60) { + if (time >= 60.0f) { /* minutes */ minutes = (int)time / 60; - time = (float)fmod(time, 60); + time = fmodf(time, 60); } if (power <= 0) { @@ -163,6 +163,18 @@ size_t BLI_timecode_string_from_time( } break; } + case USER_TIMECODE_SUBRIP: + { + /* SubRip, like SMPTE milliseconds but seconds and milliseconds are separated by a comma, not a dot... */ + + /* precision of decimal part */ + const int ms_dp = (power <= 0) ? (1 - power) : 1; + const int ms = iroundf((time - (float)seconds) * 1000.0f); + + rlen = BLI_snprintf_rlen( + str, maxncpy, "%s%02d:%02d:%02d,%0*d", neg, hours, minutes, seconds, ms_dp, ms); + break; + } case USER_TIMECODE_SECONDS_ONLY: { /* only show the original seconds display */ |