video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-10-30 b1ed46392ad11cb454d13fb58d331239252d1546
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
package goffmpeg
 
/*
#include <stdlib.h>
#include "libcffmpeg.h"
*/
import "C"
 
import "unsafe"
 
// FireRecorder fire recorder
func (h *GoFFMPEG) FireRecorder(sid string, id int64) {
    csid := C.CString(sid)
    defer C.free(unsafe.Pointer(csid))
    C.wrap_fn_fire_recorder(unsafe.Pointer(libcffmpeg), h.ffmpeg, csid, C.long(id))
}
 
// BuildRecorder build recorder
func (h *GoFFMPEG) BuildRecorder(sid, output string, id int64, mind, maxd int, audio bool) {
    out := C.CString(output)
    defer C.free(unsafe.Pointer(out))
    csid := C.CString(sid)
    defer C.free(unsafe.Pointer(csid))
 
    a := 0
    if audio {
        a = 1
    }
    C.wrap_fn_recorder(unsafe.Pointer(libcffmpeg), h.ffmpeg, csid, out, C.long(id), C.int(mind), C.int(maxd), C.int(a))
}
 
// GetInfoRecorder info
func (h *GoFFMPEG) GetInfoRecorder() (string, int, string) {
    var i C.int = -1
 
    var id *C.char
    var idl C.int
 
    var p *C.char
    var pl C.int
 
    C.wrap_fn_info_recorder(unsafe.Pointer(libcffmpeg), h.ffmpeg, &i, &id, &idl, &p, &pl)
    // if p == nil {
    //     return -1, ""
    // }
    gID := C.GoString(id)
    C.free(unsafe.Pointer(id))
    path := C.GoString(p)
    C.free(unsafe.Pointer(p))
 
    // fmt.Println("Go get info : ", path, " len: ", l)
 
    return gID, int(i), path
}
 
// SetRecDurationForCache cache
func (h *GoFFMPEG) SetRecDurationForCache(min, max int) {
    C.wrap_fn_rec_duration(unsafe.Pointer(libcffmpeg), h.ffmpeg, C.int(min), C.int(max))
}