stl

package
v0.0.0-...-ed40b9f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 12 Imported by: 0

README

go-stl

go-stl is a library made to decode, validate and encode EBU-STL subtitles files.

Documentation

Index

Constants

View Source
const GSIBlockSize = 1024

GSIBlockSize is the size in bytes of the GSI block in a STL file.

View Source
const TTIBlockSize = 128

TTIBlockSize is the size in bytes of a TTI block in a STL file.

Variables

View Source
var (
	ErrInvalidGSIIntValue      = errors.New("invalid GSI int value")
	ErrEmptyGSIIntValue        = errors.New("empty GSI int value")
	ErrInvalidGSIByteValue     = errors.New("invalid GSI byte value")
	ErrEmptyGSIByteValue       = errors.New("empty GSI byte value")
	ErrInvalidGSIHexValue      = errors.New("invalid GSI hex value")
	ErrEmptyGSIHexValue        = errors.New("empty GSI hex value")
	ErrInvalidGSIStringValue   = errors.New("invalid GSI string value")
	ErrEmptyGSIStringValue     = errors.New("empty GSI string value")
	ErrUnsupportedGSICodePage  = errors.New("unsupported code page")
	ErrInvalidGSIDateValue     = errors.New("invalid GSI date value")
	ErrEmptyGSIDateValue       = errors.New("empty GSI date value")
	ErrInvalidGSITimecodeValue = errors.New("invalid GSI timecode value")
	ErrEmptyGSITimecodeValue   = errors.New("empty GSI timecode value")
)
View Source
var (
	ErrUnknown = errors.New("unknown error")

	ErrNoTTIBlocks            = errors.New("no TTI blocks")
	ErrTTIBlocksCountMismatch = errors.New("TTI blocks count mismatch")
	ErrTCFFirstTCIMismatch    = errors.New("first TTI timecode mismatch")

	ErrEBNNotConsecutive = errors.New("EBN not consecutive")
	ErrSNNotConsecutive  = errors.New("SN not consecutive")
	ErrSGNNotConsecutive = errors.New("SGN not consecutive")

	ErrNoFirstSubtitleInNewGroup = errors.New("no first subtitle in new group")

	ErrNonClosingEBNForLastSubtitle = errors.New("non closing EBN for last subtitle")

	ErrCSNotNoneOrFirst        = errors.New("CS not none or first")
	ErrCSNotIntermediateOrLast = errors.New("CS not intermediate or last")
	ErrCSNotNoneOrLast         = errors.New("CS not none or last")

	ErrSubtitleCountMismatch = errors.New("subtitle count mismatch")
	ErrGroupCountMismatch    = errors.New("group count mismatch")
)
View Source
var (
	ErrUnsupportedCPN               = errors.New("unsupported CPN")
	ErrUnsupportedDFC               = errors.New("unsupported DFC")
	ErrUnsupportedFramerate         = errors.New("unsupported framerate")
	ErrUnsupportedDSC               = errors.New("unsupported DSC")
	ErrUnsupportedCCT               = errors.New("unsupported CCT")
	ErrUnsupportedLC                = errors.New("unsupported LC")
	ErrEmptyOPT                     = errors.New("empty OPT")
	ErrEmptyOET                     = errors.New("empty OET")
	ErrEmptyTPT                     = errors.New("empty TPT")
	ErrEmptyTET                     = errors.New("empty TET")
	ErrEmptyTN                      = errors.New("empty TN")
	ErrEmptyTCD                     = errors.New("empty TCD")
	ErrEmptySLR                     = errors.New("empty SLR")
	ErrEmptyCD                      = errors.New("empty CD")
	ErrEmptyCR                      = errors.New("empty CR")
	ErrEmptyRD                      = errors.New("empty RD")
	ErrCDGreaterThanRD              = errors.New("CD greater than RD")
	ErrUnsupportedRN                = errors.New("unsupported RN")
	ErrUnsupportedTNB               = errors.New("unsupported TNB")
	ErrUnsupportedTNS               = errors.New("unsupported TNS")
	ErrUnsupportedTNG               = errors.New("unsupported TNG")
	ErrUnsupportedMNC               = errors.New("unsupported MNC")
	ErrUnsupportedMNRTeletext       = errors.New("unsupported MNR (teletext)")
	ErrUnsupportedMNROpenSubtitling = errors.New("unsupported MNR (open subtitling)")
	ErrUnsupportedTCS               = errors.New("unsupported TCS")
	ErrEmptyTCP                     = errors.New("empty TCP")
	ErrEmptyTCF                     = errors.New("empty TCF")
	ErrTCPTCFOrder                  = errors.New("TCP greater than TCF")
	ErrInvalidTimecodes             = errors.New("invalid timecodes")
	ErrUnsupportedTND               = errors.New("unsupported TND")
	ErrUnsupportedDSN               = errors.New("unsupported DSN")
	ErrEmptyCO                      = errors.New("empty CO")
	ErrEmptyPUB                     = errors.New("empty PUB")
	ErrEmptyEN                      = errors.New("empty EN")
	ErrEmptyECD                     = errors.New("empty ECD")
)
View Source
var (
	ErrInvalidFramerate = errors.New("invalid framerate")

	ErrUnsupportedSGN              = errors.New("unsupported SGN")
	ErrUnsupportedSN               = errors.New("unsupported SN")
	ErrLastEBNNotTerminatedBySpace = errors.New("last EBN not terminated by space")
	ErrReservedEBNRange            = errors.New("reserved EBN range")
	ErrUnsupportedCS               = errors.New("unsupported CS")
	ErrInvalidTCI                  = errors.New("invalid TCI")
	ErrInvalidTCO                  = errors.New("invalid TCO")
	ErrInvalidTCITCOOrder          = errors.New("invalid TCI/TCO order")
	ErrUnsupportedVPTeletext       = errors.New("unsupported VP (teletext)")
	ErrUnsupportedVPOpenSubtitling = errors.New("unsupported VP (for open subtitling)")
	ErrUnsupportedVPDSC            = errors.New("unsupported DSC, cannot use VP")
	ErrUnsupportedJC               = errors.New("unsupported JC")
	ErrUnsupportedCF               = errors.New("unsupported CF")
)
View Source
var CharacterCodeTableDecoders = map[CharacterCodeTable]TextDecoder{
	CharacterCodeTableLatin:         &ISO6937,
	CharacterCodeTableLatinCyrillic: &Charmap{charmap.ISO8859_5},
	CharacterCodeTableLatinArabic:   &Charmap{charmap.ISO8859_6},
	CharacterCodeTableLatinGreek:    &Charmap{charmap.ISO8859_7},
	CharacterCodeTableLatinHebrew:   &Charmap{charmap.ISO8859_8},
}
View Source
var CharacterCodeTableEncoders = map[CharacterCodeTable]TextEncoder{
	CharacterCodeTableLatin:         &ISO6937,
	CharacterCodeTableLatinCyrillic: &Charmap{charmap.ISO8859_5},
	CharacterCodeTableLatinArabic:   &Charmap{charmap.ISO8859_6},
	CharacterCodeTableLatinGreek:    &Charmap{charmap.ISO8859_7},
	CharacterCodeTableLatinHebrew:   &Charmap{charmap.ISO8859_8},
}
View Source
var CodePageNumberDecoders = map[CodePageNumber]TextDecoder{
	CodePageNumberUnitedStates:   &Charmap{charmap.CodePage437},
	CodePageNumberMultiLingual:   &Charmap{charmap.CodePage850},
	CodePageNumberPortugal:       &Charmap{charmap.CodePage860},
	CodePageNumberCanadianFrench: &Charmap{charmap.CodePage863},
	CodePageNumberNordic:         &Charmap{charmap.CodePage865},
}
View Source
var CodePageNumberEncoders = map[CodePageNumber]TextEncoder{
	CodePageNumberUnitedStates:   &Charmap{charmap.CodePage437},
	CodePageNumberMultiLingual:   &Charmap{charmap.CodePage850},
	CodePageNumberPortugal:       &Charmap{charmap.CodePage860},
	CodePageNumberCanadianFrench: &Charmap{charmap.CodePage863},
	CodePageNumberNordic:         &Charmap{charmap.CodePage865},
}
View Source
var ISO6937 = iso6937{}

