func NewMuxer(source *MediaSource, format, uri string) (*Muxer, error) { m := Muxer{done: make(chan bool), recl: make([]reclaimer, 0, 8)} m.context = C.avformat_alloc_context() if m.context == (*C.AVFormatContext)(null) { return nil, fmt.Errorf("allocate output format context failed") } m.recl = append(m.recl, func() { C.avformat_free_context(m.context) }) var f *C.char = C.CString(format) var u *C.char = C.CString(uri) defer C.free(unsafe.Pointer(f)) defer C.free(unsafe.Pointer(u)) m.context.oformat = C.av_guess_format(f, u, (*C.char)(null)) if m.context.oformat == (*C.AVOutputFormat)(null) { return nil, fmt.Errorf("output format not supported") } C.av_strlcpy(&m.context.filename[0], u, C.size_t(unsafe.Sizeof(m.context.filename))) var err error if m.capture, err = NewCapture(source.Video.driver, source.Video.device); err != nil { return nil, err } return &m, nil }
func (ctx *Context) SetFileName(fileName string) { cFileName := C.CString(fileName) defer C.free(unsafe.Pointer(cFileName)) C.av_strlcpy(&ctx.CAVFormatContext.filename[0], cFileName, C.sizeOfAVFormatContextFilename) }