Skip to content

Commit b2c1bab

Browse files
Feat(rust): Implement WebVTT-specific timestamp format and layout anchor (#2135)
* Feat(rust): Implement WebVTT-specific timestamp format and layout anchor * style: apply rustfmt to g608.rs * fix(rust): use WebVTT-spec dot separator for milliseconds in timestamp line
1 parent a44db9f commit b2c1bab

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/rust/src/encoder/g608.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,20 @@ pub fn write_cc_buffer_as_g608(data: &eia608_screen, context: &mut encoder_ctx)
191191
}
192192

193193
// Create timeline string for timestamps
194-
let timestamp_line = format!(
195-
"{h1:02}:{m1:02}:{s1:02},{ms1:03} --> {h2:02}:{m2:02}:{s2:02},{ms2:03}{encoded_clrf}"
196-
);
194+
let is_webvtt = context.write_format == crate::bindings::ccx_output_format::CCX_OF_WEBVTT;
195+
196+
let timestamp_line = if is_webvtt {
197+
// WebVTT Standard requires dots instead of commas for milliseconds
198+
// and supports trailing settings (e.g., vertical text direction, alignment)
199+
format!(
200+
"{h1:02}:{m1:02}:{s1:02}.{ms1:03} --> {h2:02}:{m2:02}:{s2:02}.{ms2:03}{encoded_clrf}"
201+
)
202+
} else {
203+
// Legacy SRT Standard requires commas
204+
format!(
205+
"{h1:02}:{m1:02}:{s1:02},{ms1:03} --> {h2:02}:{m2:02}:{s2:02},{ms2:03}{encoded_clrf}"
206+
)
207+
};
197208

198209
// Encode and write timestamp line
199210
let used = encode_line(context, buffer_slice, timestamp_line.as_bytes());

0 commit comments

Comments
 (0)