video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-10-09 68a19a73681301c6712e10d55bc64324716dbd24
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
package goffmpeg
 
/*
#include <stdlib.h>
#include "libcffmpeg.h"
*/
import "C"
 
///////////////for encoder
 
// GoEncoder encoder
type GoEncoder struct {
    enc C.cencoder
}
 
// NewEncoder encoder
func NewEncoder(w, h, fps, br, sFlag, gi int) *GoEncoder {
    if w <= 0 || h <= 0 {
        return nil
    }
 
    return &GoEncoder{
        enc: C.wrap_fn_create_encoder(C.int(w), C.int(h), C.int(fps), C.int(br), C.int(sFlag), C.int(gi)),
    }
}
 
// Free free
func (e *GoEncoder) Free() {
    if e.enc != nil {
        C.wrap_fn_destroy_encoder(e.enc)
    }
}
 
// Encode pic
func (e *GoEncoder) Encode(in []byte, w, h int) ([]byte, int, bool) {
 
    var size C.int
    var key C.int
    cin := C.CBytes(in)
    defer C.free(cin)
 
    p := C.wrap_fn_encode(e.enc, cin, C.int(w), C.int(h), &size, &key)
    defer C.free(p)
    if p != nil && size > 0 {
        b := C.GoBytes(p, size)
 
        isKey := false
        if key > 0 {
            isKey = true
        }
        return b, int(size), isKey
    }
    return nil, 0, false
}