-
Notifications
You must be signed in to change notification settings - Fork 168
/
stream_test.go
64 lines (45 loc) · 1.42 KB
/
stream_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
package gmf_test
import (
"log"
"testing"
"github.com/3d0c/gmf"
)
func TestStream(t *testing.T) {
ctx := gmf.NewCtx()
vc, err := gmf.FindEncoder("mpeg4")
if err != nil {
t.Fatal(err)
}
cc := gmf.NewCodecCtx(vc)
if cc == nil {
t.Fatal("Unable to allocate codec context")
}
defer cc.Free()
if ctx.NewStream(vc) == nil {
t.Fatal("Unable to create new stream")
}
td := CodecCtxTestData
cc.SetWidth(td.width).SetHeight(td.height).SetTimeBase(td.timebase).SetPixFmt(td.pixfmt).SetBitRate(td.bitrate)
if err := cc.Open(nil); err != nil {
t.Fatal(err)
}
st := assert(ctx.GetStream(0)).(*gmf.Stream)
st.DumpContexCodec(cc)
if cc.Height() != td.height || cc.Width() != td.width {
t.Fatalf("Expected dimension = %dx%d, %dx%d got\n", td.width, td.height, st.CodecCtx().Width(), st.CodecCtx().Height())
}
ctx.Free()
log.Println("Stream is OK")
}
func TestStreamInputCtx(t *testing.T) {
inputCtx, err := gmf.NewInputCtx(inputSampleFilename)
if err != nil {
t.Fatal(err)
}
ist := assert(inputCtx.GetStream(0)).(*gmf.Stream)
if ist.CodecPar().Width() != inputSampleWidth || ist.CodecPar().Height() != inputSampleHeight {
t.Fatalf("Expected dimension = %dx%d, %dx%d got\n", inputSampleWidth, inputSampleHeight, ist.CodecCtx().Width(), ist.CodecCtx().Height())
}
log.Printf("Input stream is OK, cnt: %d, %dx%d\n", inputCtx.StreamsCnt(), ist.CodecCtx().Width(), ist.CodecCtx().Height())
inputCtx.Free()
}