| | |
| | | "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 NV |
| | | const SrcFormat = 23 |
| | | |
| | | // DstFormat format |
| | | const DstFormat = 3 |
| | | |
| | | var libcffmpeg C.libcffmpeg |
| | | |
| | | // InitFFmpeg init ffmepg |
| | |
| | | } |
| | | } |
| | | |
| | | // NewWithDevID 2nd new |
| | | func NewWithDevID(GB, CPU bool, devID int) *GoFFMPEG { |
| | | |
| | | f := C.wrap_fn_create(unsafe.Pointer(libcffmpeg)) |
| | | |
| | | if f == nil { |
| | | return nil |
| | | } |
| | | if GB { |
| | | C.wrap_fn_run_gb28181(unsafe.Pointer(libcffmpeg), f) |
| | | } |
| | | if CPU { |
| | | C.wrap_fn_use_cpu(unsafe.Pointer(libcffmpeg), f) |
| | | } else if devID > -1 { |
| | | r := C.wrap_fn_set_devid(unsafe.Pointer(libcffmpeg), f, C.int(devID)) |
| | | if r != 0 { |
| | | if f != nil { |
| | | C.wrap_fn_destroy(unsafe.Pointer(libcffmpeg), f) |
| | | } |
| | | FreeFFmpeg() |
| | | return nil |
| | | } |
| | | } |
| | | |
| | | return &GoFFMPEG{ |
| | | ffmpeg: f, |
| | | } |
| | | } |
| | | |
| | | // NewWithLogAndDevID log |
| | | func NewWithLogAndDevID(GB, CPU bool, devID int, ffmpegLog string) *GoFFMPEG { |
| | | lf := C.CString(ffmpegLog) |
| | | defer C.free(unsafe.Pointer(lf)) |
| | | |
| | | f := C.wrap_fn_create2(unsafe.Pointer(libcffmpeg), lf) |
| | | if f == nil { |
| | | return nil |
| | | } |
| | | if GB { |
| | | C.wrap_fn_run_gb28181(unsafe.Pointer(libcffmpeg), f) |
| | | } |
| | | if CPU { |
| | | C.wrap_fn_use_cpu(unsafe.Pointer(libcffmpeg), f) |
| | | } else if devID > -1 { |
| | | r := C.wrap_fn_set_devid(unsafe.Pointer(libcffmpeg), f, C.int(devID)) |
| | | if r != 0 { |
| | | if f != nil { |
| | | C.wrap_fn_destroy(unsafe.Pointer(libcffmpeg), f) |
| | | } |
| | | FreeFFmpeg() |
| | | return nil |
| | | } |
| | | } |
| | | |
| | | return &GoFFMPEG{ |
| | | ffmpeg: f, |
| | | } |
| | | } |
| | | |
| | | // NewWithLog log |
| | | func NewWithLog(GB, CPU bool, ffmpegLog string) *GoFFMPEG { |
| | | lf := C.CString(ffmpegLog) |
| | |
| | | C.wrap_fn_run(unsafe.Pointer(libcffmpeg), h.ffmpeg, in) |
| | | } |
| | | |
| | | // Run2 ffmpeg |
| | | func (h *GoFFMPEG) Run2(input string, minDuration int) { |
| | | in := C.CString(input) |
| | | defer C.free(unsafe.Pointer(in)) |
| | | |
| | | C.wrap_fn_run(unsafe.Pointer(libcffmpeg), h.ffmpeg, in) |
| | | } |
| | | |
| | | // FPS fps |
| | | func (h *GoFFMPEG) FPS() int { |
| | | return int(C.wrap_fn_fps(unsafe.Pointer(libcffmpeg), h.ffmpeg)) |
| | | } |
| | | |
| | | // ReleaseC release c memory |
| | | func ReleaseC(p unsafe.Pointer) { |
| | | if p == nil { |
| | | return |
| | | } |
| | | C.free(unsafe.Pointer(p)) |
| | | } |
| | | |
| | | // GetGBJpg Get GB28181 Jpg |
| | | func GetGBJpg(rtspUrl string) []byte { |
| | | rtsp := C.CString(rtspUrl) |
| | | defer C.free(unsafe.Pointer(rtsp)) |
| | | var jpgLen C.int |
| | | func GetGBJpg(rtspURL string, maxTry int) []byte { |
| | | rtsp := C.CString(rtspURL) |
| | | defer C.free(unsafe.Pointer(rtsp)) |
| | | var jpgLen C.int |
| | | |
| | | pic := C.wrap_fn_get_gb28181_pic(unsafe.Pointer(libcffmpeg), rtsp, &jpgLen) |
| | | defer C.free(unsafe.Pointer(pic)) |
| | | pic := C.wrap_fn_get_gb28181_pic(unsafe.Pointer(libcffmpeg), rtsp, &jpgLen, C.int(maxTry)) |
| | | defer C.free(unsafe.Pointer(pic)) |
| | | |
| | | retJpg := C.GoBytes(unsafe.Pointer(pic), jpgLen) |
| | | return retJpg |
| | | } |
| | | retJpg := C.GoBytes(unsafe.Pointer(pic), jpgLen) |
| | | return retJpg |
| | | } |