This guide covers the complete setup and configuration of UVC (USB Video Class) cameras for video streaming on ESP32-S2/S3. The library supports MJPEG format video streaming with configurable resolution and frame rates.
void frame_callback(uvc_frame_t *frame, void *user_ptr) { // Process frame data ESP_LOGI(TAG, "Frame: %dx%d, format=%d, bytes=%u, seq=%u", frame->width, frame->height, frame->frame_format, frame->data_bytes, frame->sequence); // Frame data available in frame->data // Do NOT block in this callback!}
Never block in the frame callback! The callback runs in the USB task context. Queue frames for processing in another task if needed.
2
Register Callback
void *callback_arg = NULL; // Optional user datausb->uvcCamRegisterCb(&frame_callback, callback_arg);
// Start streamingusb->start();// Wait for camera connectionusb->connectWait(10000); // 10 second timeout// Camera is now streaming...// Stop streamingusb->stop();
Query supported resolutions from the connected camera:
size_t frame_size = 0;size_t frame_index = 0;// Get list sizeusb->uvcCamGetFrameListSize(&frame_size, &frame_index);// Allocate and retrieve listuvc_frame_size_t *frame_list = (uvc_frame_size_t *)malloc(frame_size * sizeof(uvc_frame_size_t));usb->uvcCamGetFrameSize(frame_list);// Print available resolutionsfor (size_t i = 0; i < frame_size; i++) { ESP_LOGI(TAG, "Resolution[%u]: %ux%u, interval: %u-%u (step: %u)", i, frame_list[i].width, frame_list[i].height, frame_list[i].interval_min, frame_list[i].interval_max, frame_list[i].interval_step);}free(frame_list);
2
Suspend Streaming
usb->uvcCamSuspend(NULL);
3
Reset Frame Parameters
// Change to specific resolutionusb->uvcCamFrameReset(640, 480, FRAME_INTERVAL_FPS_15);// Or keep current resolution, only change frame rateusb->uvcCamFrameReset(0, 0, FRAME_INTERVAL_FPS_30);
Setting both width and height to 0 means no change to resolution, only frame interval is updated.
4
Resume Streaming
usb->uvcCamResume(NULL);
The camera will now stream with the new configuration.