This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
How to Use the API
Flávio Ribeiro edited this page Jul 17, 2016
·
8 revisions
# Snickers API How To
Given a JSON file called preset.json
:
{
"name": "mp4_240p",
"description": "Encodes video in H264/MP4 @ 240p",
"container": "mp4",
"rateControl": "vbr",
"video": {
"height": "240",
"width": "426",
"codec": "h264",
"bitrate": "1000000",
"gopSize": "90",
"gopMode": "fixed",
"profile": "main",
"profileLevel": "3.1",
"interlaceMode": "progressive"
},
"audio": {
"codec": "aac",
"bitrate": "64000"
}
}
You can create a preset by sending the follow request:
$ curl -X POST -d @preset.json http://api.host.com/presets
{
"name": "mp4_240p",
"description": "Encodes video in H264/MP4 @ 240p",
"container": "mp4",
"rateControl": "vbr",
"video": {
"height": "240",
"width": "426",
"codec": "h264",
"bitrate": "1000000",
"gopSize": "90",
"gopMode": "fixed",
"profile": "main",
"profileLevel": "3.1",
"interlaceMode": "progressive"
},
"audio": {
"codec": "aac",
"bitrate": "64000"
}
}
$ curl -X GET http://api.host.com/presets
[
{
"audio": {
"bitrate": "64000",
"codec": "aac"
},
"container": "mp4",
"description": "HLS 1080 for tests",
"name": "mp4_240p",
"rateControl": "vbr",
"video": {
"bitrate": "1000000",
"codec": "h264",
"gopMode": "fixed",
"gopSize": "90",
"height": "240",
"profile": "main",
"profileLevel": "3.1",
"interlaceMode": "progressive",
"width": "426"
}
},
{
"audio": {
"bitrate": "64000",
"codec": "vorbis"
},
"container": "webm",
"description": "WebM @ 720p",
"name": "webm_720p",
"rateControl": "vbr",
"video": {
"profile": "main",
"profileLevel": "3.1",
"bitrate": "1000000",
"codec": "vp8",
"gopMode": "fixed",
"gopSize": "90",
"height": "240",
"interlaceMode": "progressive",
"width": "426"
}
}
]
$ curl -X PUT -d @preset.json http://api.host.com/presets
< HTTP/1.1 200 OK
In order to create a job you need to specify a HTTP or S3 address of a source and a S3 address for the destination. Snickers only supports one preset per job but this problem is being addressed on issue #40.
The format of the S3 address should be:
http://AWSKEY:AWSSECRET@BUCKET.s3.amazonaws.com/DIRECTORY
See below an example of job.json
:
{
"source": "http://flv.io/KailuaBeach.mp4",
"destination": "http://AKIAII3C6HP:4wooQI51NXIN5ELJNTq@snickers-media.s3.amazonaws.com/outputs/",
"preset": "mp4_240p"
}
Then, make a POST request to the API:
$ curl -X POST -H "Content-Type: application/json" -d @job.json http://api.host.com/jobs
< HTTP/1.1 200 OK
$ curl -X GET http://api.host.com/jobs
< HTTP/1.1 200 OK
[
{
"destination": "http://AWSKEY:AWSSECRET@BUCKET.s3.amazonaws.com/OBJECT",
"id": "QWizjJwLP98LgTuQ",
"preset": {
"audio": {
"bitrate": "64000",
"codec": "vorbis"
},
"container": "webm",
"description": "WebM @ 720p",
"name": "webm_720p",
"rateControl": "vbr",
"video": {
"profile": "main",
"profileLevel": "3.1",
"bitrate": "1000000",
"codec": "vp8",
"gopMode": "fixed",
"gopSize": "90",
"height": "240",
"interlaceMode": "progressive",
"width": "426"
}
},
"progress": "",
"source": "http://flv.io/comingsoon.mov",
"status": "created"
}
]
With the job ID
:
$ curl -X GET http://api.host.com/jobs/QWizjJwLP98LgTuQ
{
"destination": "http://AWSKEY:AWSSECRET@BUCKET.s3.amazonaws.com/OBJECT",
"id": "QWizjJwLP98LgTuQ",
"preset": {
"audio": {
"bitrate": "64000",
"codec": "vorbis"
},
"container": "webm",
"description": "WebM @ 720p",
"name": "webm_720p",
"rateControl": "vbr",
"video": {
"profile": "main",
"profileLevel": "3.1",
"bitrate": "1000000",
"codec": "vp8",
"gopMode": "fixed",
"gopSize": "90",
"height": "240",
"interlaceMode": "progressive",
"width": "426"
}
},
"progress": "",
"source": "http://flv.io/comingsoon.mov",
"status": ""
}
With the job ID
:
$ curl -X GET http://api.host.com/jobs/QWizjJwLP98LgTuQ/start
Then you should request job details in order to follow the status
and progress
of each step (downloading, encoding, uploading).