Skip to content

Fix initial numbering of frames in TTML to SRT converter#12671

Merged
TobiGr merged 1 commit intoTeamNewPipe:devfrom
TransZAllen:SRT_numbering
Oct 1, 2025
Merged

Fix initial numbering of frames in TTML to SRT converter#12671
TobiGr merged 1 commit intoTeamNewPipe:devfrom
TransZAllen:SRT_numbering

Conversation

@TransZAllen
Copy link
Contributor

@TransZAllen TransZAllen commented Sep 29, 2025

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

This PR fixes the numbering in .srt subtitle files generated from YouTube streams.
Previously, numbering started at 0, which is accepted by most players but does not comply with the SubRip specification. Now numbering starts at 1, ensuring strict compliance.

Subtitles are numbered sequentially, starting at 1.

  • Observed behavior: numbering started at 0.
  • Tested players:
    • mpv 0.37.0 ✅ works with 0
    • VLC 3.0.20 ✅ works with 0, even -1
    • MPlayer 1.5 ✅ works with 0
    • Totem 43.0 ✅ works with 0
  • Even though playback worked fine, some stricter tools may reject such files.

Why not i++ or ++i?

Every time I see i++ or ++i, I need to pause and think:

  • Is it “use first, then increment” (i++) or “increment first, then use” (++i)?
  • Even after I've written the code, two or three days later, when I look at the modified code, I still find myself thinking about the same issue.

To avoid this confusion, I prefer splitting the current line writeString(String.valueOf(frameIndex++)); into two lines: one to use current value of frameIndex, and the other to increment it.

Before/After Screenshots/Screen Record

a51x:/storage/emulated/0/Newpipe $ cat Bear\ Family\ Searches\ for\ Water\ _\ Wild\ Mexico\ _\ BBC\ Earth-en.srt
0
00:00:00,640 --> 00:00:07,160
This mother has three young cubs just 8

1
00:00:03,840 --> 00:00:07,160
months old.

2
00:00:08,520 --> 00:00:22,899
[Music]

3
00:00:24,560 --> 00:00:29,039
It's autumn and the family needs to

4
00:00:27,119 --> 00:00:32,039
flatten up before the winter

  • After: Now numbering start at 1
start 1  2025-09-29 18-32-00

Fixes the following issue(s)

Fixes #12670

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.

Due diligence

…e#12670)

- The SubRip (.srt) specification requires subtitle numbering to begin from 1.
- Please refer to https://en.wikipedia.org/wiki/SubRip
- Previously numbering started from 0, which is accepted by most
  players (tested on mpv, VLC, MPlayer, Totem) but not strictly compliant.
@github-actions github-actions bot added the size/small PRs with less than 50 changed lines label Sep 29, 2025
@TransZAllen TransZAllen changed the title [YouTube] Fix SRT numbering to start at 1 (issue #12670) [bug][YouTube] Fix SRT numbering to start at 1 (issue #12670) Sep 29, 2025
@AudricV AudricV added bug Issue is related to a bug downloader Issue is related to the downloader labels Sep 29, 2025
@AudricV AudricV changed the title [bug][YouTube] Fix SRT numbering to start at 1 (issue #12670) Fix initial numbering of frames in TTML to SRT converter Sep 29, 2025
Copy link
Contributor

@TobiGr TobiGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

throws IOException {
writeString(String.valueOf(frameIndex++));
writeString(String.valueOf(frameIndex));
frameIndex += 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use this because is just a write / increment and no read. Thus there is only little room for confusion.

Suggested change
frameIndex += 1;
frameIndex++;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion.
I agree that frameIndex++ works fine here and avoids confusion.

My earlier comment about i++ / ++i was only about using them directly inside something like writeString(String.valueOf(...)), which can indeed be confusing.

Between frameIndex += 1, frameIndex++, and frameIndex = frameIndex + 1, I personally prefer += 1 because it’s very explicit and leaves no room for overthinking.

I’m fine with switching to frameIndex++ if the team prefers, but my preference would be to keep += 1 if that’s acceptable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you’d like me to change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm fine with either

@TobiGr TobiGr merged commit c25f83d into TeamNewPipe:dev Oct 1, 2025
18 checks passed
@TransZAllen TransZAllen deleted the SRT_numbering branch November 30, 2025 08:32
@TobiGr TobiGr mentioned this pull request Dec 21, 2025
4 tasks
@TobiGr TobiGr added the subtitles Related to displaying, converting or saving subtitles or captions. label Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue is related to a bug downloader Issue is related to the downloader size/small PRs with less than 50 changed lines subtitles Related to displaying, converting or saving subtitles or captions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[YouTube] SRT numbering should start at 1 (currently starts at 0)

4 participants