HomeForumSourceResearchGuide
Sign in to contribute to source. how it works
Component media.video.Encoder:h264 by barry
expand copy to clipboardexpand
interface H264Lib {
	int newDecoder()
	PixelMapYUV[] decode(int handle, byte encoded[], WH sz)
	void destroyDecoder(int handle)

	int newEncoder(int w, int h, int fps, KeyValue options[])
	EncodedFrame[] encode(int handle, PixelMapYUV frame, bool keyFrame)
	EncodedFrame[] finishEncode(int handle)
	void destroyEncoder(int handle)
}

component provides Encoder:h264(Destructor) requires native H264Lib lib {

	int handle
	WH sz

	Encoder:Encoder(store WH size, int fps, opt KeyValue options[])
		{
		handle = lib.newEncoder(size.width, size.height, fps, options)
		if (handle == 0) throw new Exception("encoder initialisation failed")
		sz = size
		}
	
	EncodedFrame[] Encoder:encode(PixelMapYUV frame, bool keyFrame)
		{
		return lib.encode(handle, frame, keyFrame)
		}
	
	EncodedFrame[] Encoder:finish()
		{
		return lib.finishEncode(handle)
		}
	
	void Destructor:destroy()
		{
		if (handle != 0) lib.destroyEncoder(handle)
		}

}
Revision history
To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n media.video.Encoder:h264 -m "reason for update" -u yourUsername
Version 2 (this version) by barry
Notes for this version: Adds a method to pass in optional encoder parameters
Version 1 by barry