Package: chrysalis
Python Chrysalis Cloud SDKThis repository houses the official Chrysalis Cloud Python SDK for use withChryscloud.comcloud, 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 projectChrysalis Edge ProxyContentsFeaturesPrerequisiteInstallationUsageProbingLive stream framesBuffered frames in the pastThumbnail image from video streamTurn permanent storage on/offExampleLive stream with OpenCVDevelopmentMac OS XUbuntu >= 18.04 LTSUbuntu < 18.04 LTSInstallingFeaturesEasy integration with numerous machine learning platformsSupport for easy access to RTMP live video stream from Chrysalis Cloud (live video/audio streaming)Supporting for any camera that has RTMP streaming abilitiesDeals with complexities of media stream managementSecure access media streamsPrerequisiteInstall anacondaInstall FFmpeg > 4.0CheckFFmpegversion:ffmpeg -versionInstallationCreateenvironment.ymlfile.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:chryssdktestchannels:-conda-forgedependencies:-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.0Create new conda environment:condaenvcreate-fenvironment.ymlUsageall returned images are in numpy format.all returned images are in bgr24 pixel format.Check ChImage attributes for more detailsProbeProbing 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.importchrysalis# connection to Chrysalis Cloudchrys=chrysalis.Connect(host="https://myserver.at.chrysvideo.com",port="1234",password="mypassword",ssl_ca_cert="mycert.cer")# returns ProbeInfo objectprobe=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_timestampandend_timestampare UTC times in milliseconds since epoch.ProbeInfoAttributes----------start_timestamp:intEarliescontainedmediadatainvideostreamcacheend_timestamp:intLatestcontainedmediadatainvideostreamcacheduration:intDurationofthebufferedmediastreaminsecondsfps:intApproximationofFramesperSecondofsourcestream"""Retrieve latest video image from a live streamChrysalis 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.importchrysalis# connection to Chrysalis Cloudchrys=chrysalis.Connect(host="https://myserver.at.chrysvideo.com",port="1234",password="mypassword",ssl_ca_cert="mycert.cer")# Perpetual reading of the streamwhileTrue:# VideoLatestImage returns ChImage objectimg=chrys.VideoLatestImage()ChImageobject returned from VideoLatestImage has a following structure:ChImageAttributes----------data:numpyImagestoredinnumpyinbgr24formatstart_timestamp:intEarliescontainedmediadatainvideostreamcacheend_timestamp:intLatestcontainedmediadatainvideostreamcacheduration:intDurationofthebufferedmediastreaminsecondsfps:intApproximationofFramesperSecondofsourcestream"""VideoLatestImage returnsNoneimage 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 pastBased on what is available in the frame cache on Chrysalis streaming nodes you can also query video images from the past. UseProbingin case you need more information how much back in time you can query the video stream.importchrysalis# connection to Chrysais Cloudchrys=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 pastend=probe.end_timestamp-(1000*15)# until 15 seconds in the past (end > start)# Perpetual reading of the stream until end is reachedwhileTrue:# VideoLatestImage returns ChImage objectimg=ch.VideoPastImage(start,end)Thumbnail image from video streamThumbnails are inbgr24 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.importchrysalischrys=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 foundimg = None.This function tries to traverse the H.264 buffered stream seeking for I-Frame. the closest I-Frame to givendt(timestamp) is returned if I-Frame found.Turn Storage On and OffBased 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 soonExampleAll examples are in/examplesfolder. Create conda environment from preparedenvironment.ymlin examples folder before you run the examples.Display live stream with OpenCVimportchrysalis# connection to Chrysalis Cloudchrys=chrysalis.Connect(host="https://myserver.at.chrysalis.com",port="1234",password="mypassword",ssl_ca_cert="mycert.cer")# Perpetual reading of the streamwhileTrue:# VideoLatestImage returns ChImage objectimg=chrys.VideoLatestImage()ifimgisnotNone:cv2.imshow("live video",img.data)ifcv2.waitKey(1)&0xFF==ord('q'):breakDevelopmentInstall FFmpegMac OS Xbrew install ffmpeg pkg-configUbuntu >= 18.04 LTSOn 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-devUbuntu < 18.04 LTSOn 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
makeInstallinggitclonehttps://github.com/cocoonhealth/ChrysalisPythonSDK.gitcdChrysalisPythonSDK

sudopipinstall-e.This should install it's dependencies also.ContributingPlease readCONTRIBUTING.mdfor details on our code of conduct, and the process of submitting pull requests to us.VersioningCurrent version is initial release - 1.0.0LicenseThis project is licensed under Apache 2.0 License - see theLICENSEfor details.