Launching your first video transcoding job
Learn how to launch your first video transcoding job
1. Create a Project
The first step of lanching a transcoding task is creating a Project, which provides an API key used for authentication and tracking billing.
To create a Project, go to the Projects page and click + Add New Project.
If you already have a Project, proceed to to Step 2.
2. Authenticate API
The next step is to use the API instance is used to communicate with the Qencode REST API. To start, authenticate using your API key.
#!/usr/bin/python
#-*- coding: utf-8 -*-
import qencode
API_KEY = '5e9e7c7ed566e'
client = qencode.client(API_KEY)
3. Create a Task
After authenticating, create a task in order to start defining your transcoding settings.
task = client.create_task()
4. Define Output Settings
Now you can define the formats, codecs, resolution and combination of settings for each of the outputs you want to create using the format object.
{
"query": {
"format": [
{
"output": "mp4",
"size": "1920x1080",
"profile": "main",
"bitrate": 4800,
"video_codec": "libx264"
},
{
"output": "mp4",
"size": "1280x720",
"profile": "main",
"bitrate": 3800,
"video_codec": "libx264"
},
{
"output": "mp4",
"size": "960x540",
"profile": "main",
"bitrate": 3000,
"video_codec": "libx264"
},
{
"output": "mp4",
"size": "640x360",
"profile": "main",
"bitrate": 1800,
"video_codec": "libx264"
},
{
"output": "mp4",
"size": "426x240",
"profile": "main",
"bitrate": 1200,
"video_codec": "libx264"
},
{
"output": "advanced_hls",
"optimize_bitrate": 0,
"stream": [
{
"size": "1920x1080",
"profile": "main",
"bitrate": 4800,
"video_codec": "libx264"
},
{
"size": "1280x720",
"profile": "main",
"bitrate": 3800,
"video_codec": "libx264"
},
{
"size": "960x540",
"profile": "main",
"bitrate": 3000,
"video_codec": "libx264"
},
{
"size": "640x360",
"profile": "main",
"bitrate": 1800,
"video_codec": "libx264"
},
{
"size": "426x240",
"profile": "main",
"bitrate": 1200,
"video_codec": "libx264"
}
]
}
],
"source": "https://nyc3.s3.qencode.com/qencode/samples/1080-sample.mov"
}
}
5. Starting a Transcoding Task
Now that all the settings have been defined, it's time to start your transcoding tasks. Run the code below to kick off the process using the settings you've just defined.
For this tutorial, we will be using the /v1/start_encode2api method, which enables you to create full transcoding workflows using only the API. Encoding with the Custom Tasks also also offers a wider range of settings which can be used to fine tune your transcoding results.
task.start_custom(QUERY)
6. Checking Status
There are a few approaches to tracking status for transcoding tasks after they have started.
The first is by using Callback URls (Webhooks) to automatically receive changes in status, including updates when the job is complete. You can read a full guide on how to set up Callback URLs here.
The second option is using the /v1/status method and providing a list of tokens
to get the status for.
You can even set up a script on your end to get the status updates on a job in real-time. Here's an example of what a script like that could look like:
import time
import json
# using while loop
while 1:
status = task.status()
print json.dumps(status, indent=2, sort_keys=True)
if status['error'] or status['status'] == 'completed':
break
time.sleep(3)
# using callback methods
def progress_changed_handler(status):
if status['status'] != 'completed':
print json.dumps(status, indent=2, sort_keys=True)
def task_completed_handler(status, task_token):
print 'Completed task: %s' % task_token
print json.dumps(status, indent=2, sort_keys=True)
task.progress_changed(progress_changed_handler)
task.task_completed(task_completed_handler, task.task_token)
POSSIBLE STATUS VALUES
downloading | Video is being downloaded to Qencode server. |
queued | Task is waiting for available encoders. |
encoding | Video is being transcoded. |
saving | Video is being saved to destination location. |
completed | The transcoding job has completed successfully and the videos were saved to the destination. |