Skip to content

Conversation

@gaurav02081
Copy link

@gaurav02081 gaurav02081 commented Dec 19, 2025

[FIX]

In raising this pull request, I confirm the following (please check boxes):

  • [ ✔] I have read and understood the contributors guide.
  • [ ✔] I have checked that another pull request for this purpose does not exist.
  • [ ✔] I have considered, and confirmed that this submission will be valuable to others.
  • [✔ ] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • [✔ ] I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • [ ✔] I am an active contributor to CCExtractor.

[FIX] -out=spupng with EIA608/teletext: offset values in XML may be not correct #893

The issue occurs because the offsets were hardcoded for a 544×390 subtitle image centered on a 720×480 NTSC screen, while the text-to-PNG renderer generates PNGs with different (dynamic) dimensions (e.g. 600px wide and variable height). This results in visibly misaligned subtitles, especially for Teletext (PAL) sources.

This PR removes the hardcoded NTSC assumptions and calculates SPUPNG offsets dynamically based on the actual rendered PNG geometry and the target screen resolution.

Key changes =>

  1. Store the real PNG dimensions (img_w, img_h) in spupng_t

2 .Introduce an is_pal flag in encoder_ctx to distinguish PAL (576 lines) vs NTSC (480 lines)

  1. Capture final canvas dimensions during text-to-PNG rendering

4.Add a helper to compute centered xOffset / yOffset dynamically

  1. Enforce even yOffset to prevent interlacing flicker on DVD/SPU

  2. Apply the new logic only to the text-to-SPUPNG pipeline, leaving the bitmap path unchanged

  3. This aligns the text-based SPUPNG output with the already-correct bitmap SPUPNG behavior.

So ,Subtitles are correctly positioned regardless of PNG width/height (PNG size decides the offset — not hardcoded values.).

in the given image i have drawn the flow of this fix .
IMG_1181

@cfsmp3
Copy link
Contributor

cfsmp3 commented Dec 19, 2025

What video file did you use to test this?

…oder

- Introduced a forward declaration for .
- Updated  to calculate and set image dimensions before writing XML tags.
- Adjusted offset calculations based on screen size for better alignment of subtitles.
- Improved handling of the opening XML tag based on subtitle data presence.
@gaurav02081
Copy link
Author

Testing was done mostly using tests/02-BBC2.No.Such.Thing.As.News.ts, which is a BBC PAL, 720

I manually checked the generated PNG size and the xoffset/yoffset information within the XML file, and I found that it didn't conform to the formula for centering, resulting in this patch.

This PR addresses the problem by -

correcting the offset calculation order (offsets are now calculated after PNG generation),

the removal of NTSC hardcoded numbers,

applying the proper centering formula, even alignment.

During testing, I also noticed that format detection in Teletext may not be represented in the encoder context (in_fileformat / is_pal) at SPUPNG. I’ve chosen to keep this PR just on the offset logic, rather than making changes to format detection.

The NTSC/EIA-608 part of the pipeline remains the same; the current Usa.ts functionality breaks on my Mac environment with respect to font support, not offset logic.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit e3b0def...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 6/7
DVD 3/3
DVR-MS 2/2
General 24/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 80/86
Teletext 21/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2...
  • ccextractor --autoprogram --out=ttxt --latin1 1974a299f0...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65...
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b...
  • ccextractor --out=spupng c83f765c66...
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

@gaurav02081
Copy link
Author

#update

Verification (PAL Teletext)

Tested with:

  • tests/02-BBC2.No.Such.Thing.As.News.ts (BBC PAL Teletext, 720×576)

Verified results:

  • sub0001.png (720×36): yoffset = 270 → (576 − 36) / 2
  • sub0007.png (720×72): yoffset = 252 → (576 − 72) / 2

note = had to set default to pal for this test temporarily .(this PR remains focused on offset logic)

This confirms the centering logic works correctly when PAL is used.

image

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit d573548...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 85/86
Teletext 21/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=ttxt --latin1 1974a299f0..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --xdsdebug --out=srt c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants