forked from Qencode-Corp/qencode-api-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_with_aws_signed_url.py
More file actions
89 lines (68 loc) · 1.94 KB
/
start_with_aws_signed_url.py
File metadata and controls
89 lines (68 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import qencode
import time
import json
from qencode import QencodeClientException, QencodeTaskException
from qencode import generate_aws_signed_url
# replace with your API KEY (can be found in your Project settings on Qencode portal)
API_KEY = 'your-api-qencode-key'
# request elements
region = 'us-east-2'
bucket = 'your-bucket-name'
object_key = 'path'
expiration = 86400 # time in seconds
access_key = 'your-AWS-access-key'
secret_key = 'your-AWS-secret-key'
# generate AWS signed url
source_url = generate_aws_signed_url(region, bucket, object_key, access_key, secret_key, expiration)
print(source_url)
format_240 = dict(
output="mp4",
size="320x240",
video_codec="libx264"
)
format_720 = dict(
output="mp4",
size="1280x720",
video_codec="libx264"
)
format = [format_240, format_720]
query = dict(
source=source_url,
format=format
)
params = dict(query=query)
def start_encode():
"""
Create client object
:param api_key: string. required
:param api_url: string. not required
:param api_version: int. not required. default 'v1'
:return: task object
"""
client = qencode.client(API_KEY)
if client.error:
raise QencodeClientException(client.message)
print('The client created. Expire date: {0}'.format(client.expire))
task = client.create_task()
if task.error:
raise QencodeTaskException(task.message)
task.custom_start(params)
if task.error:
raise QencodeTaskException(task.message)
print('Start encode. Task: {0}'.format(task.task_token))
line = "-"*80
while True:
print(line)
status = task.status()
# print status
print(json.dumps(status, indent=2, sort_keys=True))
if status['error'] or status['status'] == 'completed':
break
time.sleep(5)
if __name__ == '__main__':
start_encode()