Skip to content

Commit

Permalink
Fix WebM SeekHead (#89)
Browse files Browse the repository at this point in the history
Disable SeekHead calculation by default and remove SeekPosition to Cluster
according to Matroska File Format section 5.3. (2009 version)
(draft-lhomme-cellar-matroska-04 says that SeekHead must have
all top-level elements.)
Having only first Cluster SeekPosition looks causing problem on some player.
  • Loading branch information
at-wat authored Dec 16, 2019
1 parent 637c037 commit de19aaf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion webm/blockwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewSimpleBlockWriter(w0 io.WriteCloser, tracks []TrackEntry, opts ...BlockW
panic(err)
},
interceptor: DefaultBlockInterceptor,
seekHead: true,
seekHead: false,
}
for _, o := range opts {
if err := o(options); err != nil {
Expand Down
15 changes: 6 additions & 9 deletions webm/blockwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,27 +588,24 @@ func TestBlockWriter_WithSeekHead(t *testing.T) {
// Segment
0x18, 0x53, 0x80, 0x67, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
// SeekHead
0x11, 0x4D, 0x9B, 0x74, 0xBF,
0x11, 0x4D, 0x9B, 0x74, 0xAA,
0x4D, 0xBB, 0x92,
0x53, 0xAB, 0x84, 0x15, 0x49, 0xA9, 0x66, // Info
0x53, 0xAC, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44,
0x53, 0xAC, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2F,
0x4D, 0xBB, 0x92,
0x53, 0xAB, 0x84, 0x16, 0x54, 0xAE, 0x6B, // Tracks
0x53, 0xAC, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,
0x4D, 0xBB, 0x92,
0x53, 0xAB, 0x84, 0x1F, 0x43, 0xB6, 0x75, // Cluster
0x53, 0xAC, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64,
// Info, pos: 80
0x53, 0xAC, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B,
// Info, pos: 47
0x15, 0x49, 0xA9, 0x66, 0x87,
0x2A, 0xD7, 0xB1, 0x83, 0x0F, 0x42, 0x40,
// Tracks, pos: 92
// Tracks, pos: 59
0x16, 0x54, 0xAE, 0x6B, 0x8F,
0xAE, 0x8D,
0xD7, 0x81, 0x01,
0x73, 0xC5, 0x81, 0x02,
0x86, 0x81, 0x00,
0x83, 0x81, 0x01,
// Cluster, pos: 112
// Cluster
0x1F, 0x43, 0xB6, 0x75, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xE7, 0x81, 0x00,
}
Expand Down
6 changes: 0 additions & 6 deletions webm/seekhead.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type flexHeader struct {
func setSeekHead(header *flexHeader, opts ...ebml.MarshalOption) error {
infoPos := new(uint64)
tracksPos := new(uint64)
clusterPos := new(uint64)
header.Segment.SeekHead = &seekHeadFixed{}
if header.Segment.Info != nil {
header.Segment.SeekHead.Seek = append(header.Segment.SeekHead.Seek, seekFixed{
Expand All @@ -56,10 +55,6 @@ func setSeekHead(header *flexHeader, opts ...ebml.MarshalOption) error {
SeekID: ebml.ElementTracks.Bytes(),
SeekPosition: tracksPos,
})
header.Segment.SeekHead.Seek = append(header.Segment.SeekHead.Seek, seekFixed{
SeekID: ebml.ElementCluster.Bytes(),
SeekPosition: clusterPos,
})

var segmentPos uint64
hook := func(e *ebml.Element) {
Expand All @@ -82,7 +77,6 @@ func setSeekHead(header *flexHeader, opts ...ebml.MarshalOption) error {
if err := ebml.Marshal(header, buf, optsWithHook...); err != nil {
return err
}
*clusterPos = uint64(buf.Len()) - segmentPos

return nil
}

0 comments on commit de19aaf

Please sign in to comment.