bertparx
Posts: 2
Joined: Sun Jan 13, 2019 1:48 am

Help controlling the quality of JPEG hardware encoding.

Sun Jan 13, 2019 2:53 am

I have code that does a jpeg encode using the hardware encoder. How do you control the quality of the encoder?

The following is the code I am using to setup the ports for the encode:

Code: Select all

	OMX_INIT_STRUCTURE(mEncoder_portdef);
	
	printf("JpegEncoder::JpegEncoder - Configure: JPEG encoder input port\n");
	// Input port definition
	mEncoder_portdef.nPortIndex=340; // Input port
	if(OMX_GetParameter(mEncoderHandle, OMX_IndexParamPortDefinition, &mEncoder_portdef) != OMX_ErrorNone)
	{
		printf("OMX_GetParameter(1) - Failed to get port definition for encoder input port 340\n");
		return;
	}
	mEncoder_portdef.format.image.nFrameWidth=IMAGE_WIDTH;
	mEncoder_portdef.format.image.nFrameHeight=IMAGE_HEIGHT;
	mEncoder_portdef.format.image.nSliceHeight=16;
	mEncoder_portdef.format.image.nStride=0;
	mEncoder_portdef.format.image.bFlagErrorConcealment=OMX_FALSE;
	mEncoder_portdef.format.image.eColorFormat=OMX_COLOR_Format24bitBGR888;
	mEncoder_portdef.format.image.eCompressionFormat=OMX_IMAGE_CodingUnused;
	mEncoder_portdef.nBufferSize=IMAGE_WIDTH*mEncoder_portdef.format.image.nSliceHeight*IMAGE_CHANNELS;
	if(OMX_SetParameter(mEncoderHandle, OMX_IndexParamPortDefinition, &mEncoder_portdef) != OMX_ErrorNone)
	{
		printf("OMX_SetParameter - Failed to set port definition for encoder input port 340\n");
		return;
	}
	OMX_INIT_STRUCTURE(mEncoder_portdef);
	mEncoder_portdef.nPortIndex=340; // Input port
	if(OMX_GetParameter(mEncoderHandle, OMX_IndexParamPortDefinition, &mEncoder_portdef) != OMX_ErrorNone)
	{
		printf("OMX_GetParameter(2) - Failed to get port definition for encoder input port 340\n");
		return;
	}
	
	printf("JpegEncoder::JpegEncoder - Configure: JPEG encoder output port\n");
	// Output port definition
	OMX_INIT_STRUCTURE(mEncoder_portdef);
	mEncoder_portdef.nPortIndex=341; // Output port
	if(OMX_GetParameter(mEncoderHandle, OMX_IndexParamPortDefinition, &mEncoder_portdef) != OMX_ErrorNone)
	{
		printf("OMX_GetParameter - Failed to get port definition for encoder output port 341\n");
		return;
	}
	mEncoder_portdef.nPortIndex=341; // Output port
	mEncoder_portdef.format.image.nFrameWidth=IMAGE_WIDTH;
	mEncoder_portdef.format.image.nFrameHeight=IMAGE_HEIGHT;
	mEncoder_portdef.format.image.bFlagErrorConcealment=OMX_FALSE;
	mEncoder_portdef.format.image.eColorFormat=OMX_COLOR_Format24bitRGB888;
	mEncoder_portdef.format.image.eCompressionFormat=OMX_IMAGE_CodingJPEG;
	if(OMX_SetParameter(mEncoderHandle, OMX_IndexParamPortDefinition, &mEncoder_portdef) != OMX_ErrorNone)
	{
		printf("OMX_SetParameter - Failed to set port definition for encoder output port 341\n");
		return;
	}

Return to “OpenMAX”