Ejemplo n.º 1
0
func NewOutputCtx(i interface{}) (*FmtCtx, error) {
	this := &FmtCtx{streams: make(map[int]*Stream)}

	switch t := i.(type) {
	case string:
		this.ofmt = FindOutputFmt("", i.(string), "")

	case *OutputFmt:
		this.ofmt = i.(*OutputFmt)

	default:
		return nil, errors.New(fmt.Sprintf("unexpected type %v", t))
	}

	if this.ofmt == nil {
		return nil, errors.New(fmt.Sprintf("output format is not initialized. Unable to allocate context"))
	}

	cfilename := C.CString(this.ofmt.Filename)
	defer C.free(unsafe.Pointer(cfilename))

	C.avformat_alloc_output_context2(&this.avCtx, this.ofmt.avOutputFmt, nil, cfilename)
	if this.avCtx == nil {
		return nil, errors.New(fmt.Sprintf("unable to allocate context"))
	}

	this.Filename = this.ofmt.Filename

	return this, nil
}
Ejemplo n.º 2
0
func NewContextForOutput(output *Output) (*Context, error) {
	var cCtx *C.AVFormatContext
	code := C.avformat_alloc_output_context2(&cCtx, output.CAVOutputFormat, nil, nil)
	if code < 0 {
		return nil, avutil.NewErrorFromCode(avutil.ErrorCode(code))
	}
	return NewContextFromC(unsafe.Pointer(cCtx)), nil
}
Ejemplo n.º 3
0
func (this *FmtCtx) SetOformat(ofmt *OutputFmt) error {
	if ofmt == nil {
		return errors.New("'ofmt' is not initialized.")
	}

	if averr := C.avformat_alloc_output_context2(&this.avCtx, ofmt.avOutputFmt, nil, nil); averr < 0 {
		return errors.New(fmt.Sprintf("Error creating output context: %s", AvError(int(averr))))
	}

	return nil
}
Ejemplo n.º 4
0
func (this *FmtCtx) OpenOutput(ofmt *OutputFmt) error {
	if ofmt == nil {
		return errors.New("Error opening output. OutputFmt is empty.")
	}

	this.ofmt = ofmt

	cfilename := C.CString(ofmt.Filename)
	defer C.free(unsafe.Pointer(cfilename))

	if averr := C.avformat_alloc_output_context2(&this.avCtx, ofmt.avOutputFmt, nil, cfilename); averr < 0 {
		return errors.New(fmt.Sprintf("Error opening output '%s': %s", ofmt.Filename, AvError(int(averr))))
	}

	return nil
}
Ejemplo n.º 5
0
func NewOutputCtxWithFormatName(filename, format string) (*FmtCtx, error) {
	this := &FmtCtx{streams: make(map[int]*Stream)}

	cfilename := C.CString(filename)
	defer C.free(unsafe.Pointer(cfilename))

	cFormat := C.CString(format)
	defer C.free(unsafe.Pointer(cFormat))

	C.avformat_alloc_output_context2(&this.avCtx, nil, cFormat, cfilename)

	if this.avCtx == nil {
		return nil, errors.New(fmt.Sprintf("unable to allocate context"))
	}

	this.Filename = filename

	this.ofmt = &OutputFmt{Filename: filename, avOutputFmt: this.avCtx.oformat}

	//	fmt.Println(this.ofmt.Infomation())
	return this, nil
}
Ejemplo n.º 6
0
Archivo: avformat.go Proyecto: ovr/goav
//Allocate an Context for an output format.
func AvformatAllocOutputContext2(ctx **Context, o *OutputFormat, fo, fi string) int {
	return int(C.avformat_alloc_output_context2((**C.struct_AVFormatContext)(unsafe.Pointer(ctx)), (*C.struct_AVOutputFormat)(o), C.CString(fo), C.CString(fi)))
}