McSimp / python-librtmp

Python bindings for librtmp, built with cffi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python-librtmp

https://badge.fury.io/py/python-librtmp.png https://travis-ci.org/chrippa/python-librtmp.png?branch=master https://pypip.in/d/python-librtmp/badge.png

python-librtmp is a Python interface to librtmp. It uses cffi to interface with the C library librtmp.

Installation

The latest stable version is available to install using pip:

# pip install cffi
# pip install python-librtmp

But you can also get the development version using Git:

$ git clone git://github.com/chrippa/python-librtmp.git
$ cd python-librtmp
# pip install cffi
# python setup.py install

Dependencies

  • a compiler, e.g gcc
  • librtmp: The library including it's headers (librtmp-dev). Only the official librtmp is supported, patched versions such as librtmp-ksv may not work.
  • cffi: The setup.py script currently depends on cffi being installed. Therefore you need to install it before installing this library. cffi also depends on libffi and it's headers (libffi-dev)

Windows

If you're on Windows, you may not have a compiler easily available.

You can find binaries of cffi at http://www.lfd.uci.edu/~gohlke/pythonlibs/#cffi. python-librtmp has wheel packages (binaries) available on PyPi, and can therefore be installed with pip 1.4+:

> pip install --use-wheel python-librtmp

Features

Streaming

The most common use case of RTMP is to read a video stream from a server.

import librtmp

# Create a connection
conn = librtmp.RTMP("rtmp://your.server.net/app/playpath", live=True)
# Attempt to connect
conn.connect()
# Get a file-like object to access to the stream
stream = conn.create_stream()
# Read 1024 bytes of data
data = stream.read(1024)

Remote function calls

Here is a example of creating a Python function that can be used to call remote functions:

my_remote_method = conn.remote_method("MyRemoteMethod", block=True)
result = my_remote_method("some argument")

Waiting for the server to call our function:

# This will automatically name the function after it's Python name
@conn.invoke_handler
def my_add(a, b):
    return a + b

# Start waiting for calls
conn.process_packets()

You can also use custom function name instead:

@conn.invoke_handler("MyMath.MyAdd")

Instead of blocking forever when waiting for a call you can specify to wait only for a specific invoke and then stop blocking:

conn.process_packets(invoked_method="MyMath.MyAdd", timeout=30)

About

Python bindings for librtmp, built with cffi

License:BSD 2-Clause "Simplified" License


Languages

Language:Python 52.5%Language:C 47.5%