-
Notifications
You must be signed in to change notification settings - Fork 0
/
sws_test.go
71 lines (52 loc) · 1.57 KB
/
sws_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
package gmf
import (
"log"
"testing"
)
// @todo export rescaled frame as jpeg and compare dimension.
func TestScale(t *testing.T) {
srcWidth, srcHeight := 640, 480
dstWidth, dstHeight := 320, 200
codec, err := FindEncoder("mpeg4")
if err != nil {
t.Fatal(err)
}
srcEncCtx := NewCodecCtx(codec)
if srcEncCtx == nil {
t.Fatal("Unable to allocate codec context")
}
srcEncCtx.SetWidth(640).SetHeight(480).SetPixFmt(AV_PIX_FMT_YUV420P)
dstCodecCtx := NewCodecCtx(codec)
if dstCodecCtx == nil {
t.Fatal("Unable to allocate codec context")
}
defer Release(dstCodecCtx)
dstCodecCtx.SetBitRate(400000).SetWidth(dstWidth).SetHeight(dstHeight).SetTimeBase(AVR{1, 25}).SetGopSize(10).SetMaxBFrames(1).SetPixFmt(AV_PIX_FMT_YUV420P)
dstCodecCtx.SetProfile(FF_PROFILE_MPEG4_SIMPLE)
outputCtx := NewCtx()
defer Release(outputCtx)
videoStream := outputCtx.NewStream(codec)
if videoStream == nil {
t.Fatalf("Unable to create stream for videoEnc [%s]\n", codec.LongName())
}
defer Release(videoStream)
if err := dstCodecCtx.Open(nil); err != nil {
t.Fatal(err)
}
videoStream.SetCodecCtx(dstCodecCtx)
swsCtx := NewSwsCtx(srcEncCtx, dstCodecCtx, SWS_BICUBIC)
defer Release(swsCtx)
dstFrame := NewFrame().SetWidth(dstWidth).SetHeight(dstHeight).SetFormat(AV_PIX_FMT_YUV420P)
defer Release(dstFrame)
if err := dstFrame.ImgAlloc(); err != nil {
t.Fatal(err)
}
var frame *Frame
for frame = range GenSyntVideoNewFrame(srcWidth, srcHeight, srcEncCtx.PixFmt()) {
frame.SetPts(0)
swsCtx.Scale(frame, dstFrame)
Release(frame)
break
}
log.Println("Swscale is OK")
}