Ejemplo n.º 1
0
/// obtain required buffers
func (this *TAppEncTop) xGetBuffer() *TLibCommon.TComPicYuv {
	//assert( this.m_iGOPSize > 0 );
	var rpcPicYuvRec *TLibCommon.TComPicYuv

	// org. buffer
	if this.m_cListPicYuvRec.Len() == this.m_iGOPSize {
		e := this.m_cListPicYuvRec.Front()
		rpcPicYuvRec = e.Value.(*TLibCommon.TComPicYuv)
		this.m_cListPicYuvRec.Remove(e)
	} else {
		rpcPicYuvRec = TLibCommon.NewTComPicYuv()

		rpcPicYuvRec.Create(this.m_iSourceWidth, this.m_iSourceHeight, this.m_uiMaxCUWidth, this.m_uiMaxCUHeight, this.m_uiMaxCUDepth)
	}
	this.m_cListPicYuvRec.PushBack(rpcPicYuvRec)

	return rpcPicYuvRec
}
Ejemplo n.º 2
0
func (this *TAppEncTop) Encode() (err error) { ///< main encoding function
	bitstreamFile, err := os.Create(this.m_pchBitstreamFile)
	if err != nil {
		fmt.Printf("\nfailed to open bitstream file `%s' for writing\n", this.m_pchBitstreamFile)
		return err
	}
	defer bitstreamFile.Close()

	pcPicYuvOrg := TLibCommon.NewTComPicYuv()
	//var pcPicYuvRec *TLibCommon.TComPicYuv;

	// initialize internal class & member variables
	this.xInitLibCfg()
	this.xCreateLib()
	this.xInitLib()

	// main encoder loop
	iNumEncoded := 0
	bEos := false

	outputAccessUnits := TLibEncoder.NewAccessUnits() ///< list of access units to write out.  is populated by the encoding process

	// allocate original YUV buffer
	pcPicYuvOrg.Create(this.m_iSourceWidth, this.m_iSourceHeight, this.m_uiMaxCUWidth, this.m_uiMaxCUHeight, this.m_uiMaxCUDepth)

	for !bEos {
		// get buffers
		this.xGetBuffer() //pcPicYuvRec =

		// read input YUV file
		this.m_cTVideoIOYuvInputFile.Read(pcPicYuvOrg, this.m_aiPad[:])

		// increase number of received frames
		this.m_iFrameRcvd++

		bEos = (this.m_iFrameRcvd == this.m_framesToBeEncoded)

		flush := false
		// if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
		if this.m_cTVideoIOYuvInputFile.IsEof() {
			flush = true
			bEos = true
			this.m_iFrameRcvd--
			this.m_cTEncTop.GetEncCfg().SetFramesToBeEncoded(this.m_iFrameRcvd)
		}

		// call encoding function for one frame
		if flush {
			this.m_cTEncTop.Encode(bEos, nil, this.m_cListPicYuvRec, outputAccessUnits, &iNumEncoded)
		} else {
			this.m_cTEncTop.Encode(bEos, pcPicYuvOrg, this.m_cListPicYuvRec, outputAccessUnits, &iNumEncoded)
		}
		// write bistream to file if necessary
		if iNumEncoded > 0 {
			this.xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits)
			outputAccessUnits.Init()
		}
	}

	this.m_cTEncTop.PrintSummary()

	// delete original YUV buffer
	pcPicYuvOrg.Destroy()
	//delete pcPicYuvOrg;
	pcPicYuvOrg = nil

	// delete used buffers in encoder class
	this.m_cTEncTop.DeletePicBuffer()

	// delete buffers & classes
	this.xDeleteBuffer()
	this.xDestroyLib()

	this.printRateSummary()

	return nil
}