|
| 1 | +# Sony Sony Camera Manager (Python) |
| 2 | + |
| 3 | +A comprehensive, high-level Python client for controlling Sony cameras (like the ZV-E10, A7RIII, etc.) via the legacy **Camera Remote API** (JSON-RPC over HTTP). |
| 4 | + |
| 5 | +## 1) Overview |
| 6 | +This package is designed to be the "best ever" implementation for Sony's legacy API, focusing on: |
| 7 | +- **Capability-First Architecture**: Always probe what the camera supports before calling. |
| 8 | +- **Dynamic Method Surface**: Use `cam.do("methodName", ...)` for any method not explicitly wrapped. |
| 9 | +- **Robust Liveview**: High-performance binary stream parser for JPEG frames. |
| 10 | +- **Comprehensive Actions**: Full catalog of Sony API methods as constants. |
| 11 | + |
| 12 | +## 2) Key Features |
| 13 | +- **Auto-Discovery**: Discover cameras on the network using SSDP. |
| 14 | +- **Full Exposure Control**: Aperture, Shutter Speed, ISO, Exposure Compensation, etc. |
| 15 | +- **Advanced Focus**: Focus modes, Touch AF position, Tracking Focus. |
| 16 | +- **Live View**: Frame-by-frame JPEG extraction from the binary stream. |
| 17 | +- **Event Monitoring**: Long-polling support to track battery, status, and settings changes. |
| 18 | + |
| 19 | +## 3) Installation |
| 20 | +```bash |
| 21 | +pip install sony-camera-manager |
| 22 | +# For developers |
| 23 | +pip install sony-camera-manager[dev] |
| 24 | +``` |
| 25 | + |
| 26 | +## 4) Usage |
| 27 | + |
| 28 | +### 4.1 Discovery & Initialization |
| 29 | +```python |
| 30 | +from sony_camera_manager import SonyCameraClient |
| 31 | + |
| 32 | +# Auto-discovery |
| 33 | +host = SonyCameraClient.discover() |
| 34 | +if not host: |
| 35 | + host = "192.168.122.1" # Fallback |
| 36 | + |
| 37 | +cam = SonyCameraClient(host=host) |
| 38 | +``` |
| 39 | + |
| 40 | +### 4.2 Probing Capabilities (The Sony Way) |
| 41 | +Sony cameras change their available APIs based on their current mode (e.g., Movie vs Still). |
| 42 | +```python |
| 43 | +# Check what's supported by the hardware |
| 44 | +print(cam.get_api_list()) |
| 45 | + |
| 46 | +# Check what's available in the current mode |
| 47 | +print(cam.get_available_api_list()) |
| 48 | + |
| 49 | +# Generic capability helpers |
| 50 | +supported_iso = cam.get_supported("IsoSpeedRate") |
| 51 | +available_f_numbers = cam.get_available("FNumber") |
| 52 | +``` |
| 53 | + |
| 54 | +### 4.3 High-Level API Examples |
| 55 | +```python |
| 56 | +from sony_camera_manager.models import ExposureMode |
| 57 | + |
| 58 | +# Set Manual Mode |
| 59 | +cam.set_shoot_mode(ExposureMode.MANUAL) |
| 60 | + |
| 61 | +# Adjust Exposure |
| 62 | +cam.set_f_number("5.6") |
| 63 | +cam.set_shutter_speed("1/100") |
| 64 | +cam.set_iso_speed_rate("400") |
| 65 | + |
| 66 | +# Focus tracking |
| 67 | +cam.act_tracking_focus(0.5, 0.5) # Center |
| 68 | + |
| 69 | +# Take a photo and wait for result |
| 70 | +image_urls = cam.await_take_picture() |
| 71 | +``` |
| 72 | + |
| 73 | +### 4.4 Liveview Stream (OpenCV) |
| 74 | +```python |
| 75 | +import cv2 |
| 76 | +import numpy as np |
| 77 | + |
| 78 | +for jpeg in cam.get_liveview_stream(): |
| 79 | + img = cv2.imdecode(np.frombuffer(jpeg, np.uint8), cv2.IMREAD_COLOR) |
| 80 | + cv2.imshow('Sony Liveview', img) |
| 81 | + if cv2.waitKey(1) == ord('q'): break |
| 82 | + |
| 83 | +cv2.destroyAllWindows() |
| 84 | +cam.stop_liveview() |
| 85 | +``` |
| 86 | + |
| 87 | +## 5) Package Structure |
| 88 | +- `SonyCameraClient`: Main interface for controlling the camera. |
| 89 | +- `transport`: Low-level JSON-RPC communication handler (internal). |
| 90 | +- `models`: Dataclasses and Enums for Camera state and settings. |
| 91 | +- `exceptions`: Custom exception hierarchy (CameraError, ConnectionError, etc.). |
| 92 | + |
| 93 | +## 6) References |
| 94 | +- [Sony Camera Remote API Documentation](https://developer.sony.com/develop/cameras/) |
| 95 | +- [libsonyapi](https://github.com/petabite/libsonyapi) (Method catalog inspiration) |
| 96 | +- [pysony](https://github.com/Bloodevil/sony_camera_api) (Protocol reference) |
0 commit comments