video analysis2.0拆分,ffmpeg封装go接口库
chenshijun
2019-07-17 803388b511d31b9e25f6829298bb12e06323474c
goffmpeg.go
@@ -113,3 +113,48 @@
   }
   return nil, 0, 0
}
///////////////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() {
   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
}