video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-07-22 d42f702ea93b3d34a300ad2f1f72db4d7bb9cc80
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
package goffmpeg
 
/*
#include <stdlib.h>
#include "libcffmpeg.h"
*/
import "C"
import "unsafe"
 
// FireRecorder fire recorder
func (h *GoFFMPEG) FireRecorder(id int64) {
    C.wrap_fn_fire_recorder(h.ffmpeg, C.long(id))
}
 
// BuildRecorder build recorder
func (h *GoFFMPEG) BuildRecorder(output string, mind, maxd int) {
    out := C.CString(output)
    defer C.free(unsafe.Pointer(out))
 
    C.wrap_fn_recorder(h.ffmpeg, out, C.int(mind), C.int(maxd))
}
 
// GetInfoRecorder info
func (h *GoFFMPEG) GetInfoRecorder() (int, string) {
    var i C.int = -1
    var l C.int
 
    p := C.wrap_fn_info_recorder(h.ffmpeg, &i, &l)
    if i == -1 {
        return -1, ""
    }
    defer C.free(unsafe.Pointer(p))
 
    return int(i), C.GoString(p)
}
 
// BuildDecoder build decoder
func (h *GoFFMPEG) BuildDecoder() {
    C.wrap_fn_decoder(h.ffmpeg)
}
 
// GetPicDecoder get pic from decoder
func (h *GoFFMPEG) GetPicDecoder() ([]byte, int, int) {
    var width C.int
    var height C.int
 
    p := C.wrap_fn_decoder_pic(h.ffmpeg, &width, &height)
    if width == 0 && height == 0 {
        return nil, 0, 0
    }
    defer C.free(unsafe.Pointer(p))
    d := C.GoBytes(p, width*height*3)
    wid := int(width)
    hei := int(height)
 
    return d, wid, hei
}