ISO6937 implements the ISO 6937 encoding. It implements the TextDecoder and TextEncoder interfaces.

Functions

func PrintGSI

func PrintGSI(gsi *GSIBlock)

func PrintTTI

func PrintTTI(tti *TTIBlock, cct CharacterCodeTable)

Types

type CharacterCodeTable

type CharacterCodeTable byte

CharacterCodeTable is the code used to represent the character code table used to define the text in the Text Field (TF) of the TTI blocks. Only "Latin" (0), "Latin/Cyrillic" (1), "Latin/Arabic" (2), "Latin/Greek" (3) and "Latin/Hebrew" (4) are supported values.

const (
	CharacterCodeTableInvalid       CharacterCodeTable = 0xFF
	CharacterCodeTableLatin         CharacterCodeTable = 0x00
	CharacterCodeTableLatinCyrillic CharacterCodeTable = 0x01
	CharacterCodeTableLatinArabic   CharacterCodeTable = 0x02
	CharacterCodeTableLatinGreek    CharacterCodeTable = 0x03
	CharacterCodeTableLatinHebrew   CharacterCodeTable = 0x04
)

func (CharacterCodeTable) String

func (cct CharacterCodeTable) String() string

String returns the string representation of CharacterCodeTable.

type Charmap

type Charmap struct {
	// contains filtered or unexported fields
}

Charmap is a wrapper around golang.org/x/text/encoding/charmap.Charmap It implements the TextDecoder and TextEncoder interfaces.

func (*Charmap) Decode

func (c *Charmap) Decode(b []byte) ([]byte, error)

