Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions stl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
39 changes: 39 additions & 0 deletions stl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}