UVCCamera icon indicating copy to clipboard operation
UVCCamera copied to clipboard

Modify the code to increase the frame rate to 30

Open GoldenStrawberry opened this issue 6 years ago • 7 comments

I changed the code inUVCPreview. cpp to convert MJPEG directly to RGBX. I'm calling the function uvc_mjpeg2rgbx in theframe_mjpepe.c library,The frame rate can reach 30fps , but sometimes the conversion fails, and the code goes wrong below: dinfo.err = jpeg_std_error(&jerr.super); jerr.super.error_exit = _error_exit; if (setjmp(jerr.jmp)) { goto fail; } The phenomenon of flashing appears, which seriously affects the quality of the picture. How to solve this problem?

GoldenStrawberry avatar Aug 17 '18 08:08 GoldenStrawberry

https://github.com/saki4510t/UVCCamera/issues/417

I don't know if you solved this problem? I have the same doubts as you.

hnlbxb2004 avatar Oct 29 '18 03:10 hnlbxb2004

Has anyone solved this issue?

zipswich avatar Mar 14 '22 14:03 zipswich

Does this issue solved? Encounter the same issue, too.

danji avatar Dec 04 '23 04:12 danji

Found that uvc_mjpeg2rgbx used wrong out_step while jpeg_read_scanlines. Modify code like below can solve the flashing issue.

jpeg_start_decompress(&dinfo);

	// local copy, assign data/out_step after out set
	uint8_t *data = out->data;
	const int out_step = out->step;
     ... 
    if (LIKELY(dinfo.output_height == out->height)) {

danji avatar Dec 07 '23 07:12 danji

@danji Thank you for sharing the solution. I am not clear what you meant. The current code is the following:

	uint8_t *data = out->data;
	const int out_step = out->step;
	if (LIKELY(dinfo.output_height == out->height)) {
		for (; dinfo.output_scanline < dinfo.output_height ;) {
			buffer[0] = data + (lines_read) * out_step;
			for (i = 1; i < MAX_READLINE; i++)
				buffer[i] = buffer[i-1] + out_step;
			num_scanlines = jpeg_read_scanlines(&dinfo, buffer, MAX_READLINE);
			lines_read += num_scanlines;
		}
		out->actual_bytes = in->width * in->height * 3;	// XXX
	}

Did you mean to move the first 2 lines to after the if block?

zipswich avatar Dec 07 '23 14:12 zipswich

Move code in uvc_mjpeg2rgbx 393-394 after 434, then you will use correct out-step to decode the jpeg into buffer.

danji avatar Dec 07 '23 16:12 danji

Thank you.

zipswich avatar Dec 07 '23 22:12 zipswich