Decode decodes b using the charmap.

func (*Charmap) Encode

func (c *Charmap) Encode(b []byte) ([]byte, error)

Encode encodes b using the charmap.

type CodePageNumber

type CodePageNumber int

CodePageNumber is the number of the code page used in the GSI block. Note: Other code pages may be used within a given national environment.

const (
	CodePageNumberInvalid        CodePageNumber = -1
	CodePageNumberUnitedStates   CodePageNumber = 437
	CodePageNumberMultiLingual   CodePageNumber = 850
	CodePageNumberPortugal       CodePageNumber = 860
	CodePageNumberCanadianFrench CodePageNumber = 863
	CodePageNumberNordic         CodePageNumber = 865
)

func (CodePageNumber) String

func (cpn CodePageNumber) String() string

String returns the string representation of CodePageNumber.

type CommentFlag

type CommentFlag byte

CommentFlag is used to indicate TTI blocks which contains text as translator's comments instead of subtitle data. Only "subtitle data" (0) and "translator's comments" (1) are supported.

const (
	CommentFlagInvalid            CommentFlag = 0xFF
	CommentFlagSubtitleData       CommentFlag = 0x00
	CommentFlagTranslatorComments CommentFlag = 0x01
)

func (CommentFlag) String

func (cf CommentFlag) String() string

String returns the string representation of CommentFlag.

type ControlCode

type ControlCode byte

ControlCode

const (
	ControlCodeItalicOn     ControlCode = 0x80
	ControlCodeItalicOff    ControlCode = 0x81
	ControlCodeUnderlineOn  ControlCode = 0x82
	ControlCodeUnderlineOff ControlCode = 0x83
	ControlCodeBoxingOn     ControlCode = 0x84
	ControlCodeBoxingOff    ControlCode = 0x85
	ControlCodeLineBreak    ControlCode = 0x8A
	ControlCodeUnusedSpace  ControlCode = 0x8F
)

func (ControlCode) String

func (cc ControlCode) String() string

String returns the string representation of ControlCode.

type CumulativeStatus

type CumulativeStatus byte

CumulativeStatus is indicating that a subtitle is part of a cumulative set of subtitles.

const (
	CumulativeStatusInvalid      CumulativeStatus = 0xFF
	CumulativeStatusNone         CumulativeStatus = 0x00
	CumulativeStatusFirst        CumulativeStatus = 0x01
	CumulativeStatusIntermediate CumulativeStatus = 0x02
	CumulativeStatusLast         CumulativeStatus = 0x03
)

func (CumulativeStatus) String

func (cs CumulativeStatus) String() string

String returns the string representation of CumulativeStatus.

type DecodeError

type DecodeError struct {
	EncodingError
}

DecodeError is an error that occurred during decoding. It extends EncodingError that carries the value that caused the error.

func (*DecodeError) Error

func (e *DecodeError) Error() string

Error returns the error message.

func (*DecodeError) Unwrap

func (e *DecodeError) Unwrap() error

Unwrap returns the underlying error.

type DiskFormatCode

type DiskFormatCode string

DiskFormatCode is the code used to represent the frame-rate of the data. Only "STL25.01" (25 fps) and "STL30.01" (30 fps) are supported values.

const (
	DiskFormatCodeInvalid DiskFormatCode = "        "
	DiskFormatCode25_01   DiskFormatCode = "STL25.01"
	DiskFormatCode30_01   DiskFormatCode = "STL30.01"
)

func (DiskFormatCode) String

func (dfc DiskFormatCode) String() string

String returns the string representation of DiskFormatCode.

type DisplayStandardCode

type DisplayStandardCode byte

DisplayStandardCode is the code used to represent the display mode. Only "Undefined" (blank), "Open Subtitling" (0), "Level-1 Teletext" (1) and "Level-2 Teletext" (2) are supported values.

const (
	DisplayStandardCodeBlank          DisplayStandardCode = 0xFF
	DisplayStandardCodeOpenSubtitling DisplayStandardCode = 0x00
	DisplayStandardCodeLevel1Teletext DisplayStandardCode = 0x01
	DisplayStandardCodeLevel2Teletext DisplayStandardCode = 0x02
)

func (DisplayStandardCode) String

func (dsc DisplayStandardCode) String() string

String returns the string representation of DisplayStandardCode.

type EncodeError

type EncodeError struct {
	EncodingError
}

EncodeError is an error that occurred during encoding. It extends EncodingError that carries the input buffer that caused the error.

func (*EncodeError) Error

func (e *EncodeError) Error() string

Error returns the error message.

func (*EncodeError) Unwrap

func (e *EncodeError) Unwrap() error

Unwrap returns the underlying error.

type EncodingError

type EncodingError struct {
	// contains filtered or unexported fields
}

EncodingError is an error that occurred during encoding or decoding. It carries the input buffer that caused the error. EncodingError implements the error and Unwrap interfaces.

func (*EncodingError) Error

func (e *EncodingError) Error() string

