-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathmultitrack_test.go
98 lines (83 loc) · 1.82 KB
/
multitrack_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"bytes"
"os"
"testing"
"github.com/Eyevinn/mp4ff/mp4"
"github.com/go-test/deep"
)
const (
inMultiTrackMp4File = "testdata/main_1.mp4"
goldenSampleList = "testdata/golden_samples.txt"
goldenScenarist = "testdata/golden_captions.scc"
)
func TestDecodeEncodeMultiTrack(t *testing.T) {
ifd, err := os.Open(inMultiTrackMp4File)
if err != nil {
t.Error(err)
}
defer ifd.Close()
tracks, err := getTracksAndSamplesFromMultiTrackFragmentedFile(ifd)
if err != nil {
t.Error(err)
}
var buf bytes.Buffer
err = writeTrackInfo(&buf, tracks)
if err != nil {
t.Error(err)
}
err = compareOrUpdateGolden(t, buf.Bytes(), goldenSampleList)
if err != nil {
t.Error(err)
}
}
func TestDecodeClcp(t *testing.T) {
ifd, err := os.Open(inMultiTrackMp4File)
if err != nil {
t.Error(err)
}
defer ifd.Close()
tracks, err := getTracksAndSamplesFromMultiTrackFragmentedFile(ifd)
if err != nil {
t.Error(err)
}
for _, track := range tracks {
if track.hdlrType == "clcp" {
var buf bytes.Buffer
err = writeScenaristFile(&buf, track)
if err != nil {
t.Error(err)
}
err = compareOrUpdateGolden(t, buf.Bytes(), goldenScenarist)
if err != nil {
t.Error(err)
}
}
}
}
func TestGetMultiTrackSamples(t *testing.T) {
ifd, err := os.Open(inMultiTrackMp4File)
if err != nil {
t.Error(err)
}
defer ifd.Close()
parsedMp4, err := mp4.DecodeFile(ifd)
if err != nil {
t.Error(err)
}
var buf bytes.Buffer
parsedMp4.FragEncMode = mp4.EncModeBoxTree
parsedMp4.EncOptimize = mp4.OptimizeNone
err = parsedMp4.Encode(&buf)
if err != nil {
t.Error(err)
}
inFileRaw, err := os.ReadFile(filePath)
if err != nil {
t.Error(err)
}
diff := deep.Equal(buf.Bytes(), inFileRaw)
if diff != nil {
t.Errorf("Encoded multi-track file not same as input for %s", inMultiTrackMp4File)
}
}