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

Help controlling the quality of JPEG hardware encoding.

Sun Jan 13, 2019 2:06 am

I have written software that encodes to JPEG for a MJPEG streamer. It works very well and I have the camera capture and the encoding interleaved.

My question is how do I control the quality of the encoder in order control bandwidth? Right now I am using about 12Mbps and I would like to have more control over that while maintaining image size. I understand this will reduce the quality of the images too.

I am setting up the encoding input and output ports as follows:

Code: Select all

	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;
	}

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7026
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Help controlling the quality of JPEG hardware encoding.

Sun Jan 13, 2019 8:11 am

OMX_IndexParamQFactor, /**< reference: OMX_IMAGE_PARAM_QFACTORTYPE */
https://github.com/raspberrypi/userland ... MX_Index.h
It's a standard index, so covered in the IL spec.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “OpenMAX”