Capture video from a USB camera using ESP-IDF.
This example demonstrates how to:
- Capture video from a USB camera using the USB Host UVC Driver. https://components.espressif.com/components/espressif/usb_host_uvc
- Stream videos over WiFi using the built-in HTTP server.
- Supports plugging and unplugging USB cameras.
This example enumerates the attached camera descriptors, negotiates the selected resolution and FPS, and starts capturing video.
I based it on this official example.
-
Changed Network connection by example_connect to WiFi connection by handler.
-
Supported VideoStreaming format of UncompressedFormat.
This will allow you to use Logitech C270n and Microsoft LifeCam.
Conversion from UVC_FRAME_FORMAT_YUYV to JPEG used this. -
Changed from TCP transmission to HTTP transmission.
I base it on this.
This example requires any ESP32-S2 or ESP32-S3 with external PSRAM and exposed USB connector attached to USB camera.
ESP module without external PSRAM will fail to initialize.
I used this board.
Note for ESP32S2
In earlier versions of the ESP32-S2 chip, USB transfers can cause SPI data contamination (esp32s2>=ECO1 and esp32s3 do not have this bug).
Software workaround is here.
USB cameras consume a lot of electricity.
If the power supplied to the USB port is insufficient, the camera will not operate and ESP32 resets.
USB connectors are available from AliExpress or eBay.
I used it by incorporating it into a Universal PCB.
Here is a list of USB cameras that support UVC that work with FreeBSD.
From what I've researched, ESP-IDF has limited USB support.
For example, the Logitech C615 works with Linux, but not with ESP-IDF.
I tested with these cameras.
- Logitech C270n -> Success
- Logitech C615 -> Fail
- Logitech QuickCam Pro 9000 -> Fail
- PAPALOOK AF925 -> Fail
- Microdia(Very old model) -> Success
- Microdia MSI Starcam Racer -> Success
- Microsoft LifeCam NX6000 -> Fail
- Microsoft LifeCam Cinema -> Success
- Microsoft LifeCam Studio -> Success
- Microsoft LifeCam HD3000 -> Success
- Microsoft LifeCam HD5000 -> Success
- Microsoft LifeCam HD6000 for Notebooks -> Success
It is very hard to find a camera that works with ESP-IDF.
On this document says that these cameras work with ESP-IDF.
- Logitech C980
- CANYON CNE-CWC2
When usb support provided by ESP-IDF is updated, this issue may eliminate the problem.
Detail is here.
ESP-IDF V5.0 or later.
ESP-IDF V4.4 release branch reached EOL in July 2024.
USB camera connects via USB connector.
The USB port on the ESP32 development board does not function as a USB-HOST.
+---------+ +-------------+ +----------+
|ESP BOARD|==|USB CONNECTOR|==|USB CAMERA|
+---------+ +-------------+ +----------+
ESP BOARD USB CONNECTOR (type A)
+--+
5V -------------> | || VCC
[GPIO19] -------------> | || D-
[GPIO20] -------------> | || D+
GND -------------> | || GND
+--+
git clone https://github.com/nopnop2002/esp-idf-video-streaming
cd esp-idf-video-streaming
idf.py set-target {esp32s2/esp32s3}
idf.py menuconfig
idf.py flash monitor
Some cameras need to change frame size, frame rate and frame format.
-
Build and flash firmware to esp32.
-
For available USB cameras, device information will be displayed and video streaming will begin.
-
For unavailable USB cameras, you will see an error like this.
-
Start your browser and enter the ESP32 IP address and port number in the address bar.
You can use mDNS instead of ESP32 IP addresses.
- At 320x240, 30FPS is the maximum rate regardless of camera capabilities.
- At 640x480, 15FPS is the maximum rate regardless of camera capabilities.
You can use this repository.