Error returns the error message.

func (*EncodingError) Input

func (e *EncodingError) Input() interface{}

Input returns the input buffer.

func (*EncodingError) Unwrap

func (e *EncodingError) Unwrap() error

Unwrap returns the underlying error.

type Field

type Field string

Filed represents a block field.

const FieldUnknown Field = "<unknown>" // Unknown field

type FieldError

type FieldError struct {
	// contains filtered or unexported fields
}

FieldError is an error that occurred on a field.

func (*FieldError) Error

func (e *FieldError) Error() string

Error returns the error message.

func (*FieldError) Field

func (e *FieldError) Field() Field

Field returns the concerned field.

func (*FieldError) Unwrap

func (e *FieldError) Unwrap() error

Unwrap returns the underlying error.

type File

type File struct {
	GSI *GSIBlock
	TTI []*TTIBlock
}

File is the representation of a STL file. The file comprises one General Subtitle Information (GSI) block and a number of Text and Timing Information (TTI) blocks.

func NewFile

func NewFile() *File

NewFile returns a new stl.File.

func (*File) Decode

func (f *File) Decode(r io.Reader) (warns []error, err error)

Decode reads and decodes the STL file from r.

func (*File) Encode

func (f *File) Encode(w io.Writer) error

Encode encodes and writes the STL file to w.

func (*File) Validate

func (f *File) Validate() ([]error, error)

Validate validates STL file. It returns a slice of warnings and an error if any. Warnings are returned for each field that is invalid, warnings can flagged as fatal if they are considered to be fatal to further file processing. An error is returned if a field is invalid and prevents validation of further fields.

type GSIBlock

type GSIBlock struct {
	CPN CodePageNumber      // Code Page Number
	DFC DiskFormatCode      // Disk Format Code
	DSC DisplayStandardCode // Display Standard Code
	CCT CharacterCodeTable  // Character Code Table number
	LC  LanguageCode        // Language Code
	OPT string              // Original Program Title
	OET string              // Original Episode Title
	TPT string              // Translated Program Title
	TET string              // Translated Episode Title
	TN  string              // Translator's Name
	TCD string              // Translator's Contact Details
	SLR string              // Subtitle List Reference Code
	CD  time.Time           // Creation Date
	RD  time.Time           // Revision Date
	RN  int                 // Revision Number
	TNB int                 // Total Number of Text and Timing Information (TTI) blocks
	TNS int                 // Total Number of Subtitles
	TNG int                 // Total Number of Subtitle Groups
	MNC int                 // Maximum Number of Displayable Characters in any text row
	MNR int                 // Maximum Number of Displayable Rows
	TCS TimeCodeStatus      // Time Code: Status
	TCP Timecode            // Time Code: Start-of-Program
	TCF Timecode            // Time Code: First In-Cue
	TND int                 // Total Number of Disks
	DSN int                 // Disk Sequence Number
	CO  string              // Country of Origin
	PUB string              // Publisher
	EN  string              // Editor's Name
	ECD string              // Editor's Contact
	UDA []byte              // User-Defined Area
}

GSIBlock is the General Subtitle Information (GSI) block representation.

func NewGSIBlock

func NewGSIBlock() *GSIBlock

NewGSIBlock returns a new GSI block.

func (*GSIBlock) Decode

func (gsi *GSIBlock) Decode(r io.Reader) ([]error, error)

Decode reads and decodes GSI block from reader. It returns a slice of warnings and an error if any. Warnings are returned for each field that is invalid and are not fatal. An error is returned if a fatal error occurs that prevents further decoding.

func (*GSIBlock) Encode

func (gsi *GSIBlock) Encode(w io.Writer) error

Encode encodes and writes GSI block to writer. An error is returned if a fatal error occurs that prevents further encoding.

func (*GSIBlock) Framerate

func (gsi *GSIBlock) Framerate() uint

Framerate returns the framerate of the GSI block (extracted from the Disk Format Code). The supported values are 25 and 30 fps. Returns -1 if Disk Format Code is unsupported.

func (*GSIBlock) Reset

func (gsi *GSIBlock) Reset()

Reset resets the GSI block to its default values.

func (*GSIBlock) Validate

func (gsi *GSIBlock) Validate() ([]error, error)

Validate validates GSI block. It returns a slice of warnings and an error if any. Warnings are returned for each field that is invalid, warnings can flagged as fatal if they are considered to be fatal to further file processing. An error is returned if a field is invalid and prevents validation of further fields.

type GSIError

type GSIError struct {
	FieldError
	// contains filtered or unexported fields
}

GSIError is an error that occurred on a GSI field. It extends FieldError that carries the concerned GSI field.

func (*GSIError) Error

func (e *GSIError) Error() string

Error returns the error message.

func (*GSIError) Field

func (e *GSIError) Field() GSIField

Field returns the concerned GSI field.

func (*GSIError) Unwrap

func (e *GSIError) Unwrap() error

Unwrap returns the underlying error.

type GSIField

