video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-07-26 88c21b872799a1ae9dd7dd7d20f3811d749d9418
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
130
131
132
133
134
135
136
137
138
139
140
 
#ifdef __cplusplus
extern "C"{
#endif
 
#include "../cffmpeg.h"
#include <string.h>
 
#ifdef __cplusplus
}
#endif
 
#ifndef LIB_CFFMPEG
#include "csrc/all.hpp"
#endif
#include "csrc/wrapper.hpp"
 
using namespace cffmpeg_wrap;
 
cffmpeg c_ffmpeg_create(){
    return new Wrapper;
}
 
void c_ffmpeg_destroy(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    delete s;
}
 
void c_ffmpeg_run(const cffmpeg h, const char *input){
    Wrapper *s = (Wrapper*)h;
    s->RunStream(input);
}
 
void c_ffmpeg_scale(const cffmpeg h, const int wid, const int hei, const int flags){
    Wrapper *s = (Wrapper*)h;
    s->ScalePicture(wid, hei, flags);
}
 
void c_ffmpeg_run_gb28181(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    s->UseGB28181();
}
 
void c_ffmepg_use_cpu(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    s->UseCPU();
}
 
 
//////passive api
void c_ffmpeg_build_recorder(const cffmpeg h, const char* id, const char *dir, int mind, int maxd){
    Wrapper *s = (Wrapper*)h;
    s->BuildRecorder(id, dir, mind, maxd);
}
 
void c_ffmpeg_fire_recorder(const cffmpeg h, const char* sid, const int64_t id){
    Wrapper *s = (Wrapper*)h;
    s->FireRecorder(sid, id);
}
 
char* c_ffmpeg_get_info_recorder(const cffmpeg h, char **sid, int *index, int *length){
    Wrapper *s = (Wrapper*)h;
    int i;
    std::string p;
    std::string id;
    s->GetInfoRecorder(id, i, p);
 
    // printf("cffmpeg get info : index : %d, file : %s\n", i, p.c_str());
 
    *index = i;
    *length = p.length();
    char *path = (char*)malloc(*length + 1);
    memcpy(path, p.c_str(), *length);
    path[*length] = '\0';
 
    *sid = (char*)malloc(id.length()+1);
    memcpy(*sid, id.c_str(), id.length());
    *sid[id.length()] = '\0';
    
    return path;
}
 
void c_ffmpeg_build_decoder(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    s->BuildDecoder();
}
 
void* c_ffmpeg_get_pic_decoder(const cffmpeg h, int *wid, int *hei){
    Wrapper *s = (Wrapper*)h;
    unsigned char *data = NULL;
    s->GetPicDecoder(&data, wid, hei);
    return data;
}
 
void* c_ffmpeg_get_avpacket(const cffmpeg h, int *size, int *key){
    Wrapper *s = (Wrapper*)h;
    unsigned char *data = NULL;
    s->GetPacket(&data, size, key);
    return data;
}
/////////////////////active api
void c_ffmpeg_active_recorder(const cffmpeg h, const char *dir, int mind, int maxd, 
                                    rec_func fn){
    Wrapper *s = (Wrapper*)h;
 
    s->ActiveRecorder(dir, mind, maxd,[fn](std::string &p, int &i){
        fn((char*)p.c_str(), i);
    });
}
 
void c_ffmpeg_active_decoder(const cffmpeg h, dec_func fn){
    Wrapper *s = (Wrapper*)h;
    s->ActiveDecoder([fn](void* d, int wid, int hei){
        fn(d, wid, hei);
    });
}
 
 
/////////////////////test
void* c_ffmpeg_decode_jpeg(const cffmpeg h, const char *file, int *wid, int *hei){
    Wrapper *s = (Wrapper*)h;
    uint8_t *p = s->decodeJPEG(file, wid, hei);
    if(!p){
        *wid = *hei = 0;
    }
    return p;
}
 
// pic encoder
void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi){
    return CreateEncoder(w, h, fps, br, scale_flag, gi);
}
 
void c_ffmpeg_destroy_encoder(void *h){
    DestroyEncoder(h);
}
 
int c_ffmpeg_encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key){
    return Encode(hdl, in, w, h, out, size, key);
}