當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.avcodec_decode_video2函數代碼示例

本文整理匯總了Golang中C.avcodec_decode_video2函數的典型用法代碼示例。如果您正苦於以下問題:Golang avcodec_decode_video2函數的具體用法?Golang avcodec_decode_video2怎麽用?Golang avcodec_decode_video2使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了avcodec_decode_video2函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: avcodec_decode_video

func avcodec_decode_video(ctx *_CodecContext, frame *Frame, finished *int, packet *avPacket) int {
	return int(C.avcodec_decode_video2(
		ctx.ctx,
		(*C.AVFrame)(unsafe.Pointer(frame.avframe)),
		(*C.int)(unsafe.Pointer(finished)),
		(*C.AVPacket)(unsafe.Pointer(packet))))
}
開發者ID:adityanatraj,項目名稱:gmf,代碼行數:7,代碼來源:avcodec.go

示例2: Decode

// @todo should be private
func (this *Packet) Decode(cc *CodecCtx) (*Frame, bool, int, error) {
	var gotOutput int
	var ret int = 0

	if frames[cc.Type()] == nil {
		frames[cc.Type()] = &Frame{avFrame: C.av_frame_alloc(), mediaType: cc.Type()}
	}

	switch cc.Type() {
	case AVMEDIA_TYPE_AUDIO:
		ret = int(C.avcodec_decode_audio4(cc.avCodecCtx, frames[AVMEDIA_TYPE_AUDIO].avFrame, (*C.int)(unsafe.Pointer(&gotOutput)), &this.avPacket))
		if ret < 0 {
			return nil, false, int(ret), errors.New(fmt.Sprintf("Unable to decode audio packet, averror: %s", AvError(int(ret))))
		}

		break

	case AVMEDIA_TYPE_VIDEO:
		ret = int(C.avcodec_decode_video2(cc.avCodecCtx, frames[AVMEDIA_TYPE_VIDEO].avFrame, (*C.int)(unsafe.Pointer(&gotOutput)), &this.avPacket))
		if ret < 0 {
			return nil, false, int(ret), errors.New(fmt.Sprintf("Unable to decode video packet, averror: %s", AvError(int(ret))))
		}

		break

	default:
		return nil, false, int(ret), errors.New(fmt.Sprintf("Unknown codec type: %v", cc.Type()))
	}

	return frames[cc.Type()], (gotOutput > 0), int(ret), nil
}
開發者ID:0x46616c6b,項目名稱:gmf,代碼行數:32,代碼來源:packet.go

示例3: Read

func (id *Capture) Read(frame *C.AVFrame) error {
	if frame == (*C.AVFrame)(null) {
		return fmt.Errorf("buffer error")
	}
	pkt := C.AVPacket{}
	C.av_init_packet(&pkt)
	defer C.av_free_packet(&pkt)
	if C.av_read_frame(id.context, &pkt) < 0 {
		return fmt.Errorf("read frame error")
	}
	if int(pkt.stream_index) != id.index {
		return fmt.Errorf("not video frame")
	}
	got_frame := C.int(0)
	if C.avcodec_decode_video2(id.codec, id.frame, &got_frame, &pkt) < 0 {
		return fmt.Errorf("decode frame error")
	}
	if got_frame != 0 {
		if C.sws_scale(id.sws, (**C.uint8_t)(&(id.frame.data[0])), &id.frame.linesize[0], 0, id.codec.height, &frame.data[0], &frame.linesize[0]) >= 0 {
			return nil
		}
		return fmt.Errorf("scale error")
	}
	return fmt.Errorf("no frame out")
}
開發者ID:qianbo0423,項目名稱:media-muxer,代碼行數:25,代碼來源:capture.go

示例4: avcodec_decode_video

func avcodec_decode_video(cdcctx *C.AVCodecContext, frame *Frame, packet *C.AVPacket) (bool, error) {
	var gotFrame C.int
	if C.avcodec_decode_video2(cdcctx, &frame.avframe, &gotFrame, packet) < 0 {
		return false, errors.New("error decoding video")
	}
	if gotFrame != 0 {
		frame.PTS = int64(C.av_frame_get_best_effort_timestamp(&frame.avframe))
	}
	return gotFrame != 0, nil
}
開發者ID:mrordinaire,項目名稱:go-ffmpeg,代碼行數:10,代碼來源:avcodec.go