type GSIField Field

GSIField represents a GSI block field. It extends Field.

const (
	GSIFieldCPN GSIField = "CPN" // Code Page Number
	GSIFieldDFC GSIField = "DSC" // Disk Format Code
	GSIFieldDSC GSIField = "DSC" // Display Standard Code
	GSIFieldCCT GSIField = "CCT" // Character Code Table number
	GSIFieldLC  GSIField = "LC"  // Language Code
	GSIFieldOPT GSIField = "OPT" // Original Program Title
	GSIFieldOET GSIField = "OET" // Original Episode Title
	GSIFieldTPT GSIField = "TPT" // Translated Program Title
	GSIFieldTET GSIField = "TET" // Translated Episode Title
	GSIFieldTN  GSIField = "TN"  // Translator's Name
	GSIFieldTCD GSIField = "TCD" // Translator's Contact Details
	GSIFieldSLR GSIField = "SLR" // Subtitle List Reference Code
	GSIFieldCD  GSIField = "CD"  // Creation Date
	GSIFieldRD  GSIField = "RD"  // Revision Date
	GSIFieldRN  GSIField = "RN"  // Revision Number
	GSIFieldTNB GSIField = "TNB" // Total Number of Text and Timing Information (TTI) blocks
	GSIFieldTNS GSIField = "TNS" // Total Number of Subtitles
	GSIFieldTNG GSIField = "TNG" // Total Number of Subtitle Groups
	GSIFieldMNC GSIField = "MNC" // Maximum Number of Displayable Characters in any text row
	GSIFieldMNR GSIField = "MNR" // Maximum Number of Displayable Rows
	GSIFieldTCS GSIField = "TCS" // Time Code: Status
	GSIFieldTCP GSIField = "TCP" // Time Code: Start-of-Program
	GSIFieldTCF GSIField = "TCF" // Time Code: First In-Cue
	GSIFieldTND GSIField = "TND" // Total Number of Disks
	GSIFieldDSN GSIField = "DSN" // Disk Sequence Number
	GSIFieldCO  GSIField = "CO"  // Country of Origin
	GSIFieldPUB GSIField = "PUB" // Publisher
	GSIFieldEN  GSIField = "EN"  // Editor's Name
	GSIFieldECD GSIField = "ECD" // Editor's Contact
	GSIFieldUDA GSIField = "UDA" // User-Defined Area
)

type JustificationCode

type JustificationCode byte

JustificationCode is indicating the horizontal alignment of the displayed subtitle. Only "unchanged presentation" (0), "left-justified text" (1), "centered text" (2) and "right-justified text" (3) are supported.

const (
	JustificationCodeInvalid               JustificationCode = 0xFF
	JustificationCodeUnchangedPresentation JustificationCode = 0x00
	JustificationCodeLeftJustifiedText     JustificationCode = 0x01
	JustificationCodeCenteredText          JustificationCode = 0x02
	JustificationCodeRightJustifiedText    JustificationCode = 0x03
)

func (JustificationCode) String

func (jc JustificationCode) String() string

String returns the string representation of JustificationCode.

type LanguageCode

type LanguageCode byte

Language Code is the code of the language for wih the subtitle list is prepared.

