Skip to main content

A python client for Intel OWT server

Project description

pyowt

PyPI PyPI - Downloads

A python client for Intel OWT Server

Installation

You can install using pip:

pip install owt

Quick Start

from owt import ConferenceClient

# create a client
client = ConferenceClient()
try:
    # join the conference using token created by owt-server
    # or if your owt-server is using the demo, the package provide an 
    # api to request token from the server directly. (It should not be permit in product environment)
    # from owt.utils import create_token_from_owt_demo
    # token = await create_token_from_owt_demo(url, user_name, role, room=room)
    conference = await client.join(token)
    # To publish, you need a LocalStream. 
    # To create a localStream, you need a MediaStreamTrack
    # which is the class of package aiortc. 
    # So you can find document of how to create a MediaStreamTrack
    # from https://github.com/aiortc/aiortc.
    # Here I provide a simple way to create it:
    stream = create_local_tracks('file', Path.join(Path.dirname(__file__), 'fixtures/video.mp4'))
    # You can add some custom attribute to the stream. After published, 
    # another endpoint will accept it and using it to distinguish the stream.
    stream.attributes = {
        'tag': 'test-video',
        'origin': stream.id,
    }
    # now publish it.
    pub = await client.publish(stream)
    # Though after the method publish returned, the publication is completed. 
    # you may not accept the new remote stream 
    # (Of course you can subscribe the stream you published)
    # immediately. Here I provide an api to wait it.
    remote_stream = await client.wait_for_stream(lambda st: st.attributes.get('origin') == local_stream.id, timeout=10)
    # now you can subscribe the video you just published
    sub = await client.subscribe(remote_stream)
    # You can read the video stream from sub.video_track()
    # or audio stream from sub.audio_track() 
    track = sub.video_track()
    # We know we just publish a video, so the video track should not be None
    assert track
    while True:
        # What's is frame is? Please see the document of [aiortc](https://github.com/aiortc/aiortc), Of course, you can convert it to numpy array.
        frame = await track.recv()
        # do something about the frame
    await sub.close()
    await pub.close()
finally:
    await client.leave()

This package is based on aiortc because it need the support of webrtc tec. And aiortc is based on pyav. So I suggest you read the document of them too.

Here is another useful api:

from owt import ConferenceClient

client = ConferenceClient()
try:
    await client.join(token)
    async def consume_stream(stream: RemoteStream):
        # first filter the stream
        if ...:
            # then subscribe it
            sub = await client.subscribe(stream)
            track = sub.video_track()
            # then process it
            while True:
                frame = await track.recv()
                ...
    # The method consume_streams will consume all the remote streams 
    # (Someone published, here someone include yourselvies.), 
    # including the stream exist and coming in in future.
    # Here timeout mean the method will wait 10 second until all the 
    # consume_stream callbacks have done and no new remote streams found.
    handle = client.consume_streams(consume_stream, timeout=10)
    # The handle will return only when all your consume_stream callbacks
    # have done and no new remote streams found for 10 seconds.
    await handle.wait()
finally:
    # leave the conference will automatically close all the 
    # related publications and subscribations
    await client.leave()

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

owt-0.1.9.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

owt-0.1.9-py3-none-any.whl (47.7 kB view details)

Uploaded Python 3

File details

Details for the file owt-0.1.9.tar.gz.

File metadata

  • Download URL: owt-0.1.9.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Windows/10

File hashes

Hashes for owt-0.1.9.tar.gz
Algorithm Hash digest
SHA256 b1047cfbf69e796dc005ce1a8448d0394693869a2b6d7945b723ce1817241f25
MD5 54a7e0bb906d511ef9f52ccc56888548
BLAKE2b-256 5f52f6d4b4afdbd30cf5f6a2ec409da62dbe866c646e56e5477df9feb906c59b

See more details on using hashes here.

File details

Details for the file owt-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: owt-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 47.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Windows/10

File hashes

Hashes for owt-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f89bd287ff3dbb0dae1f04cbc9b7d444090c6fb818d995edb43e698c3851ede8
MD5 90f5cc075cb3884e17fb20cc54b4d293
BLAKE2b-256 7f335ebbea185f5cb80ec00b13507a576a002457b5408b98f45e2bdc3bb18c2d

See more details on using hashes here.

Supported by

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