1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-12-17 13:48:05 +00:00

Merge pull request #12671 from TransZAllen/SRT_numbering

Fix initial numbering of frames in TTML to SRT converter
This commit is contained in:
Tobi
2025-10-01 02:42:33 -07:00
committed by GitHub

View File

@@ -24,7 +24,11 @@ public class SrtFromTtmlWriter {
private final boolean ignoreEmptyFrames; private final boolean ignoreEmptyFrames;
private final Charset charset = StandardCharsets.UTF_8; private final Charset charset = StandardCharsets.UTF_8;
private int frameIndex = 0; // According to the SubRip (.srt) specification, subtitle
// numbering must start from 1.
// Some players accept 0 or even negative indices,
// but to ensure compliance we start at 1.
private int frameIndex = 1;
public SrtFromTtmlWriter(final SharpStream out, final boolean ignoreEmptyFrames) { public SrtFromTtmlWriter(final SharpStream out, final boolean ignoreEmptyFrames) {
this.out = out; this.out = out;
@@ -39,7 +43,8 @@ public class SrtFromTtmlWriter {
private void writeFrame(final String begin, final String end, final StringBuilder text) private void writeFrame(final String begin, final String end, final StringBuilder text)
throws IOException { throws IOException {
writeString(String.valueOf(frameIndex++)); writeString(String.valueOf(frameIndex));
frameIndex += 1;
writeString(NEW_LINE); writeString(NEW_LINE);
writeString(begin); writeString(begin);
writeString(" --> "); writeString(" --> ");