video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-10-09 de6e563245cdfabc5bd3890d05b7e54bdbf16eb4
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package goffmpeg
 
/*
#include <stdlib.h>
#include "libcffmpeg.h"
*/
import "C"
import "unsafe"
 
const (
    // ScaleNone self add no scale raw frame data
    ScaleNone = 0
    // ScaleFastBilinear SWS_FAST_BILINEAR
    ScaleFastBilinear = 1
    // ScaleBilinear SWS_BILINEAR
    ScaleBilinear = 2
    // ScaleBicubic SWS_BICUBIC
    ScaleBicubic = 4
    // ScaleX SWS_X
    ScaleX = 8
    // ScalePoint SWS_POINT
    ScalePoint = 0x10
    // ScaleArea SWS_AREA
    ScaleArea = 0x20
    // ScaleBicublin SWS_BICUBLIN
    ScaleBicublin = 0x40
    // ScaleGauss SWS_GAUSS
    ScaleGauss = 0x80
    // ScaleSinc SWS_SINC
    ScaleSinc = 0x100
    // ScaleLancZos SWS_LANCZOS
    ScaleLancZos = 0x200
    // ScaleSpline SWS_SPLINE
    ScaleSpline = 0x400
)
 
// SrcFormat format
const SrcFormat = 23
 
// DstFormat format
const DstFormat = 3
 
// GoConv conv
type GoConv struct {
    srcW int
    srcH int
    dstW int
    dstH int
 
    conv C.cconv
}
 
// NewConv new conv
func NewConv(srcW, srcH, dstW, dstH, scaleFlag int) *GoConv {
    c := C.wrap_fn_create_conv(C.int(srcW), C.int(srcH), C.int(SrcFormat),
        C.int(dstW), C.int(dstH), C.int(DstFormat), C.int(scaleFlag))
 
    if c == nil {
        return nil
    }
 
    return &GoConv{
        srcW,
        srcH,
        dstW,
        dstH,
        c,
    }
}
 
// NewResizer resize
func NewResizer(srcW, srcH, format, dstW, dstH int) *GoConv {
    c := C.wrap_fn_create_conv(C.int(srcW), C.int(srcH), C.int(format), C.int(dstW), C.int(dstH), C.int(format), ScaleNone)
 
    if c == nil {
        return nil
    }
 
    return &GoConv{
        srcW,
        srcH,
        dstW,
        dstH,
        c,
    }
}
 
// Free free
func (c *GoConv) Free() {
    if c.conv != nil {
        C.wrap_fn_destroy_conv(c.conv)
    }
}
 
// ConvToPicture conv to pic
func (c *GoConv) ConvToPicture(src []byte) []byte {
    if c.conv == nil {
        return nil
    }
 
    cin := C.CBytes(src)
    defer C.free(cin)
 
    bgr := C.wrap_fn_conv(c.conv, (*C.uchar)(cin))
    defer C.free(unsafe.Pointer(bgr))
 
    if bgr != nil {
        return C.GoBytes(bgr, C.int(c.dstW*c.dstH*3))
    }
 
    return nil
}
 
// Resize resize
func (c *GoConv) Resize(src []byte) []byte {
    if c.srcW == c.dstW && c.srcH == c.dstH {
        return src
    }
    return c.ConvToPicture(src)
}
 
/////////////// for conv
 
// ConvGPU conv gpu resize
func ConvGPU(in []byte, w, h, dstW, dstH int) []byte {
 
    return nil
 
}