Download the PHP package mimicak/camera-capture without Composer
On this page you can find all versions of the php package mimicak/camera-capture. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mimicak/camera-capture
More information about mimicak/camera-capture
Files in mimicak/camera-capture
Package camera-capture
Short Description A standalone PHP library for capturing still images from IP cameras using snapshot URLs or MJPEG streams. Ideal for surveillance, automation, or IoT applications where lightweight, server-side image capture is needed without browser interaction.
License MIT
Informations about the package camera-capture
CameraCapture PHP Library
The CameraCapture
PHP library provides a flexible and extensible way to capture images from IP cameras, such as Hikvision and generic HTTP snapshot cameras. It uses a factory pattern to support multiple camera types and includes robust error handling, authentication, and MIME type validation.
Features
- Modular Design: Supports multiple camera types (e.g., Hikvision, generic HTTP snapshot) via a factory pattern.
- Extensible: Easily add new camera types by registering them with the
CameraFactory
. - Authentication: Supports HTTP Basic and Digest authentication.
- SSL/TLS Support: Configurable HTTP/HTTPS protocols with SSL verification options.
- Type Safety: Uses constants from
CameraTypes
to avoid configuration errors. - Error Handling: Throws detailed exceptions for network issues, invalid responses, or misconfigurations.
- Flexible Configuration: Supports type-specific options and customizable timeouts.
Requirements
- PHP 7.4 or higher
- PHP extensions:
curl
,fileinfo
- Composer (recommended for autoloading)
Installation
Using Composer (Recommended)
-
Add the library to your project:
Note: Replace
your-vendor/camera-capture
with the actual package name if published to Packagist, or use a custom repository. -
Ensure your
composer.json
includes autoloading: - Run
composer dump-autoload
to generate the autoloader.
Manual Installation
- Clone or download the library to your project directory.
- Place the
src/
directory in your project. - Manually include the required files:
Usage
Basic Example
The following example demonstrates how to initialize the library, add cameras, capture images, and manage camera instances.
Expected Output (assuming cameras are accessible):
Configuration
Each camera configuration is an array with the following keys:
Key | Type | Required | Description | |
---|---|---|---|---|
id |
string | Yes | Unique identifier for the camera. | |
type |
string | Yes | Camera type (e.g., CameraTypes::TYPE_HIKVISION , CameraTypes::TYPE_HTTP_SNAPSHOT ). |
|
brand |
string | Yes | Camera brand (e.g., 'Hikvision', 'Dahua'). | |
host |
string | Yes | Camera IP address or hostname (e.g., '192.168.1.3'). | |
model |
string | null | No | Camera model (e.g., 'DS-2CD2345FWD-I'). |
username |
string | No | Username for camera authentication. | |
password |
string | No | Password for camera authentication (required if username is provided). |
|
protocol |
string | No | Connection protocol ('http' or 'https', defaults to 'http'). | |
options |
array | Yes | Type-specific settings (see below). |
Type-Specific Options
- Hikvision (
CameraTypes::TYPE_HIKVISION
):snapshotChannel
: Channel for snapshot (e.g., '101' for main stream).
- HTTP Snapshot (
CameraTypes::TYPE_HTTP_SNAPSHOT
):snapshotUrlPath
: Path to the snapshot endpoint (e.g., '/cgi-bin/currentpic.cgi').
- Common Options (for both types):
connectTimeout
: Connection timeout in seconds (default: 5).timeout
: Total operation timeout in seconds (default: 10).verifySsl
: Whether to verify SSL certificates (default: true).
Troubleshooting
- Connection Timeouts:
- Ensure the camera’s IP and port are correct (e.g.,
telnet 192.168.1.3 443
for HTTPS). - Try
protocol => 'https'
orprotocol => 'http'
in the config. - Increase
connectTimeout
andtimeout
in theoptions
array. - Set
verifySsl => false
for cameras with self-signed certificates.
- Ensure the camera’s IP and port are correct (e.g.,
- Authentication Errors:
- Verify username and password in the camera’s web interface.
- Ensure the camera supports Basic or Digest authentication.
- Invalid MIME Type:
- Check the snapshot endpoint in a browser to confirm it returns an image.
- Verify the endpoint in the camera’s documentation (e.g.,
/ISAPI/Streaming/channels/101/picture
for Hikvision).
- Logs:
- Errors are logged via
CameraCapture::logError
(defaults to PHP’s error log). - Override
logError
for custom logging (e.g., to a file or external service).
- Errors are logged via
Extending the Library
To add a new camera type:
- Create a class implementing
CameraInterface
(e.g.,AxisCamera
). - Register it in
CameraFactory
:
Testing
- Unit Tests: Use PHPUnit to test
CameraCapture
,CameraFactory
, and camera classes. MockCameraInterface
for isolated tests. - Integration Tests: Test with real cameras to verify snapshot capture.
- Example Test:
License
MIT License (or specify your preferred license).
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
Contact
For support, contact [[email protected]] or open an issue on GitHub.