-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffprobe_test.go
83 lines (68 loc) · 1.91 KB
/
ffprobe_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
package mediaprobe_test
import (
"testing"
"github.com/Arimeka/mediaprobe"
)
var bitrateFiles = map[string]int64{
"./fixtures/video.mp4": 551193,
"./fixtures/with-meta.mov": 481140,
"./fixtures/audio.mp3": 128000,
"./fixtures/not-a-video.mp4": 0,
"./fixtures/corrupted.mp4": 0,
}
func TestInfo_FFProbe(t *testing.T) {
for filename, expectedBitrate := range bitrateFiles {
info, err := mediaprobe.New(filename)
if err != nil {
t.Fatalf("Filename: %s. Unexpected error %v", filename, err)
}
err = info.FFProbe()
if err != nil {
if filename != "./fixtures/corrupted.mp4" {
t.Errorf("Filename: %s. Unexpected error %v", filename, err)
}
} else {
if filename == "./fixtures/corrupted.mp4" {
t.Errorf("Filename: %s. Expected to return error but return nil", filename)
}
}
bitrate := info.BitRate
if bitrate != expectedBitrate {
t.Errorf("Filename: %s. Not expected video bitrate. Expected %d; got %d", filename, expectedBitrate, bitrate)
}
}
t.Run("remote_file", ffprobeRemoteFile)
t.Run("pixel format", ffprobePixelFormat)
}
func ffprobeRemoteFile(t *testing.T) {
handler := &Handler{
Filename: "./fixtures/video.mp4",
}
srv := ServeHttp(handler)
defer srv.Stop()
info, err := mediaprobe.New(srv.Endpoint())
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
err = info.FFProbe()
if err != nil {
t.Errorf("Unexpected error %v", err)
}
bitrate := info.BitRate
if bitrate != 551193 {
t.Errorf("Not expected video bitrate. Expected %d; got %d", 551193, bitrate)
}
}
func ffprobePixelFormat(t *testing.T) {
info, err := mediaprobe.New("./fixtures/video.mp4")
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
err = info.FFProbe()
if err != nil {
t.Errorf("Unexpected error %v", err)
}
if info.Streams[0].PixFmtName != "yuv420p" {
t.Errorf("Not expected pixel format. Expected %s; got %s", "yuv420p", info.Streams[0].PixFmtName)
}
}