示例5: NextFrame

func (g *Generator) NextFrame() (image.Image, int64, error) {
	img := image.NewRGBA(image.Rect(0, 0, g.Width, g.Height))
	frame := C.av_frame_alloc()
	var pkt C.struct_AVPacket
	var frameFinished C.int
	for C.av_read_frame(g.avfContext, &pkt) == 0 {
		if int(pkt.stream_index) != g.vStreamIndex {
			C.av_free_packet(&pkt)
			continue
		}
		if C.avcodec_decode_video2(g.avcContext, frame, &frameFinished, &pkt) <= 0 {
			C.av_free_packet(&pkt)
			return nil, 0, errors.New("can't decode frame")
		}
		C.av_free_packet(&pkt)
		if frameFinished == 0 {
			continue
		}
		ctx := C.sws_getContext(
			C.int(g.Width),
			C.int(g.Height),
			g.avcContext.pix_fmt,
			C.int(g.Width),
			C.int(g.Height),
			C.PIX_FMT_RGBA,
			C.SWS_BICUBIC,
			nil,
			nil,
			nil,
		)
		if ctx == nil {
			return nil, 0, errors.New("can't allocate scaling context")
		}
		srcSlice := (**C.uint8_t)(&frame.data[0])
		srcStride := (*C.int)(&frame.linesize[0])
		dst := (**C.uint8_t)(unsafe.Pointer(&img.Pix))
		dstStride := (*C.int)(unsafe.Pointer(&[1]int{img.Stride}))
		C.sws_scale(
			ctx,
			srcSlice,
			srcStride,
			C.int(0),
			g.avcContext.height,
			dst,
			dstStride,
		)
		break
	}
	timestamp := int64(C.av_frame_get_best_effort_timestamp(frame))
	return img, timestamp, nil
}
開發者ID:reaperhulk,項目名稱:screengen,代碼行數:51,代碼來源:screengen.go

示例6: Decode

// @todo should be private
func (this *Packet) Decode(cc *CodecCtx) (*Frame, bool, int, error) {
	var gotOutput int
	var ret int = 0

	if frames[cc.Type()] == nil {
		frames[cc.Type()] = &Frame{avFrame: C.av_frame_alloc(), mediaType: cc.Type()}
	}

	switch cc.Type() {
	case AVMEDIA_TYPE_AUDIO:
		ret = int(C.avcodec_decode_audio4(cc.avCodecCtx, frames[AVMEDIA_TYPE_AUDIO].avFrame, (*C.int)(unsafe.Pointer(&gotOutput)), &this.avPacket))
		if ret < 0 {
			return nil, false, int(ret), errors.New(fmt.Sprintf("Unable to decode audio packet, averror: %s", AvError(int(ret))))
		}
		break

	case AVMEDIA_TYPE_VIDEO:
		ret = int(C.avcodec_decode_video2(cc.avCodecCtx, frames[AVMEDIA_TYPE_VIDEO].avFrame, (*C.int)(unsafe.Pointer(&gotOutput)), &this.avPacket))

		if ret < 0 {
			return nil, false, int(ret), errors.New(fmt.Sprintf("Unable to decode video packet, averror: %s", AvError(int(ret))))
		}

		break

	default:
		return nil, false, int(ret), errors.New(fmt.Sprintf("Unknown codec type: %v", cc.Type()))
	}

	defer func() {
		if r := recover(); r != nil {
			buf := make([]byte, 1<<16)
			runtime.Stack(buf, false)
			reason := fmt.Sprintf("%v: %s", r, buf)
			fmt.Println("Runtime failure, reason -> %s", reason)

		}
	}()

	return frames[cc.Type()], (gotOutput > 0), int(ret), nil
}
開發者ID:flexconstructor,項目名稱:gmf,代碼行數:42,代碼來源:packet.go

示例7: AvcodecDecodeVideo2

//Decode the video frame of size avpkt->size from avpkt->data into picture.
func (ctxt *Context) AvcodecDecodeVideo2(p *Frame, g *int, a *Packet) int {
	return int(C.avcodec_decode_video2((*C.struct_AVCodecContext)(ctxt), (*C.struct_AVFrame)(p), (*C.int)(unsafe.Pointer(g)), (*C.struct_AVPacket)(a)))
}
開發者ID:gale320,項目名稱:goav,代碼行數:4,代碼來源:context.go

