| | |
| | | void* c_ffmpeg_decode(const char *file, const int gb, int *wid, int *hei); |
| | | |
| | | // 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, const int fmt, const char *file); |
| | | void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); |
| | | void c_ffmpeg_destroy_encoder(void *h); |
| | | int c_ffmpeg_encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); |
| | | |
| | |
| | | } |
| | | |
| | | // 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, const int fmt, const char *file){ |
| | | return CreateEncoder(w, h, fps, br, scale_flag, gi, fmt, file); |
| | | 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){ |
| | |
| | | int br; |
| | | int gi; |
| | | int flag; |
| | | int fmt; |
| | | cvbridge *bridge; |
| | | } PicEncoder; |
| | | |
| | | void *CreateEncoder(const int w, const int h, const int fps, const int br, |
| | | const int scale_flag, const int gi, const int fmt, const char *file){ |
| | | |
| | | if (fmt < 0) return NULL; |
| | | const int scale_flag, const int gi){ |
| | | |
| | | PicEncoder *e = (PicEncoder*)malloc(sizeof(PicEncoder)); |
| | | e->enc = NULL; |
| | |
| | | e->br = br; |
| | | e->gi = gi; |
| | | e->flag = scale_flag; |
| | | e->fmt = fmt; |
| | | e->bridge = NULL; |
| | | |
| | | VideoProp prop_; |
| | |
| | | prop_.bit_rate_ = br; |
| | | gi < 0 ? prop_.gpu_acc_ = false : prop_.gpu_acc_ = true; |
| | | |
| | | std::string filename("./88.mp4"); |
| | | if (file) filename = file; |
| | | |
| | | FormatOut *enc = new FormatOut(prop_, filename.c_str()); |
| | | FormatOut *enc = new FormatOut(prop_, "./88.mp4"); |
| | | e->enc = enc; |
| | | |
| | | return e; |
| | |
| | | |
| | | if (e->bridge == NULL){ |
| | | e->bridge = new cvbridge( |
| | | w, h, e->fmt, |
| | | w, h, AV_PIX_FMT_BGR24, |
| | | e->w, e->h, ctx->pix_fmt, e->flag); |
| | | } |
| | | |
| | | AVFrame *bgr_frame = cvbridge::fillFrame(in, w, h, e->fmt); |
| | | AVFrame *bgr_frame = cvbridge::fillFrame(in, w, h, AV_PIX_FMT_BGR24); |
| | | AVFrame *frame = e->bridge->convert2Frame(bgr_frame); |
| | | av_frame_free(&bgr_frame); |
| | | |
| | |
| | | uint8_t* Decode(const char *file, const int gb, int *w, int *h); |
| | | |
| | | void *CreateEncoder(const int w, const int h, const int fps, const int br, |
| | | const int scale_flag, const int gi, const int fmt, const char *file); |
| | | const int scale_flag, const int gi); |
| | | void DestroyEncoder(void *h); |
| | | int Encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); |
| | | |
| | |
| | | } |
| | | |
| | | return &GoEncoder{ |
| | | enc: C.wrap_fn_create_encoder(unsafe.Pointer(libcffmpeg), C.int(w), C.int(h), C.int(fps), C.int(br), C.int(sFlag), C.int(gi), C.int(DstFormat), nil), |
| | | enc: C.wrap_fn_create_encoder(unsafe.Pointer(libcffmpeg), C.int(w), C.int(h), C.int(fps), C.int(br), C.int(sFlag), C.int(gi)), |
| | | } |
| | | } |
| | | |
| | |
| | | return b, int(size), isKey |
| | | } |
| | | return nil, 0, false |
| | | } |
| | | |
| | | // NewJpegEncoder encoder |
| | | func NewJpegEncoder(w, h, fps, br, sFlag, gi, fmt int, file string) *GoEncoder { |
| | | if w <= 0 || h <= 0 { |
| | | return nil |
| | | } |
| | | |
| | | cfile := C.CString(file) |
| | | defer C.free(unsafe.Pointer(cfile)) |
| | | return &GoEncoder{ |
| | | enc: C.wrap_fn_create_encoder(unsafe.Pointer(libcffmpeg), C.int(w), C.int(h), C.int(fps), C.int(br), C.int(sFlag), C.int(gi), C.int(fmt), cfile), |
| | | } |
| | | } |
| | | |
| | | // EncodeJpeg bgr->jpg |
| | | func (e *GoEncoder) EncodeJpeg(bgr []byte, w, h int) ([]byte, error) { |
| | | |
| | | return nil, nil |
| | | } |
| | |
| | | } |
| | | |
| | | // for encoder |
| | | cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int scale_flag, const int gi, const int fmt, const char *file){ |
| | | cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int scale_flag, const int gi){ |
| | | if (!fn_create_encoder){ |
| | | fn_create_encoder = (lib_cffmpeg_create_encoder)dlsym(lib, "c_ffmpeg_create_encoder"); |
| | | release_if_err(fn_create_encoder, lib); |
| | | } |
| | | return fn_create_encoder(w, h, fps, br, scale_flag, gi, fmt, file); |
| | | return fn_create_encoder(w, h, fps, br, scale_flag, gi); |
| | | } |
| | | |
| | | void wrap_fn_destroy_encoder(void *lib, const cencoder h){ |
| | |
| | | void* wrap_fn_decode(void *lib, const char* file, const int gb, int* wid, int* hei); |
| | | // for encoder |
| | | typedef void* cencoder; |
| | | typedef cencoder (*lib_cffmpeg_create_encoder)(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi, const int fmt, const char *file); |
| | | typedef cencoder (*lib_cffmpeg_create_encoder)(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); |
| | | typedef void (*lib_cffmpeg_destroy_encoder)(cencoder h); |
| | | typedef int (*lib_cffmpeg_encode)(cencoder hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); |
| | | |
| | |
| | | static lib_cffmpeg_destroy_encoder fn_destroy_encoder = NULL; |
| | | static lib_cffmpeg_encode fn_encode = NULL; |
| | | |
| | | cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int scale_flag, const int gi, const int fmt, const char *file); |
| | | cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); |
| | | void wrap_fn_destroy_encoder(void *lib, const cencoder h); |
| | | void* wrap_fn_encode(void *lib, cencoder hdl, void *in, const int w, const int h, int *out_size, int *key); |
| | | |