Exemplo n.º 1
1
func (m *Muxer) writeAudioFrame(frame *C.AVFrame) bool {
	for C.av_audio_fifo_size(m.fifo) < 1024 { // generate & store in fifo
		C.fill_audio_frame(frame, m.audioStream.stream.codec)
		frame_size := frame.nb_samples
		if C.av_audio_fifo_realloc(m.fifo, C.av_audio_fifo_size(m.fifo)+frame_size) < 0 {
			return false
		}
		if C.av_audio_fifo_write(m.fifo, (*unsafe.Pointer)(unsafe.Pointer(&frame.data[0])), frame_size) < frame_size {
			return false
		}
	}
	got_packet := C.int(0)
	for C.av_audio_fifo_size(m.fifo) >= 1024 { // read & encode & write
		frame_size := C.min(C.av_audio_fifo_size(m.fifo), m.audioStream.stream.codec.frame_size)
		output_frame := C.alloc_audio_frame(m.audioStream.stream.codec)
		if C.av_audio_fifo_read(m.fifo, (*unsafe.Pointer)(unsafe.Pointer(&output_frame.data[0])), frame_size) < frame_size {
			C.av_frame_free(&output_frame)
			return false
		}
		pkt := C.AVPacket{}
		C.av_init_packet(&pkt)
		output_frame.pts = C.int64_t(m.audioStream.ts)
		m.audioStream.ts += int(m.audioStream.stream.codec.frame_size)
		if C.avcodec_encode_audio2(m.audioStream.stream.codec, &pkt, frame, &got_packet) < 0 {
			C.av_free_packet(&pkt)
			return false
		}
		if got_packet == 0 {
			continue
		}
		C.av_packet_rescale_ts(&pkt, m.audioStream.stream.codec.time_base, m.audioStream.stream.time_base)
		pkt.stream_index = m.audioStream.stream.index
		if C.av_interleaved_write_frame(m.context, &pkt) < 0 {
			return false
		}
	}
	return true
}
Exemplo n.º 2
0
func (this *FmtCtx) WritePacket(p *Packet) error {
	if averr := C.av_interleaved_write_frame(this.avCtx, &p.avPacket); averr < 0 {
		return errors.New(fmt.Sprintf("Unable to write packet to '%s': %s", this.Filename, AvError(int(averr))))
	}

	return nil
}
Exemplo n.º 3
0
func (ctx *Context) InterleavedWriteFrame(pkt *avcodec.Packet) error {
	var cPkt *C.AVPacket
	if pkt != nil {
		cPkt = (*C.AVPacket)(unsafe.Pointer(&pkt.CAVPacket))
	}
	code := C.av_interleaved_write_frame(ctx.CAVFormatContext, cPkt)
	if code < 0 {
		return avutil.NewErrorFromCode(avutil.ErrorCode(code))
	}
	return nil
}
Exemplo n.º 4
0
func (m *Muxer) writeVideoFrame(frame *C.AVFrame) bool {
	if m.capture.Read(frame) != nil {
		return false
	}
	if m.display != nil {
		m.display.Render(frame)
	}
	pkt := C.AVPacket{}
	C.av_init_packet(&pkt)
	frame.pts = C.int64_t(m.videoStream.ts)
	m.videoStream.ts++
	got_packet := C.int(0)
	if C.avcodec_encode_video2(m.videoStream.stream.codec, &pkt, frame, &got_packet) < 0 {
		C.av_free_packet(&pkt)
		return false
	}
	if got_packet == 0 {
		return false
	}
	C.av_packet_rescale_ts(&pkt, m.videoStream.stream.codec.time_base, m.videoStream.stream.time_base)
	pkt.stream_index = m.videoStream.stream.index
	return C.av_interleaved_write_frame(m.context, &pkt) == 0
}
Exemplo n.º 5
0
func av_interleaved_write_frame(ctx *FormatContext, packet *Packet) int {
	return int(C.av_interleaved_write_frame((*C.AVFormatContext)(unsafe.Pointer(ctx.ctx)), (*C.AVPacket)(unsafe.Pointer(packet.avpacket))))
}
Exemplo n.º 6
0
Arquivo: context.go Projeto: ovr/goav
//Write a packet to an output media file ensuring correct interleaving.
func (s *Context) AvInterleavedWriteFrame(pkt *Packet) int {
	return int(C.av_interleaved_write_frame((*C.struct_AVFormatContext)(s), (*C.struct_AVPacket)(pkt)))
}
Exemplo n.º 7
0
//int av_interleaved_write_frame (AVFormatContext *s, AVPacket *pkt)
//Write a packet to an output media file ensuring correct interleaving.
func Av_interleaved_write_frame(s *AVFormatContext, pkt *AVPacket) int {
	return int(C.av_interleaved_write_frame((*C.struct_AVFormatContext)(s), (*C.struct_AVPacket)(pkt)))
}