示例8: decodeVideo

func (c *Decoder) decodeVideo(p Packet) *Frame {
	if !c.Valid {
		//println("try to decode with an invalid Decoder")
		return nil
	}
	//println("try to decode with a valid Decoder")

	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(make([]byte, p.Size)[0])
	//myBytes:=make([]byte,p.Size);
	/*
	   var pb *byte
	   if(len(p.Data)>0){
	   //println("Data > 0")
	   pb=&p.Data[0]
	   }*/
	packet.data = (*C.uint8_t)(unsafe.Pointer(&p.Data[0]))
	//    println(p.Data)
	//    println(pb)
	//    println(packet.data)
	//    packet.data=unsafe.Pointer(p.Data)
	//    for i:= 0; i < re.Size; i++ {
	//      re.Data[i] = data[i];
	//    }
	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)

	height := c.Ctx.height
	width := c.Ctx.width
	var frame *Frame = new(Frame)

	numBytes := C.avpicture_get_size(0, width, height)
	//_size = numBytes;
	//_buffer := (*C.uint8_t) (C.av_malloc(C.uint(numBytes)));
	if numBytes > 0 {
		var buffer []byte = make([]byte, numBytes)
		var pbuffer *byte = &buffer[0]
		// C.memset((*C.uint8_t)(_buffer), 0, C.size_t(numBytes));
		// Assign appropriate parts of buffer to image planes
		//var picture * C.AVPicture=(*C.AVPicture)(unsafe.Pointer(frame))
		//println(frame)
		//println(picture)
		//:=&frame
		//854x480
		C.avpicture_fill((*C.AVPicture)(unsafe.Pointer(frame)), (*C.uint8_t)(unsafe.Pointer(pbuffer)), 0, width, height)
	}

	//frameFinished:=C.int(0)
	var frameFinished *C.int = new(C.int)
	//bytes_decoded:=

	C.avcodec_decode_video2(c.Ctx, (*C.AVFrame)(unsafe.Pointer(frame)), frameFinished, packet)
	frame.pts = packet.pts
	//frame.dts=packet.dts

	/*
	   //C.avcodec_decode_video2(nil,nil,nil,nil)

	   header:=fmt.Sprintf("P5\n%d %d\n255\n",width,height)

	   file, err := os.Open("test.ppm", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666)

	   if(err!=nil){
	   println("error while openning file")
	   }
	   file.WriteString(header)
	   linesize:=int(frame.linesize[0])
	   //println(linesize)
	   data:=make([]byte, width)
	   tmpdata:=(*(*[1<<30]byte)(unsafe.Pointer(frame.data[0])))[0:numBytes]
	   //    for i:= 0; i < 1; i++ {
	   //      data[i] = tmpdata[i];
	   //    }

	   for i := 0; i < int(height); i++{
	   for a:= 0; a < int(width); a++ {
	   data[a] = tmpdata[(i*linesize)+a];
	   }
	   file.Write(data);
	   }

	   file.Close()*/
	//ioutil.WriteFile("test.data", header,0755)
	//println("bla fasel")
	//println(bytes_decoded)
	//println(*frameFinished)
	return frame
}
開發者ID:psychobob666,項目名稱:MediaEncodingCluster,代碼行數:96,代碼來源:ffmpeg.go

示例9: ImageWxH

