func (e *Encoder) Close() { // Process "delayed" frames for { outsize := C.avcodec_encode_video(e._context, ptr(e._outbuf), C.int(len(e._outbuf)), nil) if outsize == 0 { break } n, err := e.Output.Write(e._outbuf[:outsize]) if err != nil { panic(err) } if n < int(outsize) { panic(fmt.Errorf("Short write, expected %d, wrote %d", outsize, n)) } } n, err := e.Output.Write([]byte{0, 0, 1, 0xb7}) if err != nil || n != 4 { log.Panicf("Error finishing mpeg file: %q; n = %d", err, n) } C.avcodec_close((*C.AVCodecContext)(unsafe.Pointer(e._context))) C.av_free(unsafe.Pointer(e._context)) C.av_free(unsafe.Pointer(e._frame)) e._frame, e._codec = nil, nil }
func (g *Graph) Dump() (string, error) { cStr := C.avfilter_graph_dump(g.CAVFilterGraph, nil) if cStr == nil { return "", ErrAllocationError } defer C.av_free(unsafe.Pointer(cStr)) return C.GoString(cStr), nil }
func (pd *ProbeData) Free() { defer C.free(unsafe.Pointer(pd.CAVProbeData.filename)) pd.CAVProbeData.filename = nil C.av_free(unsafe.Pointer(pd.CAVProbeData.buf)) pd.CAVProbeData.buf = nil pd.CAVProbeData.buf_size = 0 defer C.free(unsafe.Pointer(pd.CAVProbeData.mime_type)) pd.CAVProbeData.mime_type = nil }
func (g *Graph) DumpWithOptions(options string) (string, error) { cOptions := C.CString(options) defer C.free(unsafe.Pointer(cOptions)) cStr := C.avfilter_graph_dump(g.CAVFilterGraph, cOptions) if cStr == nil { return "", ErrAllocationError } defer C.av_free(unsafe.Pointer(cStr)) return C.GoString(cStr), nil }
func (oa *OptionAccessor) GetOptionWithFlags(name string, flags OptionSearchFlags) (string, bool, error) { var cOut *C.uint8_t cName := C.CString(name) defer C.free(unsafe.Pointer(cName)) searchFlags := oa.searchFlags(flags) code := C.av_opt_get(oa.obj, cName, searchFlags, &cOut) if code < 0 { return "", false, getOptionError(code) } defer C.av_free(unsafe.Pointer(cOut)) cStr := (*C.char)(unsafe.Pointer(cOut)) return C.GoString(cStr), true, nil }
func (self *Decoder) Close() { C.avformat_close_input(&self.FormatContext) for _, stream := range self.Streams { C.avcodec_close(stream.codec) } for _, frame := range self.frames { C.av_frame_free(&frame) } for _, buffer := range self.buffers { C.av_free(unsafe.Pointer(buffer)) } close(self.frameChan) self.running = false }
func (c *Decoder) decodeAudio(p Packet) *Frame { packet := new(C.AVPacket) C.av_init_packet(packet) defer C.av_free_packet(packet) packet.pts = C.int64_t(p.Pts) packet.dts = C.int64_t(p.Dts) packet.size = C.int(p.Size) packet.data = (*C.uint8_t)(unsafe.Pointer(&p.Data[0])) packet.stream_index = C.int(p.Stream) packet.flags = C.int(p.Flags) packet.duration = C.int(p.Duration) packet.pos = C.int64_t(p.Pos) //size:=packet.size; samples_size := C.int(C.AVCODEC_MAX_AUDIO_FRAME_SIZE) //bps := C.av_get_bits_per_sample_fmt(c.Ctx.sample_fmt) >> 3; outbuf := (*C.uint8_t)(C.av_malloc(C.uint(samples_size))) defer C.av_free(unsafe.Pointer(outbuf)) C.avcodec_decode_audio3(c.Ctx, (*C.int16_t)(unsafe.Pointer(outbuf)), &samples_size, packet) //println(data_len) return nil }
func av_free_codec_context(p *coder) { if p.Ctx.ctx != nil { C.av_free(unsafe.Pointer(p.Ctx.ctx)) } }
func (p *Frame) destroy() { if p.avframe != nil { C.av_free(unsafe.Pointer(p.avframe)) p.avframe = nil } }
func av_free_format_context(ctx *FormatContext) { C.av_free(unsafe.Pointer(ctx.ctx)) }
//Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). func AvFree(p unsafe.Pointer) { C.av_free(p) }
func (this *AVIOContext) Free() { delete(handlersMap, this.handlerKey) C.av_free(unsafe.Pointer(this.avAVIOContext.buffer)) C.av_free(unsafe.Pointer(this.avAVIOContext)) }
func av_free(data []byte) { C.av_free(unsafe.Pointer(&data[0])) }