-
Notifications
You must be signed in to change notification settings - Fork 2
/
scale.go
52 lines (43 loc) · 1.11 KB
/
scale.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
package ffmpeg
//#include <libswscale/swscale.h>
import "C"
import (
"errors"
"unsafe"
)
type ScaleContext C.struct_SwsContext
func NewScaleContext(srcWidth, srcHeight int, srcPixFmt PixelFormat, dstWidth, dstHeight int, dstPixFmt PixelFormat) (*ScaleContext, error) {
convertContext := (*ScaleContext)(C.sws_getContext(
C.int(srcWidth),
C.int(srcHeight),
RGBA.ctype(),
C.int(dstWidth),
C.int(dstHeight),
YUV420P.ctype(),
C.SWS_GAUSS,
(*C.struct_SwsFilter)(nil),
(*C.struct_SwsFilter)(nil),
(*C.double)(nil),
))
if convertContext == nil {
return nil, errors.New("create convetr context error")
}
return convertContext, nil
}
func (scaleContext *ScaleContext) Release() {
C.sws_freeContext(scaleContext.ctype())
}
func (scaleContext *ScaleContext) Scale(src, dst *VideoFrame) {
C.sws_scale(
scaleContext.ctype(),
&(src.ctype().data[0]),
&(src.ctype().linesize[0]),
C.int(0),
src.ctype().height,
&(dst.ctype().data[0]),
&(dst.ctype().linesize[0]),
)
}
func (scaleContext *ScaleContext) ctype() *C.struct_SwsContext {
return (*C.struct_SwsContext)(unsafe.Pointer(scaleContext))
}