fix(subtitles): exported cue times keep their milliseconds - #2074
fix(subtitles): exported cue times keep their milliseconds#2074kevin9327 wants to merge 3 commits into
Conversation
The SRT/VTT formatters in dub_export and openai_compat truncated (seconds % 1) * 1000. Most decimal times are not exact in binary (2.3 is 2.29999...), so a cue imported as 00:00:02,300 exported as 00:00:02,299: every such cue moved a millisecond early in the /dub/srt and /dub/vtt downloads, burned-in subtitles, and /v1/audio/transcriptions srt/vtt. All four now call srt_parser.format_cue_timestamp, which rounds the whole value to milliseconds once and splits it, so 59.9996 carries to 00:01:00,000 rather than printing ",1000" -- the same round-then-divmod shape karaoke_ass._ass_time already uses. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe change centralizes subtitle timestamp formatting, adds millisecond rounding with carry-over handling, updates SRT and VTT export paths, and adds coverage for direct and end-to-end outputs. ChangesSubtitle timestamp formatting
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to The timestamp correction consistently rounds and normalizes SRT and VTT cue times, with coverage for formatter output and subtitle-download behavior. No merge-blocking risk was identified. 🚥 Pre-merge checks | ✅ 7 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (7 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files. (1 skipped: 1 unsupported.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The PR appears safe to merge; no concrete correctness, security, data-risk, or repository-rule violation remains.
|
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Summary
Exported subtitle cue times lost a millisecond. The SRT/VTT formatters truncated
(seconds % 1) * 1000, and most decimal times are not exact in binary (2.3is2.2999…), so a cue imported as00:00:02,300 --> 00:00:04,100came back from Dub → Export → SRT/VTT as00:00:02,299 --> 00:00:04,099. Every such cue moved 1 ms early; import-then-export of an untouched subtitle file no longer round-tripped.The same two formatters exist four times, all truncating:
dub_export._format_srt_time—/dub/srtdownload and the SRT burned into video exports (_write_burn_srt)dub_export._format_vtt_time—/dub/vttopenai_compat._format_ts_srt/_format_ts_vtt—POST /v1/audio/transcriptionswithresponse_format=srt|vttChanges
services/srt_parser.format_cue_timestamp(seconds, ms_separator): rounds the whole value to milliseconds once, then splits it withdivmod— the same shapekaraoke_ass._ass_timealready uses for ASS centiseconds.59.9996carries to00:01:00,000instead of needing a,1000special case.services/file, sodocs/STRUCTURE.md's service count is unchanged.Type
Testing
tests/test_subtitle_timestamp_rounding.py: all four formatters on0.0, 2.3, 4.1, 70.7, 3661.123, 59.9996; an SRT parsed byparse_srtand downloaded throughGET /dub/srtandGET /dub/vtt; and the burn-in SRT file.8 failed, 6 passed— e.g.At index 0 diff: '00:00:02,299 --> 00:00:04,099' != '00:00:02,300 --> 00:00:04,100'andassert '00:00:59,999' == '00:01:00,000'. After: all pass.HF_HUB_OFFLINE=1: the new file plustest_dub_subtitles_309.py,test_dub_per_lang_subtitles.py,test_smart_fit_export.py,test_api.py(its existing_format_srt_time/_format_vtt_timecases),test_srt_parser.py,test_structure_doc.py,test_no_hardcoded_cjk.py,test_changelog_style.py→145 passed, 7 skipped, 1 xfailed.Checklist
tests/fixtures/omnivoice_data/still loads green on thesmoke-matrixCI job (macOS + Windows + Linux)🤖 Generated with Claude Code
Adds shared millisecond rounding for subtitle timestamps across SRT and VTT exports, preventing binary floating-point values from exporting cues 1 ms early. The helper handles carry-over, including
59.9996becoming00:01:00,000, and tests cover all affected export paths. Risk is limited to timestamp formatting; review carry-over behavior and separator handling.