const (
	LanguageCodeInvalid       LanguageCode = 0xFF
	LanguageCodeUnknown       LanguageCode = 0x00
	LanguageCodeAlbanian      LanguageCode = 0x01
	LanguageCodeBreton        LanguageCode = 0x02
	LanguageCodeCatalan       LanguageCode = 0x03
	LanguageCodeCroatian      LanguageCode = 0x04
	LanguageCodeWelsh         LanguageCode = 0x05
	LanguageCodeCzech         LanguageCode = 0x06
	LanguageCodeDanish        LanguageCode = 0x07
	LanguageCodeGerman        LanguageCode = 0x08
	LanguageCodeEnglish       LanguageCode = 0x09
	LanguageCodeSpanish       LanguageCode = 0x0A
	LanguageCodeEsperanto     LanguageCode = 0x0B
	LanguageCodeEstonian      LanguageCode = 0x0C
	LanguageCodeBasque        LanguageCode = 0x0D
	LanguageCodeFaroese       LanguageCode = 0x0E
	LanguageCodeFrench        LanguageCode = 0x0F
	LanguageCodeFrisian       LanguageCode = 0x10
	LanguageCodeIrish         LanguageCode = 0x11
	LanguageCodeGaelic        LanguageCode = 0x12
	LanguageCodeGalician      LanguageCode = 0x13
	LanguageCodeIcelandic     LanguageCode = 0x14
	LanguageCodeItalian       LanguageCode = 0x15
	LanguageCodeLappish       LanguageCode = 0x16
	LanguageCodeLatin         LanguageCode = 0x17
	LanguageCodeLatvian       LanguageCode = 0x18
	LanguageCodeLuxembourgian LanguageCode = 0x19
	LanguageCodeLithuanian    LanguageCode = 0x1A
	LanguageCodeHungarian     LanguageCode = 0x1B
	LanguageCodeMaltese       LanguageCode = 0x1C
	LanguageCodeDutch         LanguageCode = 0x1D
	LanguageCodeNorwegian     LanguageCode = 0x1E
	LanguageCodeOccitan       LanguageCode = 0x1F
	LanguageCodePolish        LanguageCode = 0x20
	LanguageCodePortugese     LanguageCode = 0x21
	LanguageCodeRomanian      LanguageCode = 0x22
	LanguageCodeRomansh       LanguageCode = 0x23
	LanguageCodeSerbian       LanguageCode = 0x24
	LanguageCodeSlovak        LanguageCode = 0x25
	LanguageCodeSlovenian     LanguageCode = 0x26
	LanguageCodeFinnish       LanguageCode = 0x27
	LanguageCodeSwedish       LanguageCode = 0x28
	LanguageCodeTurkish       LanguageCode = 0x29
	LanguageCodeFlemish       LanguageCode = 0x2A
	LanguageCodeWallon        LanguageCode = 0x2B
	LanguageCodeAmharic       LanguageCode = 0x7F
	LanguageCodeArabic        LanguageCode = 0x7E
	LanguageCodeArmenian      LanguageCode = 0x7D
	LanguageCodeAssamese      LanguageCode = 0x7C
	LanguageCodeAzerbaijani   LanguageCode = 0x7B
	LanguageCodeBambora       LanguageCode = 0x7A
	LanguageCodeBielorussian  LanguageCode = 0x79
	LanguageCodeBengali       LanguageCode = 0x78
	LanguageCodeBulgarian     LanguageCode = 0x77
	LanguageCodeBurmese       LanguageCode = 0x76
	LanguageCodeChinese       LanguageCode = 0x75
	LanguageCodeChurash       LanguageCode = 0x74
	LanguageCodeDari          LanguageCode = 0x73
	LanguageCodeFulani        LanguageCode = 0x72
	LanguageCodeGeorgian      LanguageCode = 0x71
	LanguageCodeGreek         LanguageCode = 0x70
	LanguageCodeGujurati      LanguageCode = 0x6F
	LanguageCodeGurani        LanguageCode = 0x6E
	LanguageCodeHausa         LanguageCode = 0x6D
	LanguageCodeHebrew        LanguageCode = 0x6C
	LanguageCodeHindi         LanguageCode = 0x6B
	LanguageCodeIndonesian    LanguageCode = 0x6A
	LanguageCodeJapanese      LanguageCode = 0x69
	LanguageCodeKannada       LanguageCode = 0x68
	LanguageCodeKazakh        LanguageCode = 0x67
	LanguageCodeKhmer         LanguageCode = 0x66
	LanguageCodeKorean        LanguageCode = 0x65
	LanguageCodeLaotian       LanguageCode = 0x64
	LanguageCodeMacedonian    LanguageCode = 0x63
	LanguageCodeMalagasay     LanguageCode = 0x62
	LanguageCodeMalaysian     LanguageCode = 0x61
	LanguageCodeMoldavian     LanguageCode = 0x60
	LanguageCodeMarathi       LanguageCode = 0x5F
	LanguageCodeNdebele       LanguageCode = 0x5E
	LanguageCodeNepali        LanguageCode = 0x5D
	LanguageCodeOriya         LanguageCode = 0x5C
	LanguageCodePapamiento    LanguageCode = 0x5B
	LanguageCodePersian       LanguageCode = 0x5A
	LanguageCodePunjabi       LanguageCode = 0x59
	LanguageCodePushtu        LanguageCode = 0x58
	LanguageCodeQuechua       LanguageCode = 0x57
	LanguageCodeRussian       LanguageCode = 0x56
	LanguageCodeRuthenian     LanguageCode = 0x55
	LanguageCodeSerboCroat    LanguageCode = 0x54
	LanguageCodeShona         LanguageCode = 0x53
	LanguageCodeSinhalese     LanguageCode = 0x52
	LanguageCodeSomali        LanguageCode = 0x51
	LanguageCodeSrananTongo   LanguageCode = 0x50
	LanguageCodeSwahili       LanguageCode = 0x4F
	LanguageCodeTadzhik       LanguageCode = 0x4E
	LanguageCodeTamil         LanguageCode = 0x4D
	LanguageCodeTatar         LanguageCode = 0x4C
	LanguageCodeTelugu        LanguageCode = 0x4B
	LanguageCodeThai          LanguageCode = 0x4A
	LanguageCodeUkrainian     LanguageCode = 0x49
	LanguageCodeUrdu          LanguageCode = 0x48
	LanguageCodeUzbek         LanguageCode = 0x47
	LanguageCodeVietnamese    LanguageCode = 0x46
	LanguageCodeZulu          LanguageCode = 0x45
)

func (LanguageCode) String

func (lc LanguageCode) String() string

String returns the string representation of LanguageCode.

type TTIBlock

