Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

Delphi_WebCam_Component

An easy to use Drag and drop VCL WebCam component!

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

🎥 Delphi Webcam Capture Component

Professional DirectShow Webcam Capture Component for Delphi VCL

High-performance • Asynchronous • Thread-safe • Easy drop-in integration

A lightweight TWebcamCapture component that captures webcam frames as TBytes and delivers them safely on the main thread via events. Designed for smooth UI behavior and straightforward integration in Delphi VCL apps.

🚀 Overview

  • Device enumeration
  • Camera selection by index
  • Configurable resolution and frame rate
  • JPEG or BMP frame output
  • Threaded capture pipeline (UI stays responsive)
  • Main-thread frame delivery via event callbacks
  • Snapshot access via GetSingleFrame

⭐ Key Features

🎥 Capture

  • Capture webcam frames continuously
  • Output frames as raw TBytes (JPEG or BMP)
  • Track actual negotiated resolution and frame count

⚙️ Configuration

  • DeviceIndex, Width, Height, FrameRate
  • ImageFormat (wifJPEG or wifBMP)
  • JPEGQuality (1..100)

🧵 Threading & Stability

  • Dedicated capture thread for DirectShow/COM work
  • UI callback delivery through queued main-thread events
  • Startup handshake to avoid false “active” state
  • Frame dispatch backpressure (prevents runaway UI queue)

🧩 Delphi Integration

  • Registered as TWebcamCapture on the Webcam palette
  • Standard VCL component usage pattern
  • Works cleanly with dropped VCL controls (TImage, TTimer, etc.)

📦 Repository Contents

  • WebcamCapture.pas — Core component implementation.
  • WebcamCaptureReg.pas — IDE component registration.
  • WebcamComponents.dpk / .dproj — Package project.
  • Demos/Basic Demo — Local preview, device selection, snapshot save.
  • Demos/Network Webcam Streaming Demo — Webcam streaming over network (uses NetCom7 sources).

✅ Requirements

Core Component

  • Delphi VCL (tested with Delphi 12.2 Athens toolchain)
  • Windows desktop target
  • DirectShow-capable system with camera drivers

Optional (Network Demo Only)

  • NetCom7 source path configured for demo build

🔧 Installation

  1. Open WebcamComponents.dproj in Delphi.
  2. Build the package for your target (Win32 and/or Win64).
  3. Install package in IDE.
  4. Drop TWebcamCapture from the Webcam component palette.

⚡ Quick Start (Basic Usage)

1) Drop components on a VCL form

  • TWebcamCapture (WebcamCapture1)
  • TImage (Image1)

2) Configure and start

pascal
procedure TForm1.FormCreate(Sender: TObject);
begin
  WebcamCapture1.DeviceIndex := 0;
  WebcamCapture1.Width := 640;
  WebcamCapture1.Height := 480;
  WebcamCapture1.FrameRate := 30;
  WebcamCapture1.ImageFormat := wifJPEG;
  WebcamCapture1.JPEGQuality := 85;
  WebcamCapture1.Active := True;
end;
procedure TForm1.WebcamCapture1FrameReceived(Sender: TObject;
  const FrameData: TBytes; Width, Height: Integer);
var
  S: TMemoryStream;
begin
  if Length(FrameData) = 0 then Exit;

  S := TMemoryStream.Create;
  try
    S.WriteBuffer(FrameData[0], Length(FrameData));
    S.Position := 0;
    Image1.Picture.LoadFromStream(S);
  finally
    S.Free;
  end;
end;

📚 API Reference

Properties

PropertyTypeDescription
ActiveBooleanStart/stop capture
DeviceIndexIntegerSelected camera index
Width / HeightIntegerRequested capture size
FrameRateIntegerRequested FPS
ImageFormatTWebcamImageFormatwifJPEG or wifBMP
JPEGQualityIntegerJPEG quality (1..100)
ActualWidth / ActualHeightIntegerNegotiated capture size
FrameCountInt64Number of captured frames
LastFrameDataTBytesLast captured encoded frame
### Methods
MethodDescription
GetDevicesReturns available camera list
RefreshDevicesRe-enumerates cameras
GetSupportedResolutionsQueries camera-supported resolutions
StartCapture / StopCaptureManual control
GetSingleFrameReturns last captured frame bytes
### Events
EventDescription
OnFrameReceivedNew frame (TBytes, width, height)
OnCaptureStartedCapture session started
OnCaptureStoppedCapture session stopped
OnCaptureErrorCapture error text
OnDeviceListChangedDevice count changed
## 🧪 Demos

Basic Demo

  • Device enumeration and selection
  • Live preview
  • JPEG/BMP switch
  • Snapshot saving
  • FPS display
### Network Webcam Streaming Demo
  • Uses NetCom7 TncServerSource / TncClientSource
  • Broadcasts captured frames to remote clients
  • Shows practical frame transport over TCP
## 🧱 Dependencies

Core Component

  • No third-party runtime DLL required by this repo itself.
  • Uses Windows COM/DirectShow APIs and system codecs.
Important Note: DirectShow availability and camera behavior can vary by machine, driver, and Windows media feature setup. ## ⚠️ Compatibility Notes
  • Windows desktop only (VCL + WinAPI/COM)
  • Win32 and Win64 build targets supported
  • Not intended for FMX/mobile platforms
  • Camera privacy settings can block access if not allowed
## 🛠️ Troubleshooting

“No webcam devices detected”

  • Verify camera is connected and not disabled
  • Check Device Manager
  • Check Windows camera permissions
### “Failed to build capture graph” or startup timeout
  • Another app may already own the camera
  • Driver may not expose expected DirectShow path
  • Try a different DeviceIndex or lower requested resolution/FPS
### Frame display issues
  • Ensure OnFrameReceived handler is correctly assigned
  • Use Image1.Picture.LoadFromStream(...) for TBytes payloads
## 👨‍💻 Author BitmasterXor If this component helps your Delphi workflow, consider starring the repository. ⭐