The ESP32-CAM streaming RTSP video to VLC is one of the most practical IoT camera projects. With less than ₹500 in hardware, you can build a Wi-Fi video camera that streams live video to any VLC player, smartphone, or browser on your home or office network. This step-by-step guide covers the complete ESP32-CAM setup, Arduino code, and VLC configuration for Indian makers.
Table of Contents
- Hardware: ESP32-CAM Overview
- Arduino IDE Setup for ESP32-CAM
- RTSP Streaming Code
- Viewing in VLC
- Browser-Based Streaming Alternative
- SD Card Recording
- India-Specific Network Tips
- Frequently Asked Questions
Hardware: ESP32-CAM Overview
The ESP32-CAM is a ₹250–450 module combining an ESP32-S chip with an OV2640 2MP camera sensor and microSD card slot. It’s one of the most cost-effective ways to add video streaming to any IoT project.
Key Specs
- MCU: ESP32-S (single-core), 240 MHz
- Camera: OV2640, up to 2MP (1600×1200)
- Flash: 4MB
- PSRAM: 4MB (required for video buffering)
- Wi-Fi: 802.11b/g/n 2.4 GHz
- MicroSD: SPI, up to 4GB reliable (some 16GB cards work)
Required Hardware
- ESP32-CAM module: ₹250–450
- FTDI USB-to-TTL programmer: ₹80–200 (needed for flashing — ESP32-CAM has no USB)
- Jumper wires
- 5V 1A USB power supply
Arduino IDE Setup for ESP32-CAM
// Arduino IDE Setup for ESP32-CAM:
// 1. Add ESP32 board manager URL in Preferences:
// https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
// 2. Tools > Board > ESP32 Arduino > AI Thinker ESP32-CAM
// 3. Upload Speed: 115200
// 4. Flash Frequency: 80MHz
// 5. Flash Mode: QIO
// Wiring for programming:
// FTDI GND -> ESP32-CAM GND
// FTDI TX -> ESP32-CAM U0R (RXD)
// FTDI RX -> ESP32-CAM U0T (TXD)
// FTDI 5V -> ESP32-CAM 5V
// GPIO0 -> GND (programming mode, remove after upload)
RTSP Streaming Code
The simplest approach uses the micro-RTSP-server library:
#include "esp_camera.h"
#include
#include "OV2640.h"
#include "SimStreamer.h"
#include "OV2640Streamer.h"
#include "CRtspSession.h"
// AI Thinker ESP32-CAM pin definitions
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
const char* ssid = "YOUR_WIFI_SSID"; // Change to your network
const char* password = "YOUR_WIFI_PASS"; // Change to your password
OV2640 cam;
WiFiServer rtspServer(554);
void setup() {
Serial.begin(115200);
// Camera configuration
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = FRAMESIZE_VGA; // 640x480 for smooth RTSP
config.jpeg_quality = 15;
config.fb_count = 2;
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed: 0x%x", err);
return;
}
cam.init(config);
// Connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("ESP32-CAM IP: rtsp://");
Serial.print(WiFi.localIP());
Serial.println(":554/mjpeg/1");
rtspServer.begin();
}
CStreamer *streamer;
CRtspSession *session;
WiFiClient client;
void loop() {
uint32_t msecPerFrame = 100; // 10 FPS
static uint32_t lastimage = millis();
if (rtspServer.hasClient()) {
client = rtspServer.accept();
streamer = new OV2640Streamer(&client, cam);
session = new CRtspSession(&client, streamer);
Serial.printf("RTSP client connected: %s
",
client.remoteIP().toString().c_str());
}
if (session) {
session->handleRequests(0);
uint32_t now = millis();
if (now > lastimage + msecPerFrame || now broadcastCurrentFrame(now);
lastimage = now;
}
if (!session->m_stopped) return;
delete session; session = nullptr;
delete streamer; streamer = nullptr;
client.stop();
}
}
Viewing in VLC
Steps to view ESP32-CAM RTSP stream in VLC:
1. Open VLC Media Player
2. Go to Media > Open Network Stream (Ctrl+N)
3. Enter URL: rtsp://[ESP32-CAM-IP]:554/mjpeg/1
(Replace [ESP32-CAM-IP] with the IP shown in Serial Monitor)
4. Click Play
Alternatively via command line:
vlc rtsp://192.168.1.105:554/mjpeg/1
For Android (VLC for Android, free on Play Store):
Open VLC > Network > New stream
Enter same RTSP URL
Note: ESP32-CAM and your viewing device must be on the same
WiFi network. For remote viewing, set up port forwarding on
your router (port 554 TCP) - but be aware of security implications.
Browser-Based Streaming Alternative
The easiest ESP32-CAM streaming uses the built-in CameraWebServer example from Arduino IDE (Examples > ESP32 > Camera > CameraWebServer). This streams MJPEG over HTTP — viewable directly in any browser by visiting http://[ESP32-IP]/. No VLC needed. Frame rate is typically 5–15 FPS at VGA resolution on Indian home Wi-Fi networks.
SD Card Recording
#include "SD_MMC.h"
// Save JPEG frames to SD card
void saveFrameToSD(camera_fb_t *fb) {
static int fileNum = 0;
char filename[32];
sprintf(filename, "/image_%04d.jpg", fileNum++);
File file = SD_MMC.open(filename, FILE_WRITE);
if (!file) {
Serial.println("SD write failed");
return;
}
file.write(fb->buf, fb->len);
file.close();
Serial.printf("Saved: %s (%d bytes)
", filename, fb->len);
}
// In setup(): SD_MMC.begin()
// Then call saveFrameToSD(cam.getFrame()) in loop
India-Specific Network Tips
- BSNL/MTNL routers: Some older BSNL routers block RTSP port 554. Try HTTP streaming (CameraWebServer example) on port 80 if RTSP doesn’t work.
- JioFi hotspot: ESP32-CAM connects reliably to JioFi 4G hotspots — useful for field deployments. Static IP assignment via JioFi web interface helps with consistent RTSP URLs.
- Static IP configuration: Assign a static IP to your ESP32-CAM in your router’s DHCP settings so the RTSP URL doesn’t change across reboots.
- Range: ESP32-CAM’s Wi-Fi range is approximately 20–30m indoors in a typical Indian concrete building. Use a Wi-Fi repeater for longer distances.
Frequently Asked Questions
Why is my ESP32-CAM stream choppy or disconnecting?
Common causes: (1) Power supply insufficient — ESP32-CAM needs 5V at least 500mA; cheap phone chargers often drop voltage under load; use a quality 5V 1A supply. (2) Wi-Fi signal too weak — the ESP32-CAM’s tiny PCB antenna has short range, especially through thick Indian concrete walls; move closer to the router or use an external antenna variant. (3) Buffer overflow — reduce resolution to QVGA (320×240) or SVGA (800×600) if VGA causes issues.
Can I add IR night vision to ESP32-CAM?
The standard ESP32-CAM has an OV2640 sensor that is sensitive to near-infrared light. Adding 850nm IR LEDs (₹5–20 each) around the camera provides illumination invisible to the human eye but visible to the camera. The camera will show a black-and-white image in IR-illuminated darkness. For better night performance, use a Pi NoIR camera with a proper IR illuminator instead.
What is the resolution and frame rate of ESP32-CAM?
ESP32-CAM at VGA (640×480): approximately 10–15 FPS via RTSP, 15–20 FPS via HTTP MJPEG. At QVGA (320×240): 20–30 FPS. Maximum resolution (UXGA, 1600×1200) at only 1–3 FPS — practical only for still image capture. The single-core ESP32-S processor limits real-time video to VGA or lower resolutions.
Add comment