Decoding MJPEG From USB Camera (ESP32-P4)
Posted: Tue May 20, 2025 7:22 pm
I have an ESP32-P4 Function Board that I'm using to decode MJPEG data from a USB Logitech C270 camera. I have the UVC demo working and can see MJPEG images at about 25FPS over WiFi to a PC. I am trying to add code to display the video on the LCD that is connected to the eval board. When I attempt to use the esp_new_jpeg component (https://components.espressif.com/compon ... p_new_jpeg) I get the following debug output error messages:
I (20421) example: Streaming...
E (20791) jpeg.decoder: JPEG_RESTART_INTERVAL configured by the software is non-0 but the RST marker cannot be parsed by the decoder
E (20791) jpeg.decoder: the number of data units obtained after decoding a frame of image is different from the number of data units calculated based on the image resolution configured by the software
E (20811) dma2d: dma2d_force_end(968): transaction not in-flight
E (20811) MPEG_DECODER: Fail to decode frame ret -1
I manually parsed the image header information:
SOI: FF D8
APPO MARKER: FF E0
LENGTH: 00 21
ID: 41 56 49 31 00
JFIF VER: 01 01
DENSITY UNITS: 01
X DENSITY: 00 78
Y DENSITY: 00 78
XTHUMBNAIL: 00
YTHUMBNAIL: 00
00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00
DQT: FF DB
LENGTH: 00 43
QT INFO: 00 (8 BIT TABLE ID 0)
08 05 06 07 06 05 08 07
06 07 09 08 08 09 0C 14
0D 0C 0B 0B 0C 18 11 12
0E 14 1D 19 1E 1E 1C 19
1C 1F 20 24 2E 27 20 22
2B 22 1B 1C 28 34 28 2B
2F 31 33 34 33 1F 26 38
3C 38 32 3C 2E 32 33 31
DQT: FF DB
LENGTH: 00 43
QT INFO: 01 (8 BIT TABLE ID 1)
08 09 09 0C 0A 0C 17 0D
0D 0D 17 31 21 1C 21 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
DEFINE RESTART INTERVAL: FF DD
LENGTH: 00 04
RESTART INTERVAL 16 MCUS: 00 0A
APP0 MARKER: FF E0
LENGTH: 00 04
00 00 // not sure the purpose of this data
START OF FRAME: FF C0
LENGTH: 00 11
PRECISION: 08
IMAGE HEIGHT: 01 E0
IMAGE WIDTH: 02 80
NUMBER OF COMPONENTS: 03
COMPONENT DATA: 01 21 00 02 11 01 03 11 01
IMAGE DATA: FF DA
LENGTH OF SOS SEGMENT: 00 0C
NUMBER OF COMPONENTS: 03
COMPONENT INFO: 01 00 02 11 03 11
SPECTRAL SELECTION PARAMS: 00 3F 00
COMPRESSED IMAGE DATA:
F0 1A 28 00...
In the image data, I can see the RST markers from FFD0 to FFD7 being repeated throughout the image.
I feel that the data is good, as I send the exact same data to the WiFi server to send to the PC. PC video looks good.
Any ideas?
I (20421) example: Streaming...
E (20791) jpeg.decoder: JPEG_RESTART_INTERVAL configured by the software is non-0 but the RST marker cannot be parsed by the decoder
E (20791) jpeg.decoder: the number of data units obtained after decoding a frame of image is different from the number of data units calculated based on the image resolution configured by the software
E (20811) dma2d: dma2d_force_end(968): transaction not in-flight
E (20811) MPEG_DECODER: Fail to decode frame ret -1
I manually parsed the image header information:
SOI: FF D8
APPO MARKER: FF E0
LENGTH: 00 21
ID: 41 56 49 31 00
JFIF VER: 01 01
DENSITY UNITS: 01
X DENSITY: 00 78
Y DENSITY: 00 78
XTHUMBNAIL: 00
YTHUMBNAIL: 00
00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00
DQT: FF DB
LENGTH: 00 43
QT INFO: 00 (8 BIT TABLE ID 0)
08 05 06 07 06 05 08 07
06 07 09 08 08 09 0C 14
0D 0C 0B 0B 0C 18 11 12
0E 14 1D 19 1E 1E 1C 19
1C 1F 20 24 2E 27 20 22
2B 22 1B 1C 28 34 28 2B
2F 31 33 34 33 1F 26 38
3C 38 32 3C 2E 32 33 31
DQT: FF DB
LENGTH: 00 43
QT INFO: 01 (8 BIT TABLE ID 1)
08 09 09 0C 0A 0C 17 0D
0D 0D 17 31 21 1C 21 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
31 31 31 31 31 31 31 31
DEFINE RESTART INTERVAL: FF DD
LENGTH: 00 04
RESTART INTERVAL 16 MCUS: 00 0A
APP0 MARKER: FF E0
LENGTH: 00 04
00 00 // not sure the purpose of this data
START OF FRAME: FF C0
LENGTH: 00 11
PRECISION: 08
IMAGE HEIGHT: 01 E0
IMAGE WIDTH: 02 80
NUMBER OF COMPONENTS: 03
COMPONENT DATA: 01 21 00 02 11 01 03 11 01
IMAGE DATA: FF DA
LENGTH OF SOS SEGMENT: 00 0C
NUMBER OF COMPONENTS: 03
COMPONENT INFO: 01 00 02 11 03 11
SPECTRAL SELECTION PARAMS: 00 3F 00
COMPRESSED IMAGE DATA:
F0 1A 28 00...
In the image data, I can see the RST markers from FFD0 to FFD7 being repeated throughout the image.
I feel that the data is good, as I send the exact same data to the WiFi server to send to the PC. PC video looks good.
Any ideas?