From 8110fe56598015d2c31653c6c6a384db7e9557ba Mon Sep 17 00:00:00 2001 From: David Le Corfec Date: Wed, 14 Jan 2026 22:27:35 +0100 Subject: [PATCH 1/2] fix missing STL25.01 in GSI block when converting TTML to STL --- stl.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stl.go b/stl.go index a9f4498..f7f6659 100644 --- a/stl.go +++ b/stl.go @@ -378,10 +378,14 @@ func newGSIBlock(s Subtitles) (g *gsiBlock) { g.creationDate = *s.Metadata.STLCreationDate } g.countryOfOrigin = s.Metadata.STLCountryOfOrigin - g.displayStandardCode = s.Metadata.STLDisplayStandardCode + if s.Metadata.STLDisplayStandardCode != "" { + g.displayStandardCode = s.Metadata.STLDisplayStandardCode + } g.editorContactDetails = s.Metadata.STLEditorContactDetails g.editorName = s.Metadata.STLEditorName - g.framerate = s.Metadata.Framerate + if s.Metadata.Framerate > 0 { + g.framerate = s.Metadata.Framerate + } if v, ok := stlLanguageMapping.GetInverse(s.Metadata.Language); ok { g.languageCode = v.(string) } From ed2d689946963f78d1a6c3e7087be6b1d3b99345 Mon Sep 17 00:00:00 2001 From: David Le Corfec Date: Thu, 15 Jan 2026 19:19:11 +0100 Subject: [PATCH 2/2] add test for ttml to stl gsi block --- stl_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/stl_test.go b/stl_test.go index 5109c70..8eba755 100644 --- a/stl_test.go +++ b/stl_test.go @@ -96,3 +96,42 @@ func TestIgnoreTimecodeStartOfProgramme(t *testing.T) { firstStart := 99 * time.Second assert.Equal(t, firstStart, s.Items[0].StartAt, "first start at 0") } + +func TestTTMLToSTLGSIBlock(t *testing.T) { + // Test that TTML to STL conversion includes correct disk format code and display standard code + // This verifies the fix for the bug where "STL25.01" was missing from the GSI block + // when converting from TTML files that have no framerate metadata + + // Open TTML file + s, err := astisub.OpenFile("./testdata/example-in.ttml") + assert.NoError(t, err) + assert.NotNil(t, s) + + // TTML files typically don't have STL-specific metadata + assert.Empty(t, s.Metadata.STLDisplayStandardCode, "TTML should not have STL-specific display standard code") + + // Write to STL + w := &bytes.Buffer{} + err = s.WriteToSTL(w) + assert.NoError(t, err) + + stlData := w.Bytes() + assert.True(t, len(stlData) >= 1024, "STL file should have at least GSI block (1024 bytes)") + + // Check GSI block header + // Bytes 0-2: Code page number (should be "850") + codePageNumber := string(stlData[0:3]) + assert.Equal(t, "850", codePageNumber, "Code page number should be '850'") + + // Bytes 3-10: Disk format code (should be "STL25.01" for 25fps, not spaces) + diskFormatCode := string(stlData[3:11]) + assert.NotEqual(t, " ", diskFormatCode, + "Disk format code should not be empty spaces (this was the bug)") + assert.True(t, diskFormatCode == "STL25.01" || diskFormatCode == "STL30.01", + "Disk format code should be 'STL25.01' or 'STL30.01', got '%s'", diskFormatCode) + + // Byte 11: Display standard code (should be "1" for Level 1 Teletext by default) + displayStandardCode := string(stlData[11:12]) + assert.True(t, displayStandardCode == "0" || displayStandardCode == "1" || displayStandardCode == "2", + "Display standard code should be '0', '1', or '2', got '%s'", displayStandardCode) +}