Skip to content

Commit

Permalink
Merge pull request #169 from abema/add-subtitle-sample-entry
Browse files Browse the repository at this point in the history
Add subtitle sample entries
  • Loading branch information
sunfish-shogi authored Dec 24, 2024
2 parents 895fe1d + 87d2795 commit ce47850
Show file tree
Hide file tree
Showing 2 changed files with 303 additions and 192 deletions.
30 changes: 30 additions & 0 deletions box_types_iso14496_12.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"strings"

"github.com/abema/go-mp4/internal/bitio"
"github.com/abema/go-mp4/internal/util"
Expand Down Expand Up @@ -1210,6 +1211,8 @@ func BoxTypeMp4a() BoxType { return StrToBoxType("mp4a") }
func BoxTypeEnca() BoxType { return StrToBoxType("enca") }
func BoxTypeAvcC() BoxType { return StrToBoxType("avcC") }
func BoxTypePasp() BoxType { return StrToBoxType("pasp") }
func BoxTypeStpp() BoxType { return StrToBoxType("stpp") }
func BoxTypeSbtt() BoxType { return StrToBoxType("sbtt") }

func init() {
AddAnyTypeBoxDef(&VisualSampleEntry{}, BoxTypeMp4v())
Expand All @@ -1221,6 +1224,8 @@ func init() {
AddAnyTypeBoxDef(&AudioSampleEntry{}, BoxTypeEnca())
AddAnyTypeBoxDef(&AVCDecoderConfiguration{}, BoxTypeAvcC())
AddAnyTypeBoxDef(&PixelAspectRatioBox{}, BoxTypePasp())
AddAnyTypeBoxDef(&XMLSubtitleSampleEntry{}, BoxTypeStpp())
AddAnyTypeBoxDef(&TextSubtitleSampleEntry{}, BoxTypeSbtt())
}

type SampleEntry struct {
Expand Down Expand Up @@ -1417,6 +1422,31 @@ type PixelAspectRatioBox struct {
VSpacing uint32 `mp4:"1,size=32"`
}

type XMLSubtitleSampleEntry struct {
SampleEntry `mp4:"0,extend"`
Namespace string `mp4:"1,string"` // space-separated list
SchemaLocation string `mp4:"2,string"` // space-separated list, optional
AuxiliaryMIMETypes string `mp4:"3,string"` // space-separated list, optional
}

func (xse *XMLSubtitleSampleEntry) GetNamespaceList() []string {
return strings.Fields(xse.Namespace)
}

func (xse *XMLSubtitleSampleEntry) GetSchemaLocationList() []string {
return strings.Fields(xse.SchemaLocation)
}

func (xse *XMLSubtitleSampleEntry) GetAuxiliaryMIMETypesList() []string {
return strings.Fields(xse.AuxiliaryMIMETypes)
}

type TextSubtitleSampleEntry struct {
SampleEntry `mp4:"0,extend"`
ContentEncoding string `mp4:"1,string"` // optional
MIMEFormat string `mp4:"2,string"`
}

/*************************** sbgp ****************************/

func BoxTypeSbgp() BoxType { return StrToBoxType("sbgp") }
Expand Down
Loading

0 comments on commit ce47850

Please sign in to comment.