Esempio n. 1
0
func (this *FmtCtx) Dump() {

	if this.ofmt == nil {
		C.av_dump_format(this.avCtx, 0, &(this.avCtx.filename[0]), 0)
	} else {
		C.av_dump_format(this.avCtx, 0, &(this.avCtx.filename[0]), 1)
	}
}
Esempio n. 2
0
func (m *Muxer) Open() bool {
	w, h := m.capture.Resolution()
	if !m.AddVideoStream(C.AV_CODEC_ID_H264, w, h) {
		return false
	}
	if !m.AddAudioStream(C.AV_CODEC_ID_AAC) {
		return false
	}
	if m.context.oformat.flags&C.AVFMT_NOFILE == 0 {
		if C.avio_open(&m.context.pb, &m.context.filename[0], C.AVIO_FLAG_WRITE) < 0 {
			return false
		}
		m.recl = append(m.recl, func() {
			C.avio_close(m.context.pb)
		})
	}
	C.av_dump_format(m.context, 0, &m.context.filename[0], 1)
	if C.avformat_write_header(m.context, (**C.AVDictionary)(null)) < 0 {
		return false
	}
	m.recl = append(m.recl, func() {
		C.av_write_trailer(m.context)
	})
	m.loop = true
	go m.routine()
	if m.display != nil {
		m.display.Open()
	}
	return true
}
Esempio n. 3
0
func (ctx *Context) Dump(streamIndex int, url string, isOutput bool) {
	var cIsOutput C.int
	if isOutput {
		cIsOutput = C.int(1)
	}
	cURL := C.CString(url)
	defer C.free(unsafe.Pointer(cURL))
	C.av_dump_format(ctx.CAVFormatContext, C.int(streamIndex), cURL, cIsOutput)
}
Esempio n. 4
0
func NewDecoder(filename string) (*Decoder, error) {
	self := new(Decoder)

	// format context
	var formatContext *C.AVFormatContext
	if C.avformat_open_input(&formatContext, C.CString(filename), nil, nil) != C.int(0) {
		return nil, errors.New(fmt.Sprintf("can't open %d", filename))
	}
	if C.avformat_find_stream_info(formatContext, nil) < 0 {
		return nil, errors.New("find stream info error")
	}
	C.av_dump_format(formatContext, 0, C.CString(filename), 0)
	self.FormatContext = formatContext

	// streams
	var streams []*C.AVStream
	header := (*reflect.SliceHeader)(unsafe.Pointer(&streams))
	header.Cap = int(formatContext.nb_streams)
	header.Len = int(formatContext.nb_streams)
	header.Data = uintptr(unsafe.Pointer(formatContext.streams))
	self.Streams = streams
	for _, stream := range streams {
		switch stream.codec.codec_type {
		case C.AVMEDIA_TYPE_VIDEO:
			self.VideoStreams = append(self.VideoStreams, stream)
		case C.AVMEDIA_TYPE_AUDIO:
			self.AudioStreams = append(self.AudioStreams, stream)
		default: //TODO other stream
		}
	}

	// codecs
	for _, stream := range self.Streams {
		codec := C.avcodec_find_decoder(stream.codec.codec_id)
		if codec == nil {
			continue
		}
		var options *C.AVDictionary
		if C.avcodec_open2(stream.codec, codec, &options) < 0 {
			return nil, errors.New(fmt.Sprintf("open codec error %v", stream.codec))
		}
		self.openedCodecs = append(self.openedCodecs, stream.codec)
	}

	// output channels
	self.audioFrames = make(chan *AudioFrame, 1024)
	self.timedFrames = make(chan *C.AVFrame)

	return self, nil
}
Esempio n. 5
0
File: context.go Progetto: ovr/goav
//Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
func (s *Context) AvDumpFormat(i int, url string, io int) {
	C.av_dump_format((*C.struct_AVFormatContext)(unsafe.Pointer(s)), C.int(i), C.CString(url), C.int(io))
}
Esempio n. 6
0
func dump_format(ctx *FormatContext) {
	C.av_dump_format(ctx.ctx, 0, nil, 1)
}
Esempio n. 7
0
func (this *FmtCtx) Dump() {
	cfilename := C.CString(this.ofmt.Filename)
	defer C.free(unsafe.Pointer(cfilename))

	C.av_dump_format(this.avCtx, 0, cfilename, 1)
}
Esempio n. 8
0
//void av_dump_format (AVFormatContext *ic, int index, const char *url, int is_output)
//Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
func Av_dump_format(ic *AVFormatContext, i int, url string, io int) {
	C.av_dump_format((*C.struct_AVFormatContext)(unsafe.Pointer(ic)), C.int(i), C.CString(url), C.int(io))
}