-
Notifications
You must be signed in to change notification settings - Fork 0
/
codecCtx_test.go
61 lines (48 loc) · 1.24 KB
/
codecCtx_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
package gmf_test
import (
"github.com/3d0c/gmf"
"log"
"testing"
)
var CodecCtxTestData = struct {
width int
height int
timebase gmf.AVR
pixfmt int32
bitrate int
}{
width: 100,
height: 200,
timebase: gmf.AVR{Num: 1, Den: 25},
pixfmt: gmf.AV_PIX_FMT_YUV420P,
bitrate: 400000,
}
func TestCodecCtx(t *testing.T) {
td := CodecCtxTestData
codec, err := gmf.FindEncoder("mpeg4")
if err != nil {
t.Fatal(err)
}
cc := gmf.NewCodecCtx(codec)
if cc == nil {
t.Fatal("Unable to allocate codec context")
}
cc.SetWidth(td.width).SetHeight(td.height).SetTimeBase(td.timebase).SetPixFmt(td.pixfmt).SetBitRate(td.bitrate)
if cc.Width() != td.width {
t.Fatalf("Expected width = %v, %v got.\n", td.width, cc.Width())
}
if cc.Height() != td.height {
t.Fatalf("Expected height = %v, %v got.\n", td.height, cc.Height())
}
if cc.TimeBase().AVR().Num != td.timebase.Num || cc.TimeBase().AVR().Den != td.timebase.Den {
t.Fatalf("Expected AVR = %v, %v got", cc.TimeBase().AVR(), td.timebase)
}
if cc.PixFmt() != td.pixfmt {
t.Fatalf("Expected pixfmt = %v, %v got.\n", td.pixfmt, cc.PixFmt())
}
if err := cc.Open(nil); err != nil {
t.Fatal(err)
}
log.Println("CodecCtx is successfully created and opened.")
cc.Free()
}