forked from discord/lilliput
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avcodec_test.go
79 lines (71 loc) · 2.12 KB
/
avcodec_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
package lilliput
import (
"os"
"testing"
)
func TestIsStreamable(t *testing.T) {
// Standard MP4
stdMp4, err := os.ReadFile("testdata/big_buck_bunny_480p_10s_std.mp4")
if err != nil {
t.Fatalf("failed to open test file: %v", err)
}
if isStreamable(createMatFromBytes(stdMp4)) {
t.Fatalf("expected file to not be streamable")
}
// Web-optimized streamable MP4
webMp4, err := os.ReadFile("testdata/big_buck_bunny_480p_10s_web.mp4")
if err != nil {
t.Fatalf("failed to open test file: %v", err)
}
if !isStreamable(createMatFromBytes(webMp4)) {
t.Fatalf("expected file to be streamable")
}
// MP4 with a big atom
bigAtomMp4, err := os.ReadFile("testdata/big_buck_bunny_480p_10s_big_atom.mp4")
if err != nil {
t.Fatalf("failed to open test file: %v", err)
}
if isStreamable(createMatFromBytes(bigAtomMp4)) {
t.Fatalf("expected file to not be streamable")
}
// MP4 with a zero-length atom
zeroLengthAtomMp4, err := os.ReadFile("testdata/big_buck_bunny_480p_10s_zero_length_atom.mp4")
if err != nil {
t.Fatalf("failed to open test file: %v", err)
}
if isStreamable(createMatFromBytes(zeroLengthAtomMp4)) {
t.Fatalf("expected file to not be streamable")
}
}
func TestICCProfile(t *testing.T) {
// Web-optimized streamable MP4 using BT.709 color space
webMp4, err := os.ReadFile("testdata/big_buck_bunny_480p_10s_web.mp4")
if err != nil {
t.Fatalf("failed to open test file: %v", err)
}
webAvCodecDecoder, err := newAVCodecDecoder(webMp4)
if err != nil {
t.Fatalf("failed to create decoder: %v", err)
}
defer webAvCodecDecoder.Close()
if len(webAvCodecDecoder.ICC()) == 0 {
t.Fatalf("expected ICC profile")
}
}
func BenchmarkIsStreamableWebMp4(b *testing.B) {
// Read the web-optimized streamable MP4 file
webMp4, err := os.ReadFile("testdata/big_buck_bunny_480p_10s_web.mp4")
if err != nil {
b.Fatalf("failed to open test file: %v", err)
}
b.ResetTimer()
// Run the benchmark
for i := 0; i < b.N; i++ {
webAvCodecDecoder, err := newAVCodecDecoder(webMp4)
if err != nil {
b.Fatalf("failed to create decoder: %v", err)
}
defer webAvCodecDecoder.Close()
_ = webAvCodecDecoder.IsStreamable()
}
}