项目作者: PerchLive

项目描述 :
Django REST Framework API模块,用于创建实时视频广播
高级语言: Python
项目地址: git://github.com/PerchLive/django-broadcast.git
创建时间: 2015-10-16T19:54:20Z
项目社区:https://github.com/PerchLive/django-broadcast

开源协议:Apache License 2.0

下载


django-broadcast

Build Status PyPI Page Coverage Status Python Versions Downloads per Day

Overview

Video broadcasting support for Django apps. Designed to abstract provisioning backend storage for video streaming clients behind
simple “Start Stream” and “Stop Stream” API calls.

API

These endpoints are all POST. Parameters are URL encoded for request, and JSON encoded for response.

/stream/start/

Request (url encoded)

  1. {
  2. 'type' : 'hls' (this is the only option currently supported)
  3. 'name' : 'some_name' (optional)
  4. }

e.g: https://endpoint.tld/stream/start/?name=some_name&type=hls

Response (json encoded)

  1. {
  2. 'stream' : {
  3. 'id' : 'stream_id', (generally a UUID or similar)
  4. 'name' : 'some_name',
  5. 'start_date' : '2015-10-22 15:27:40', (time always in GMT)
  6. },
  7. 'endpoint': {
  8. 'S3': {
  9. 'aws_access_key_id': 'key'
  10. 'aws_secret_access_key': 'secret',
  11. 'aws_session_token': 'token',
  12. 'aws_expiration': 3600.0 // in seconds
  13. 's3_bucket_name': 'bucket',
  14. 's3_bucket_path': 'path',
  15. 's3_bucket_region': 'us-west-1' // valid amazon region string
  16. }
  17. // future endpoints could go here, like RTMP, WebRTC, etc
  18. }
  19. }

/stream/stop/

Request (url encoded)

  1. {
  2. 'id' : 'stream_id'
  3. }

e.g: https://endpoint.tld/stream/start/?id=B8C2401D-B2F8-47CD-90BD-53B608D47F3F

Response (json encoded)

  1. {
  2. 'stream': {
  3. 'id' : 'stream_id',
  4. 'name' : 'some_name',
  5. 'start_date' : '2015-10-22 15:27:40', (time always in GMT)
  6. 'stop_date' : '2015-10-22 16:27:40', (time always in GMT)
  7. }
  8. }

Usage

We currently recommend your hosting Django application setup the URL and views for /stream/start and /stream/stop.
Within those views, you can yield to built-in methods to handle most of the work for you while leaving you ultimate control
over the request and response formats.

For example, your /stream/start view may look like:

  1. from django.http import JsonResponse
  2. from django_broadcast.api import start_hls_stream, prepare_start_hls_stream_response
  3. def your_start_stream_view(request):
  4. # Do request validation, etc.
  5. # Prepare for new Stream : This handles creating storage credentials
  6. # and preparing data needed by mobile client
  7. start_result = start_hls_stream(request=request)
  8. # start_result is a python dictionary with format:
  9. # {'stream': ..., 'storage': ...}
  10. # Use built-in function for standard dictionary representation
  11. # as specified in API section above.
  12. serialized_response = prepare_start_hls_stream_response(start_result)
  13. return JsonResponse({'success': true, 'response': serialized_response})

Requirements

  • Python (2.7, 3.3, 3.4)
  • Django (1.6, 1.7, 1.8)
  • Django REST Framework (2.4, 3.0, 3.1)

Installation

Install using pip

  1. $ pip install django-broadcast

Setup

Currently django-broadcast supports an S3 backend:

  1. BROADCAST_SETTINGS = {
  2. "STREAM_MODEL": "home.Stream",
  3. "S3": {
  4. "AWS_ACCESS_KEY_ID": os.environ.get('DJ_BROADCAST_AWS_ACCESS_KEY', ''),
  5. "AWS_SECRET_ACCESS_KEY": os.environ.get('DJ_BROADCAST_AWS_ACCESS_SECRET', ''),
  6. "BUCKET": os.environ.get('DJ_BROADCAST_S3_BUCKET', '')
  7. }
  8. }

Testing

Install testing requirements.

  1. $ pip install -r requirements.txt

Run with runtests.

  1. $ ./runtests.py

You can also use the excellent tox_ testing tool to run the tests
against all supported versions of Python and Django. Install tox
globally, and then simply run:

  1. $ tox