Python Chrysalis Cloud SDK
This repository houses the official Chrysalis Cloud Python SDK for use with Chryscloud.com cloud, end-to-end media streaming and analytics platform.
Chrysalis Cloud SDK aims to provide easy and powerful control over live media streaming consumption and ingestion into various machine learning libraries in the cloud.
If you're looking for a hybrid edge-cloud solution we recommend you look into our open source project Chrysalis Edge Proxy
Contents
Features
- Easy integration with numerous machine learning platforms
- Support for easy access to RTMP live video stream from Chrysalis Cloud (live video/audio streaming)
- Supporting for any camera that has RTMP streaming abilities
- Deals with complexities of media stream management
- Secure access media streams
Prerequisite
Check FFmpeg version:
ffmpeg -version
Installation
Create environment.yml file.
You can easily add to this file dependencies and additional image manipulation libraries such as Pillow and OpenCV.
If you need GPU support, you can check how to work with Anaconda and GPU packages.
name: chryssdktest
channels:
- conda-forge
dependencies:
- ca-certificates=2020.1.1=0
- certifi=2020.4.5.1=py37_0
- pip=20.0.2=py37_1
- wheel=0.34.2=py37_0
- python=3.7.7=hcf32534_0_cpython
- opencv=4.2.0
- av=7.0.1
- numpy=1.18.1
- redis-py=3.4.1
- pip:
- Cython
- chrysalis==1.0.0
Create new conda environment:
conda env create -f environment.yml
Usage
- all returned images are in numpy format.
- all returned images are in bgr24 pixel format.
Check ChImage attributes for more details
Probe
Probing returns information about the streaming media. It gives you a sense if the camera is streaming, when it was last seen, what is the frame cache duration stored on the Chrysalis streaming server.
import chrysalis
# connection to Chrysalis Cloud
chrys = chrysalis.Connect(host="https://myserver.at.chrysvideo.com", port="1234", password="mypassword", ssl_ca_cert="mycert.cer")
# returns ProbeInfo object
probe = chrys.Probe()
print("start {}, end {}, duration {} s, assessed fps {}".format(probe.start_timestamp, probe.end_timestamp, probe.duration, probe.fps))
The ProbeInfo object returns the information about cached frames as well as assessment of FPS (frames per second) streamed from the camera.
start_timestamp and end_timestamp are UTC times in milliseconds since epoch.
ProbeInfo Attributes
----------
start_timestamp : int
Earlies contained media data in video stream cache
end_timestamp : int
Latest contained media data in video stream cache
duration : int
Duration of the buffered media stream in seconds
fps : int
Approximation of Frames per Second of source stream
"""
Retrieve latest video image from a live stream
Chrysalis Cloud Python SDK takes care of delivering crisp and clear images from your live video stream, regardless of the processing speeds, speed ups or slow downs because of the latency or even if your camera disconnects from the network.
import chrysalis
# connection to Chrysalis Cloud
chrys = chrysalis.Connect(host="https://myserver.at.chrysvideo.com", port="1234", password="mypassword", ssl_ca_cert="mycert.cer")
# Perpetual reading of the stream
while True:
# VideoLatestImage returns ChImage object
img = chrys.VideoLatestImage()
ChImage object returned from VideoLatestImage has a following structure:
ChImage Attributes
----------
data: numpy
Image stored in numpy in bgr24 format
start_timestamp : int
Earlies contained media data in video stream cache
end_timestamp : int
Latest contained media data in video stream cache
duration : int
Duration of the buffered media stream in seconds
fps : int
Approximation of Frames per Second of source stream
"""
VideoLatestImage returns None image when frame not available.
VideoLatestImage might return None in cases when querying for the next frame is faster than the camera stream produces them.
The SDK will not return already consumed frames (images) in the perpetual reading of the stream.
You can also consume live stream images from mutliple sinks in case when you need to run the same live stream (e.g. the same image) through multiple Computer Vision algorithms. Not returning already consumed frames applies per SDK instance basis.
Retrieve video images from the past
Based on what is available in the frame cache on Chrysalis streaming nodes you can also query video images from the past. Use Probing in case you need more information how much back in time you can query the video stream.
import chrysalis
# connection to Chrysais Cloud
chrys = chrysalis.Connect(hos="https://myserver.at.chrysvideo.com", prt="1234", password="mypassword", ssl_ca_cert="mycert.cer")
probe = ch.Probe()
start = probe.end_timestamp - (1000 * 30) # 30 seconds in the past
end = probe.end_timestamp - (1000 * 15) # until 15 seconds in the past (end > start)
# Perpetual reading of the stream until end is reached
while True:
# VideoLatestImage returns ChImage object
img = ch.VideoPastImage(start, end)
Thumbnail image from video stream
Thumbnails are in bgr24 format in numpy array. In fact all images for local consumption are in the same format. This makes it easy to consume images in any processing and analytics after.
import chrysalis
chrys = chrysalis.Connect(host="https://myserver.at.chrysalis.com", port="1234", password="mypassword", ssl_ca_cert="mycert.crt")
d = datetime.today() - timedelta(hours=0, minutes=0, seconds=2)
img = chrys.Screenshot(dt=d)
Due to the nature of H.264 straming it is not guaranteed the successfulness of the Screenshot method. In case no screenshot was found img = None.
This function tries to traverse the H.264 buffered stream seeking for I-Frame. the closest I-Frame to given dt (timestamp) is returned if I-Frame found.
Turn Storage On and Off
Based on video analysis you can decide to store a stream into the permanent Chrysalis Cloud storage. Since live video form a webcam might be streaming 24/7 we don’t necessarily need to store everything, but rather we can perform simple analysis (e.g. movement detection, face recognition, …) to decide when and for how long we want to permanently store that video segment.
Coming soon
Example
All examples are in /examples folder. Create conda environment from prepared environment.yml in examples folder before you run the examples.
Display live stream with OpenCV
import chrysalis
# connection to Chrysalis Cloud
chrys = chrysalis.Connect(host="https://myserver.at.chrysalis.com", port="1234", password="mypassword", ssl_ca_cert="mycert.cer")
# Perpetual reading of the stream
while True:
# VideoLatestImage returns ChImage object
img = chrys.VideoLatestImage()
if img is not None:
cv2.imshow("live video", img.data)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Development
Install FFmpeg
Mac OS X
brew install ffmpeg pkg-config
Ubuntu >= 18.04 LTS
On Ubuntu 18.04 LTS everything can come from the default sources:
sudo apt-get install -y python-dev pkg-config
# Library components
sudo apt-get install -y \
libavformat-dev libavcodec-dev libavdevice-dev \
libavutil-dev libswscale-dev libswresample-dev libavfilter-dev
Ubuntu < 18.04 LTS
On older Ubuntu releases you will be unable to satisfy these requirements with the default package sources. We recommend compiling and installing FFmpeg from source. For FFmpeg:
sudo apt install \
autoconf \
automake \
build-essential \
cmake \
libass-dev \
libfreetype6-dev \
libjpeg-dev \
libtheora-dev \
libtool \
libvorbis-dev \
libx264-dev \
pkg-config \
wget \
yasm \
zlib1g-dev
wget http://ffmpeg.org/releases/ffmpeg-3.2.tar.bz2
tar -xjf ffmpeg-3.2.tar.bz2
cd ffmpeg-3.2
./configure --disable-static --enable-shared --disable-doc
make
Installing
git clone https://github.com/cocoonhealth/ChrysalisPythonSDK.git
cd ChrysalisPythonSDK
sudo pip install -e .
This should install it's dependencies also.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process of submitting pull requests to us.
Versioning
Current version is initial release - 1.0.0
License
This project is licensed under Apache 2.0 License - see the LICENSE for details.
Metadata
Release files for chrysalis 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chrysalis-1.0.0.tar.gz | 15.0 kB | Without provenance | Details for chrysalis-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chrysalis-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for chrysalis-1.0.0-py3-none-any.whl |
Total release size: 38.7 kB
Release files / chrysalis-1.0.0.tar.gz
| Download URL | chrysalis-1.0.0.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32b1ad1aba7e2ca7114fafdc73e248530ced3f49d018c77dc902b3d5d8e0eb86
|
|
BLAKE2b-256 checksum How to use checksums |
c322d2355853b918a96d76a87b7de00108fb8dae4841a7205fd74027d3b01fbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
|
Release files / chrysalis-1.0.0-py3-none-any.whl
| Download URL | chrysalis-1.0.0-py3-none-any.whl |
|---|---|
| Size | 23.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28263699878b1bd30046fa4a1e93deb74e5c92dcfb464a49351777dc0a346635
|
|
BLAKE2b-256 checksum How to use checksums |
ed17434542267f20bf7c90d6d14f0263d17431637042fb7fecb2301febbbe428
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
|
Security for chrysalis 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.