Name | picamera2-webstream JSON |
Version |
0.2.6
JSON |
| download |
home_page | None |
Summary | A Flask-based web streaming solution for Raspberry Pi cameras using PiCamera2 |
upload_time | 2024-11-21 16:59:32 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | MIT License Copyright (c) 2024 Ian Ross Williams Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
raspberry pi
camera
streaming
picamera2
ffmpeg
flask
|
VCS |
|
bugtrack_url |
|
requirements |
flask
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# PiCamera2 Web Streamer
A Flask-based web streaming solution for Raspberry Pi cameras using PiCamera2. Stream your Raspberry Pi camera feed securely over HTTPS with minimal latency.
## Features
- Real-time MJPEG streaming over HTTPS
- Adaptive frame rate based on client connections
- Clean shutdown handling
- Mobile-responsive web interface
- Thread-safe implementation
- Configurable camera parameters
- Resource-efficient with multiple client support
## Dependencies
A split installation approach ensures compatibility with Raspberry Pi OS while keeping application-specific dependencies isolated.
### System Packages (installed via apt)
- python3-libcamera
- python3-picamera2
- python3-opencv
- python3-numpy
### Virtual Environment Packages (installed via pip)
- flask
- Additional Python-only dependencies
## Installation
### Via pip
```bash
pip install picamera2-webstream
```
## Quick Installation
For a quick automated installation:
```bash
git clone https://github.com/glassontin/picamera2-webstream.git
cd picamera2-webstream
```
For an ffmpeg based webstream:
```
./install_ffmpeg.sh
```
For a picamera2 OpenCV based webstream use:
```
./install_picamera.sh
```
The installation script will:
1. Install all required system dependencies
2. Enable the camera interface
3. Set up a Python virtual environment
4. Install Python package dependencies
5. Generate SSL certificates
6. Add your user to the video group
7. Verify camera detection
After installation completes:
1. Log out and log back in (required for video group access)
2. Activate the virtual environment: `source venv/bin/activate`
3. Run the example: `python examples/ffmpeg_stream.py`
4. Open `https://your-pi-ip` in your browser
To uninstall:
```bash
./uninstall.sh
```
## Usage
Two streaming implementations are available:
### 1. FFmpeg-based (Recommended)
```python
from picamera2_webstream import FFmpegStream, create_ffmpeg_app
stream = FFmpegStream(
width=1280,
height=720,
framerate=30,
device='/dev/video0'
).start()
app = create_ffmpeg_app(stream)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=443, ssl_context=('cert.pem', 'key.pem'))
```
Advantages:
- Lighter weight (fewer dependencies)
- Hardware acceleration where available
- Better performance for basic streaming
- Works with both USB and CSI cameras
- Lower CPU usage
### 2. PiCamera2-based
```python
from picamera2_webstream import VideoStream, create_picamera_app
stream = VideoStream(
resolution=(1280, 720),
framerate=30,
brightness=0.0,
contrast=1.0
).start()
app = create_picamera_app(stream)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=443, ssl_context=('cert.pem', 'key.pem'))
```
Advantages:
- Full PiCamera2 feature set
- More camera controls
- Better for image processing
- Native Raspberry Pi camera support
- Access to raw camera data
### Choosing the Right Implementation
Use FFmpeg-based streaming when:
- You need basic video streaming
- You want minimal dependencies
- CPU resources are limited
- You're using a USB webcam
Use PiCamera2-based streaming when:
- You need advanced camera controls
- You want to do image processing
- You need raw camera data
- You're using the Raspberry Pi camera module
### Accessing the Stream
For either implementation:
1. Open your browser and navigate to `https://your-pi-ip`
2. Accept the self-signed certificate warning
3. View your camera stream!
## Camera Configuration
### Automatic Configuration
To find the optimal settings for your camera, run the diagnostic tool:
```bash
python examples/camera_diagnostics.py
```
This will:
1. Detect all available cameras
2. Show detailed camera capabilities
3. Test different resolutions and formats
4. Measure actual achievable framerates
5. Suggest optimal configuration settings
### Manual Configuration
You can customize various parameters when initializing the VideoStream:
```python
stream = VideoStream(
resolution=(1280, 720), # Width x Height
framerate=30, # Target framerate
format="MJPEG", # Video format
brightness=0.0, # -1.0 to 1.0
contrast=1.0, # 0.0 to 2.0
saturation=1.0 # 0.0 to 2.0
)
```
Common camera settings:
1. Resolution: Common values include (1920, 1080), (1280, 720), (640, 480)
2. Format: Usually "MJPEG" for web streaming
3. Framerate: Higher values (30+) for smooth video, lower values (15-) for reduced bandwidth
To see all available settings for your camera:
```bash
# List all video devices
v4l2-ctl --list-devices
# Show device capabilities (replace X with your device number)
v4l2-ctl -d /dev/videoX --all
# List supported formats
v4l2-ctl -d /dev/videoX --list-formats-ext
```
For USB cameras, you might also want to check:
```bash
# Show detailed USB device information
lsusb -v | grep -A 10 "Video"
```
### Performance Considerations
- Higher resolutions and framerates require more CPU and bandwidth
- MJPEG format provides good quality with reasonable bandwidth usage
- If streaming over the internet, consider lower resolutions and framerates
- Monitor CPU usage and network bandwidth to find optimal settings
## Development
If you want to modify the code:
1. Create a development environment:
```bash
# Clone and enter the repository
git clone https://github.com/glassontin/picamera2-webstream.git
cd picamera2-webstream
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# Install in editable mode
pip install -e .
```
2. Run tests (once implemented):
```bash
pip install pytest
pytest
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- Thanks to the picamera2 team for their excellent camera interface
- The Flask team for their lightweight web framework
## Troubleshooting
Common issues and solutions:
1. Camera not detected:
- Ensure the camera is properly connected
- Check if the camera interface is enabled in `raspi-config`
- Verify with `libcamera-hello` command
2. ImportError for picamera2:
- Make sure system packages are installed: `sudo apt install python3-libcamera python3-picamera2`
- Ensure you're using the virtual environment
3. SSL Certificate issues:
- Regenerate certificates if they've expired
- Ensure certificates are in the same directory as the script
4. Permission denied errors:
- Ensure your user is in the video group: `sudo usermod -a -G video $USER`
- Logout and login again for group changes to take effect
Raw data
{
"_id": null,
"home_page": null,
"name": "picamera2-webstream",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "raspberry pi, camera, streaming, picamera2, ffmpeg, flask",
"author": null,
"author_email": "Ian Ross Williams <ianrosswilliams@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/d2/83/8020ad2aec8c0d7ba0d18471c061c3a21513f18193d156890783bbfeec88/picamera2_webstream-0.2.6.tar.gz",
"platform": null,
"description": "# PiCamera2 Web Streamer\n\nA Flask-based web streaming solution for Raspberry Pi cameras using PiCamera2. Stream your Raspberry Pi camera feed securely over HTTPS with minimal latency.\n\n## Features\n\n- Real-time MJPEG streaming over HTTPS\n- Adaptive frame rate based on client connections\n- Clean shutdown handling\n- Mobile-responsive web interface\n- Thread-safe implementation\n- Configurable camera parameters\n- Resource-efficient with multiple client support\n\n## Dependencies\n\nA split installation approach ensures compatibility with Raspberry Pi OS while keeping application-specific dependencies isolated.\n\n### System Packages (installed via apt)\n- python3-libcamera\n- python3-picamera2\n- python3-opencv\n- python3-numpy\n\n### Virtual Environment Packages (installed via pip)\n- flask\n- Additional Python-only dependencies\n\n## Installation\n\n### Via pip\n```bash\npip install picamera2-webstream\n```\n\n## Quick Installation\n\nFor a quick automated installation:\n\n```bash\ngit clone https://github.com/glassontin/picamera2-webstream.git\ncd picamera2-webstream\n```\n\nFor an ffmpeg based webstream:\n```\n./install_ffmpeg.sh\n```\n\nFor a picamera2 OpenCV based webstream use:\n```\n./install_picamera.sh\n```\n\nThe installation script will:\n1. Install all required system dependencies\n2. Enable the camera interface\n3. Set up a Python virtual environment\n4. Install Python package dependencies\n5. Generate SSL certificates\n6. Add your user to the video group\n7. Verify camera detection\n\nAfter installation completes:\n1. Log out and log back in (required for video group access)\n2. Activate the virtual environment: `source venv/bin/activate`\n3. Run the example: `python examples/ffmpeg_stream.py`\n4. Open `https://your-pi-ip` in your browser\n\nTo uninstall:\n```bash\n./uninstall.sh\n```\n\n## Usage\n\nTwo streaming implementations are available:\n\n### 1. FFmpeg-based (Recommended)\n```python\nfrom picamera2_webstream import FFmpegStream, create_ffmpeg_app\n\nstream = FFmpegStream(\n width=1280,\n height=720,\n framerate=30,\n device='/dev/video0'\n).start()\n\napp = create_ffmpeg_app(stream)\n\nif __name__ == '__main__':\n app.run(host='0.0.0.0', port=443, ssl_context=('cert.pem', 'key.pem'))\n```\n\nAdvantages:\n- Lighter weight (fewer dependencies)\n- Hardware acceleration where available\n- Better performance for basic streaming\n- Works with both USB and CSI cameras\n- Lower CPU usage\n\n### 2. PiCamera2-based\n```python\nfrom picamera2_webstream import VideoStream, create_picamera_app\n\nstream = VideoStream(\n resolution=(1280, 720),\n framerate=30,\n brightness=0.0,\n contrast=1.0\n).start()\n\napp = create_picamera_app(stream)\n\nif __name__ == '__main__':\n app.run(host='0.0.0.0', port=443, ssl_context=('cert.pem', 'key.pem'))\n```\n\nAdvantages:\n- Full PiCamera2 feature set\n- More camera controls\n- Better for image processing\n- Native Raspberry Pi camera support\n- Access to raw camera data\n\n### Choosing the Right Implementation\n\nUse FFmpeg-based streaming when:\n- You need basic video streaming\n- You want minimal dependencies\n- CPU resources are limited\n- You're using a USB webcam\n\nUse PiCamera2-based streaming when:\n- You need advanced camera controls\n- You want to do image processing\n- You need raw camera data\n- You're using the Raspberry Pi camera module\n\n### Accessing the Stream\n\nFor either implementation:\n1. Open your browser and navigate to `https://your-pi-ip`\n2. Accept the self-signed certificate warning\n3. View your camera stream!\n\n## Camera Configuration\n\n### Automatic Configuration\nTo find the optimal settings for your camera, run the diagnostic tool:\n\n```bash\npython examples/camera_diagnostics.py\n```\n\nThis will:\n1. Detect all available cameras\n2. Show detailed camera capabilities\n3. Test different resolutions and formats\n4. Measure actual achievable framerates\n5. Suggest optimal configuration settings\n\n### Manual Configuration\nYou can customize various parameters when initializing the VideoStream:\n\n```python\nstream = VideoStream(\n resolution=(1280, 720), # Width x Height\n framerate=30, # Target framerate\n format=\"MJPEG\", # Video format\n brightness=0.0, # -1.0 to 1.0\n contrast=1.0, # 0.0 to 2.0\n saturation=1.0 # 0.0 to 2.0\n)\n```\n\nCommon camera settings:\n1. Resolution: Common values include (1920, 1080), (1280, 720), (640, 480)\n2. Format: Usually \"MJPEG\" for web streaming\n3. Framerate: Higher values (30+) for smooth video, lower values (15-) for reduced bandwidth\n\nTo see all available settings for your camera:\n```bash\n# List all video devices\nv4l2-ctl --list-devices\n\n# Show device capabilities (replace X with your device number)\nv4l2-ctl -d /dev/videoX --all\n\n# List supported formats\nv4l2-ctl -d /dev/videoX --list-formats-ext\n```\n\nFor USB cameras, you might also want to check:\n```bash\n# Show detailed USB device information\nlsusb -v | grep -A 10 \"Video\"\n```\n\n### Performance Considerations\n- Higher resolutions and framerates require more CPU and bandwidth\n- MJPEG format provides good quality with reasonable bandwidth usage\n- If streaming over the internet, consider lower resolutions and framerates\n- Monitor CPU usage and network bandwidth to find optimal settings\n\n## Development\n\nIf you want to modify the code:\n\n1. Create a development environment:\n```bash\n# Clone and enter the repository\ngit clone https://github.com/glassontin/picamera2-webstream.git\ncd picamera2-webstream\n\n# Create and activate virtual environment\npython3 -m venv venv\nsource venv/bin/activate\n\n# Install in editable mode\npip install -e .\n```\n\n2. Run tests (once implemented):\n```bash\npip install pytest\npytest\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- Thanks to the picamera2 team for their excellent camera interface\n- The Flask team for their lightweight web framework\n\n## Troubleshooting\n\nCommon issues and solutions:\n\n1. Camera not detected:\n - Ensure the camera is properly connected\n - Check if the camera interface is enabled in `raspi-config`\n - Verify with `libcamera-hello` command\n\n2. ImportError for picamera2:\n - Make sure system packages are installed: `sudo apt install python3-libcamera python3-picamera2`\n - Ensure you're using the virtual environment\n\n3. SSL Certificate issues:\n - Regenerate certificates if they've expired\n - Ensure certificates are in the same directory as the script\n\n4. Permission denied errors:\n - Ensure your user is in the video group: `sudo usermod -a -G video $USER`\n - Logout and login again for group changes to take effect\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Ian Ross Williams Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "A Flask-based web streaming solution for Raspberry Pi cameras using PiCamera2",
"version": "0.2.6",
"project_urls": {
"Homepage": "https://github.com/GlassOnTin/picamera2-webstream",
"Issues": "https://github.com/GlassOnTin/picamera2-webstream/issues",
"Repository": "https://github.com/GlassOnTin/picamera2-webstream.git"
},
"split_keywords": [
"raspberry pi",
" camera",
" streaming",
" picamera2",
" ffmpeg",
" flask"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a56ade54fbf8f14dfba073b5bf261d8c6a01a1a02a17d292f32b311284326a44",
"md5": "11adff3cbc80a907d014e239eb3a6118",
"sha256": "1c00a8350ee9795017b673511b700ec13f521a5faa58e09280e469d1c0f8c10c"
},
"downloads": -1,
"filename": "picamera2_webstream-0.2.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "11adff3cbc80a907d014e239eb3a6118",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9702,
"upload_time": "2024-11-21T16:59:31",
"upload_time_iso_8601": "2024-11-21T16:59:31.208409Z",
"url": "https://files.pythonhosted.org/packages/a5/6a/de54fbf8f14dfba073b5bf261d8c6a01a1a02a17d292f32b311284326a44/picamera2_webstream-0.2.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d2838020ad2aec8c0d7ba0d18471c061c3a21513f18193d156890783bbfeec88",
"md5": "1e136754298e89810986ecd6cb481000",
"sha256": "ff0807e4623e04600ee54f132f5a6bedf9d376556b4c94ce0cfca83f9faf4337"
},
"downloads": -1,
"filename": "picamera2_webstream-0.2.6.tar.gz",
"has_sig": false,
"md5_digest": "1e136754298e89810986ecd6cb481000",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8884,
"upload_time": "2024-11-21T16:59:32",
"upload_time_iso_8601": "2024-11-21T16:59:32.852253Z",
"url": "https://files.pythonhosted.org/packages/d2/83/8020ad2aec8c0d7ba0d18471c061c3a21513f18193d156890783bbfeec88/picamera2_webstream-0.2.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-21 16:59:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GlassOnTin",
"github_project": "picamera2-webstream",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "flask",
"specs": [
[
">=",
"2.0.0"
]
]
}
],
"lcname": "picamera2-webstream"
}