package goffmpeg /* #include #include "libcffmpeg.h" */ import "C" import "unsafe" const ( // ScaleNone self add no scale raw frame data ScaleNone = 0 // ScaleFastBilinear SWS_FAST_BILINEAR ScaleFastBilinear = 1 // ScaleBilinear SWS_BILINEAR ScaleBilinear = 2 // ScaleBicubic SWS_BICUBIC ScaleBicubic = 4 // ScaleX SWS_X ScaleX = 8 // ScalePoint SWS_POINT ScalePoint = 0x10 // ScaleArea SWS_AREA ScaleArea = 0x20 // ScaleBicublin SWS_BICUBLIN ScaleBicublin = 0x40 // ScaleGauss SWS_GAUSS ScaleGauss = 0x80 // ScaleSinc SWS_SINC ScaleSinc = 0x100 // ScaleLancZos SWS_LANCZOS ScaleLancZos = 0x200 // ScaleSpline SWS_SPLINE ScaleSpline = 0x400 ) // SrcFormat format const SrcFormat = 23 // DstFormat format const DstFormat = 3 // GoConv conv type GoConv struct { SrcW int SrcH int DstW int DstH int conv C.cconv } // NewConv new conv func NewConv(srcW, srcH, dstW, dstH, scaleFlag int) *GoConv { c := C.wrap_fn_create_conv(unsafe.Pointer(libcffmpeg), C.int(srcW), C.int(srcH), C.int(SrcFormat), C.int(dstW), C.int(dstH), C.int(DstFormat), C.int(scaleFlag)) if c == nil { return nil } return &GoConv{ srcW, srcH, dstW, dstH, c, } } // NewResizer resize func NewResizer(srcW, srcH, format, dstW, dstH, scaleFlag int) *GoConv { c := C.wrap_fn_create_conv(unsafe.Pointer(libcffmpeg), C.int(srcW), C.int(srcH), C.int(format), C.int(dstW), C.int(dstH), C.int(format), C.int(scaleFlag)) if c == nil { return nil } return &GoConv{ srcW, srcH, dstW, dstH, c, } } // Free free func (c *GoConv) Free() { if c.conv != nil { C.wrap_fn_destroy_conv(unsafe.Pointer(libcffmpeg), c.conv) } } // ConvToPicture conv to pic func (c *GoConv) ConvToPicture(src []byte) []byte { if c.conv == nil { return nil } cin := C.CBytes(src) defer C.free(cin) bgr := C.wrap_fn_conv(unsafe.Pointer(libcffmpeg), c.conv, (*C.uchar)(cin)) defer C.free(unsafe.Pointer(bgr)) if bgr != nil { return C.GoBytes(bgr, C.int(c.DstW*c.DstH*3)) } return nil } // Resize resize func (c *GoConv) Resize(src []byte) []byte { if c.SrcW == c.DstW && c.SrcH == c.DstH { return src } return c.ConvToPicture(src) } /////////////// for conv