type TTIBlock struct {
	SGN int               // Subtitle Group Number
	SN  int               // Subtitle Number
	EBN int               // Extension Block Number
	CS  CumulativeStatus  // Cumulative Status
	TCI Timecode          // Time Code In
	TCO Timecode          // Time Code Out
	VP  int               // Vertical Position
	JC  JustificationCode // Justification Code
	CF  CommentFlag       // Comment Flag
	TF  string            // Text Field
	// contains filtered or unexported fields
}

TTIBlock is the Text and Timing Information (TTI) block representation.

func NewTTIBlock

func NewTTIBlock() *TTIBlock

NewTTIBlock returns a new TTI block.

func (*TTIBlock) Decode

func (tti *TTIBlock) Decode(r io.Reader) error

Decode reads and decodes TTI block from reader. An error is returned if a fatal error occurs that prevents further decoding.

func (*TTIBlock) Encode

func (tti *TTIBlock) Encode(w io.Writer) error

Encode encodes and writes TTI block to writer. An error is returned if a fatal error occurs that prevents further encoding.

func (*TTIBlock) Reset

func (tti *TTIBlock) Reset()

Reset resets the TTI block to its default values.

func (*TTIBlock) SetText

func (tti *TTIBlock) SetText(text string, cct CharacterCodeTable) error

SetText sets the Text Field (TF) from the UTF-8 encoded text.

func (*TTIBlock) Text

func (tti *TTIBlock) Text(cct CharacterCodeTable) (string, error)

Text returns the UTF-8 decoded Text Field (TF).

func (*TTIBlock) Validate

func (tti *TTIBlock) Validate(framerate uint, dsc DisplayStandardCode, mnr int) ([]error, error)

Validate validates TTI block. It returns a slice of warnings and an error if any. Warnings are returned for each field that is invalid, warnings can flagged as fatal if they are considered to be fatal to further file processing. An error is returned if a field is invalid and prevents validation of further fields.

type TTIError

type TTIError struct {
	FieldError
	// contains filtered or unexported fields
}

TTIError is an error that occurred on a TTI field. It extends FieldError that carries the concerned TTI field. It carries the concerned TTI block number. If TTI block number is -1, it means that the TTI block number is unknown.

func (*TTIError) BlockNumber

func (e *TTIError) BlockNumber() int

BlockNumber returns the concerned TTI block number. If TTI block number is -1, it means that the TTI block number is unknown.

func (*TTIError) Error

func (e *TTIError) Error() string

Error returns the error message.

func (*TTIError) Field

func (e *TTIError) Field() TTIField

Field returns the concerned TTI field.

func (*TTIError) Unwrap

func (e *TTIError) Unwrap() error

Unwrap returns the underlying error.

type TTIField

type TTIField Field

TTIField represents a TTI block field. It extends Field.

const (
	TTIFieldSGN TTIField = "SGN" // Subtitle Group Number
	TTIFieldSN  TTIField = "SN"  // Subtitle Number
	TTIFieldEBN TTIField = "EBN" // Extension Block Number
	TTIFieldCS  TTIField = "CS"  // Cumulative Status
	TTIFieldTCI TTIField = "TCI" // Time Code In
	TTIFieldTCO TTIField = "TCO" // Time Code Out
	TTIFieldVP  TTIField = "VP"  // Vertical Position
	TTIFieldJC  TTIField = "JC"  // Justification Code
	TTIFieldCF  TTIField = "CF"  // Comment Flag
	TTIFieldTF  TTIField = "TF"  // Text Field
)

type TeletextColor

type TeletextColor TeletextControlCode

TeletextColor is the code used to represent a Teletext color (from EBU document Tech. 3240)

const (
	TeletextColorBlack   TeletextColor = 0x0
	TeletextColorRed     TeletextColor = 0x1
	TeletextColorGreen   TeletextColor = 0x2
	TeletextColorYellow  TeletextColor = 0x3
	TeletextColorBlue    TeletextColor = 0x4
	TeletextColorMagenta TeletextColor = 0x5
	TeletextColorCyan    TeletextColor = 0x6
	TeletextColorWhite   TeletextColor = 0x7
)

func (TeletextColor) String

func (c TeletextColor) String() string

String returns the string representation of TeletextColor.

type TeletextControlCode

type TeletextControlCode ControlCode

TeletextControlCode (from EBU document Tech. 3240)

