Skip to main content

FastAPI Based video streamer

Project description

video-streamer

Video streamer to be used with MXCuBE. The streamer currently supports streaming from Tango (Lima) devices, as well as Redis and MJPEG streams and can be extened to be used with other camera solutions as well. The output streams are either MJPEG or MPEG1 with an option to use a secondary output stream to a Redis Pub/Sub channel.

Screenshot from 2023-03-03 14-36-02

Documentation 📚

Check out the full documentation to explore everything this project has to offer! Including:

  • Information about all supported input camera types
  • A detailed guide on how to start and run the project
  • A developers guide
  • An FAQ
  • and more!

Installation

git clone https://github.com/mxcube/video-streamer.git
cd video-streamer

# optional 
conda env create -f conda-environment.yml

# For development
pip install -e .

# For usage 
pip install .

Usage

usage: video-streamer [-h] [-c CONFIG_FILE_PATH] [-uri URI] [-hs HOST]
                      [-p PORT] [-q QUALITY] [-s SIZE] [-of OUTPUT_FORMAT]
                      [-id HASH] [-d] [-r] [-rhs REDIS_HOST] [-rp REDIS_PORT]
                      [-rk REDIS_CHANNEL] [-irc IN_REDIS_CHANNEL]

mxcube video streamer

options:
  -h, --help            show this help message and exit
  -c CONFIG_FILE_PATH, --config CONFIG_FILE_PATH
                        Configuration file path
  -uri URI, --uri URI   Tango device URI
  -hs HOST, --host HOST
                        Host name to listen on for incomming client
                        connections default (0.0.0.0)
  -p PORT, --port PORT  Port
  -q QUALITY, --quality QUALITY
                        Compresion rate/quality
  -s SIZE, --size SIZE  size
  -of OUTPUT_FORMAT, --output-format OUTPUT_FORMAT
                        output format, MPEG1 or MJPEG
  -id HASH, --id HASH   Stream id
  -d, --debug           Debug true or false
  -r, --redis           Use redis-server
  -rhs REDIS_HOST, --redis-host REDIS_HOST
                        Host name of redis server to send to
  -rp REDIS_PORT, --redis-port REDIS_PORT
                        Port of redis server
  -rk REDIS_CHANNEL, --redis-channel REDIS_CHANNEL
                        Key for saving to redis database
  -irc IN_REDIS_CHANNEL, --in_redis_channel IN_REDIS_CHANNEL
                        Channel for RedisCamera to listen to

There is the possibility to use a configuration file instead of command line arguments. All command line arguments except debug are ignored if a config file is used. The configuration file also makes it possible to configure several sources while the command line only allows configuration of a single source.

Example command line (for testing):

video-streamer -d -of MPEG1 -uri test

Example configuration file (config.json):

The configuration file format is JSON. A test image is used when the input_uri is set to "test". The example below creates one MPEG1 stream and one MJPEG stream from the test image. There is a defualt test/demo UI to see the video stream on http://localhost:[port]/ui. In example below case:

MPEG1: http://localhost:8000/ui

MJPEG: http://localhost:8001/ui

video-streamer -c config.json

config.json:
{
    "sources": {
        "0.0.0.0:8000": {
            "input_uri": "test",
            "quality": 4,
            "format": "MPEG1"
        },
        "0.0.0.0:8001": {
            "input_uri": "test",
            "quality": 4,
            "format": "MJPEG"
        }
    }
}

Dual Streaming: Seamlessly Serve MJPEG and Redis Pub/Sub Video Feeds

When generating an MJPEG stream using any of the cameras (except for MJPEGCamera) implemented in video-streamer, it is possible to use a Redis Pub/Sub channel as additional Video feed. Below you can see an example on how to do that from the command line:

video-streamer -d -of MPEG1 -uri test -r -rhs localhost -rp 6379 -rk video-streamer

where -r flag is needed to allow the stream to redis , -rhs,-rp, -rk define the host, port and channel of the targeted Redis Pub/Sub respectively.

The format of the frames send to Redis looks as follows:

frame_dict = {
    "data": [encoded image data],
    "size": [image size],
    "time": [timestamp of image_polling],
    "frame_number": [number of frame send to Redis starting at 0],
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mxcube_video_streamer-1.8.2.tar.gz (6.8 MB view details)

Uploaded Source

Built Distribution

mxcube_video_streamer-1.8.2-py3-none-any.whl (6.8 MB view details)

Uploaded Python 3

File details

Details for the file mxcube_video_streamer-1.8.2.tar.gz.

File metadata

  • Download URL: mxcube_video_streamer-1.8.2.tar.gz
  • Upload date:
  • Size: 6.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.16 Linux/6.11.0-19-generic

File hashes

Hashes for mxcube_video_streamer-1.8.2.tar.gz
Algorithm Hash digest
SHA256 0de041c5f17148cec4668a7683f39f1064cd5036d6de311de23a29965466bba6
MD5 4f85f4935e2def54eba39cf2bbae0a12
BLAKE2b-256 df608edb10fd9743f8b900959f46d37fa33d031ba9826eed26b7d67ee4400065

See more details on using hashes here.

File details

Details for the file mxcube_video_streamer-1.8.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mxcube_video_streamer-1.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 356998627e4ecc74b6b764dcd4799be0d85e4d658f10810b877d9af14ac57178
MD5 cd05f396e5ad98f1e2d645e489385257
BLAKE2b-256 e2ac01cbc738728794048194506c51e39dfa978251543025ca52448c1aff405e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page