// ImageWxH returns a screenshot at the ts milliseconds, scaled to the specified width and height.
func (g *Generator) ImageWxH(ts int64, width, height int) (image.Image, error) {
	img := image.NewRGBA(image.Rect(0, 0, width, height))
	frame := C.av_frame_alloc()
	defer C.av_frame_free(&frame)
	frameNum := C.av_rescale(
		C.int64_t(ts),
		C.int64_t(g.streams[g.vStreamIndex].time_base.den),
		C.int64_t(g.streams[g.vStreamIndex].time_base.num),
	) / 1000
	if C.avformat_seek_file(
		g.avfContext,
		C.int(g.vStreamIndex),
		0,
		frameNum,
		frameNum,
		C.AVSEEK_FLAG_FRAME,
	) < 0 {
		return nil, errors.New("can't seek to timestamp")
	}
	C.avcodec_flush_buffers(g.avcContext)
	var pkt C.struct_AVPacket
	var frameFinished C.int
	for C.av_read_frame(g.avfContext, &pkt) == 0 {
		if int(pkt.stream_index) != g.vStreamIndex {
			C.av_free_packet(&pkt)
			continue
		}
		if C.avcodec_decode_video2(g.avcContext, frame, &frameFinished, &pkt) <= 0 {
			C.av_free_packet(&pkt)
			return nil, errors.New("can't decode frame")
		}
		C.av_free_packet(&pkt)
		if frameFinished == 0 || pkt.dts < frameNum {
			continue
		}
		ctx := C.sws_getContext(
			C.int(g.Width),
			C.int(g.Height),
			g.avcContext.pix_fmt,
			C.int(width),
			C.int(height),
			C.PIX_FMT_RGBA,
			C.SWS_BICUBIC,
			nil,
			nil,
			nil,
		)
		if ctx == nil {
			return nil, errors.New("can't allocate scaling context")
		}
		srcSlice := (**C.uint8_t)(&frame.data[0])
		srcStride := (*C.int)(&frame.linesize[0])
		dst := (**C.uint8_t)(unsafe.Pointer(&img.Pix))
		dstStride := (*C.int)(unsafe.Pointer(&[1]int{img.Stride}))
		C.sws_scale(
			ctx,
			srcSlice,
			srcStride,
			0,
			g.avcContext.height,
			dst,
			dstStride,
		)
		break
	}
	return img, nil
}
開發者ID:kevin-cantwell,項目名稱:stillframe,代碼行數:68,代碼來源:screengen.go

示例10: Start


//.........這裏部分代碼省略.........
			if C.av_read_frame(self.FormatContext, &packet) < 0 { // read packet
				log.Fatal("read frame error") //TODO stop gracefully
			}

			// get packet time
			if packet.dts != C.AV_NOPTS_VALUE {
				pts = int64(packet.dts)
			} else {
				pts = 0
			}
			if packet.stream_index == videoIndex {
				packetTime = time.Duration(float64(pts) * float64(C.av_q2d(videoStream.time_base)) * float64(time.Second))
			} else if packet.stream_index == audioIndex {
				packetTime = time.Duration(float64(pts) * float64(C.av_q2d(audioStream.time_base)) * float64(time.Second))
			} else { // ignore packet
				goto read_packet
			}
			p("packet time %v at timer time %v\n", packetTime, self.Timer.Now())

			// check seek
			if self.seekTarget > 0 && packetTime > 0 { // if packet time cannot determined, skip
				if packetTime < self.seekTarget { // seek again
					self.seekNext += self.seekStep
					p("seek again %v\n", self.seekNext)
				} else { // seek ok
					p("seek ok\n")
					self.seekTarget = 0
					self.Timer.Jump(packetTime - self.Timer.Now())
				}
			}

			// decode
			if packet.stream_index == videoIndex { // decode video
				if C.avcodec_decode_video2(vCodecCtx, vFrame, &frameFinished, &packet) < 0 {
					continue // bad packet
				}
				if frameFinished <= 0 {
					goto read_packet // frame not complete
				}
				bufFrame := <-pool        // get frame buffer
				C.sws_scale(scaleContext, // scale
					&vFrame.data[0], &vFrame.linesize[0], 0, vCodecCtx.height,
					&bufFrame.data[0], &bufFrame.linesize[0])
				bufFrame.pts = C.int64_t(packetTime) // set packet time
				self.frameChan <- bufFrame           // push to queue
				p("video frame %v\n", packetTime)

			} else if packet.stream_index == audioIndex { // decode audio
			decode_audio_packet:
				l := C.avcodec_decode_audio4(aCodecCtx, aFrame, &frameFinished, &packet)
				if l < 0 {
					continue // bad packet
				}
				if frameFinished <= 0 {
					goto read_packet // frame not complete
				}
				if frameFinished > 0 { // frame finished
					n := C.swr_convert(resampleContext, resampleBufferp, 4096,
						aFrame.extended_data, aFrame.nb_samples)
					if n != aFrame.nb_samples {
						log.Fatal("audio resample failed")
					}
					self.audioFrames <- &AudioFrame{
						time: packetTime,
						data: C.GoBytes(unsafe.Pointer(resampleBuffer), n*8),
					}
開發者ID:reusee,項目名稱:player,代碼行數:67,代碼來源:decoder.go


注:本文中的C.avcodec_decode_video2函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。