const (
	TeletextControlCodeAlphaBlack       TeletextControlCode = 0x00
	TeletextControlCodeAlphaRed         TeletextControlCode = 0x01
	TeletextControlCodeAlphaGreen       TeletextControlCode = 0x02
	TeletextControlCodeAlphaYellow      TeletextControlCode = 0x03
	TeletextControlCodeAlphaBlue        TeletextControlCode = 0x04
	TeletextControlCodeAlphaMagenta     TeletextControlCode = 0x05
	TeletextControlCodeAlphaCyan        TeletextControlCode = 0x06
	TeletextControlCodeAlphaWhite       TeletextControlCode = 0x07
	TeletextControlCodeFlash            TeletextControlCode = 0x08
	TeletextControlCodeSteady           TeletextControlCode = 0x09
	TeletextControlCodeEndBox           TeletextControlCode = 0x0A
	TeletextControlCodeStartBox         TeletextControlCode = 0x0B
	TeletextControlCodeNormalHeight     TeletextControlCode = 0x0C
	TeletextControlCodeDoubleHeight     TeletextControlCode = 0x0D
	TeletextControlCodeDoubleWidth      TeletextControlCode = 0x0E
	TeletextControlCodeDoubleSize       TeletextControlCode = 0x0F
	TeletextControlCodeMosaicBlack      TeletextControlCode = 0x10
	TeletextControlCodeMosaicRed        TeletextControlCode = 0x11
	TeletextControlCodeMosaicGreen      TeletextControlCode = 0x12
	TeletextControlCodeMosaicYellow     TeletextControlCode = 0x13
	TeletextControlCodeMosaicBlue       TeletextControlCode = 0x14
	TeletextControlCodeMosaicMagenta    TeletextControlCode = 0x15
	TeletextControlCodeMosaicCyan       TeletextControlCode = 0x16
	TeletextControlCodeMosaicWhite      TeletextControlCode = 0x17
	TeletextControlCodeConceal          TeletextControlCode = 0x18
	TeletextControlCodeContiguousMosaic TeletextControlCode = 0x19
	TeletextControlCodeSeparatedMosaic  TeletextControlCode = 0x1A
	TeletextControlCodeReserved         TeletextControlCode = 0x1B
	TeletextControlCodeBlackBackground  TeletextControlCode = 0x1C
	TeletextControlCodeNewBackground    TeletextControlCode = 0x1D
	TeletextControlCodeHoldMosaic       TeletextControlCode = 0x1E
	TeletextControlCodeReleaseMosaic    TeletextControlCode = 0x1F
)

func (TeletextControlCode) String

func (c TeletextControlCode) String() string

String returns the string representation of TeletextControlCode.

type TextDecoder

type TextDecoder interface {
	// Decode decodes a X-encoded byte slice to a UTF-8 byte slice.
	Decode(b []byte) ([]byte, error)
}

TextDecoder is a decoder for text.

type TextEncoder

type TextEncoder interface {
	// Encode decodes a UTF-8 byte slice to a X-encoded byte slice.
	Encode(b []byte) ([]byte, error)
}

TextEncoder is an encoder for text.

type TimeCodeStatus

type TimeCodeStatus byte

TimeCodeStatus is indicating the validity of the information given in the GSI and TTI blocks containing time-code data. Only "Not intended for use" (0) and "Intended for use" (1) are supported values.

const (
	TimeCodeStatusInvalid           TimeCodeStatus = 0xFF
	TimeCodeStatusNotIntendedForUse TimeCodeStatus = 0x00
	TimeCodeStatusIntendedForUse    TimeCodeStatus = 0x01
)

func (TimeCodeStatus) String

func (tcs TimeCodeStatus) String() string

String returns the string representation of TimeCodeStatus.

type Timecode

type Timecode struct {
	Hours   int
	Minutes int
	Seconds int
	Frames  int
}

Timecode represents a temporal position.

func TimecodeFromDuration

func TimecodeFromDuration(duration time.Duration, framerate uint) Timecode

TimecodeFromDuration returns a timecode from the given time.Duration.

func TimecodeFromFrames

func TimecodeFromFrames(frames int, framerate uint) Timecode

TimecodeFromFrames returns a timecode from the given number of frames.

func (*Timecode) Correct

func (t *Timecode) Correct(framerate uint)

Correct corrects the timecode to make sure that the values are within the valid ranges. For example, if the timecode is 00:00:00:30 with a framerate of 25, the timecode will be corrected to 00:00:01:05.

func (Timecode) String

func (t Timecode) String() string

String returns a string representation of the timecode.

func (Timecode) ToDuration

func (t Timecode) ToDuration(framerate uint) time.Duration

ToDuration returns timecode time.Duration representation.

func (Timecode) ToFrames

func (t Timecode) ToFrames(framerate uint) int

ToFrames returns the total number of frames.

func (Timecode) Validate

func (t Timecode) Validate(framerate uint) error

Validate validates the timecode.

type ValidateError

type ValidateError struct {
	// contains filtered or unexported fields
}

ValidateError is an error that occurred during validation. It carries the value that caused the error. ValidateError implements the error and Unwrap interfaces.

func (*ValidateError) Error

func (e *ValidateError) Error() string

Error returns the error message.

func (*ValidateError) IsFatal

func (e *ValidateError) IsFatal() bool

IsFatal returns true if the error is fatal.

func (*ValidateError) Unwrap

func (e *ValidateError) Unwrap() error

Unwrap returns the underlying error.

func (*ValidateError) Value

func (e *ValidateError) Value() any

Value returns the value that caused the error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL