django与aws弹性转码器
django-elastic-transcoder-socialschools的Python项目详细描述
django-elastic-transcoder是一个django应用程序,让您可以轻松地在django中集成aws弹性转码器。
这个包裹里有什么?
- Transcoder类
- 接收sns通知的url端点
- 进程、错误、完成的信号
- EncodeJob型号
工作流程
安装
首先,用pip
安装dj_elastictranscode。$ pip install django-elastic-transcoder
然后,将dj_elastictranscoder添加到INSTALLED_APPS
INSTALLED_APPS=(...'dj_elastictranscoder',...)
绑定urls.py
urlpatterns=patterns('',...url(r'^dj_elastictranscoder/',include('dj_elastictranscoder.urls')),...)
迁移
$ ./manage.py migrate
设置AWS弹性转码器
- 在aws弹性转码器中创建一个新的Pipeline。
- 连接每个通知。
- 通过http订阅sns通知
- 你已经准备好编码了!
所需的django设置
请在下面设置变量以使此应用程序正常工作。
AWS_ACCESS_KEY_ID=<yourawsaccesskeyid>AWS_SECRET_ACCESS_KEY=<yourawssecretaccesskey>AWS_REGION=<awsregion>
用法
例如,对MP3进行编码
fromdj_elastictranscoder.transcoderimportTranscoderinput={'Key':'path/to/input.mp3',}outputs=[{'Key':'path/to/output.mp3','PresetId':'1351620000001-300040'# for example: 128k mp3 audio preset}]pipeline_id='<pipeline_id>'transcoder=Transcoder(pipeline_id)transcoder.encode(input,outputs)# your can also create a EncodeJob for object automaticallytranscoder.create_job_for_object(obj)# Transcoder can also work standalone without Django# just pass region and required aws key/secret to Transcoder, when initiatetranscoder=Transcoder(pipeline_id,AWS_REGION,AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)
设置AWS SNS端点
aws弹性转码器可以发送各种sns通知来通知您的应用程序,如PROGRESS、ERROR、WARNING和COMPLETE
所以这个包提供了一个端点来接收这些通知,以便您更新代码转换进度。不用你自己检查。
转到aws webconsole中的sns部分,选择主题并使用下面的url订阅。
http://<your-domain>/dj_elastictranscoder/endpoint/
在通知开始工作之前,您必须激活sns订阅,您将收到带有激活链接的电子邮件。
订阅完成后,您将收到sns通知。
信号
这个包为您提供各种信号,让您获得通知,并在应用程序中执行更多操作。您可以检查tests.py中的信号用法以获取更多用法示例。
- 转码进展
- 转码错误
- 代码转换完成