|
| 1 | +##Usage |
| 2 | + |
| 3 | +**Usage by transcoding profile ID** |
| 4 | + |
| 5 | +```` |
| 6 | +import sys |
| 7 | +import os.path |
| 8 | +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) |
| 9 | +import qencode |
| 10 | +import time |
| 11 | +
|
| 12 | +
|
| 13 | +API_KEY = 'Your API KEY' |
| 14 | +TRANSCODING_PROFILEID = 'Your profile ID' |
| 15 | +VIDO_URL = 'your source url' |
| 16 | +
|
| 17 | +
|
| 18 | +
|
| 19 | +def start_encode(): |
| 20 | + """ |
| 21 | + Create client object |
| 22 | + :param api_key: string. required |
| 23 | + :param api_url: string. not required |
| 24 | + :param api_version: int. not required. default 'v1' |
| 25 | + :return: client object |
| 26 | + """ |
| 27 | + client = qencode.client(API_KEY) |
| 28 | + client.create() |
| 29 | + if client.error: |
| 30 | + print 'encoder error:', client.error, client.message |
| 31 | + raise SystemExit |
| 32 | +
|
| 33 | + """ |
| 34 | + :return: task object |
| 35 | + """ |
| 36 | + task = client.create_task() |
| 37 | + task.start_time = 0.0 |
| 38 | + task.duration = 10.0 |
| 39 | + task.start(TRANSCODING_PROFILEID, VIDO_URL) |
| 40 | + if task.error: |
| 41 | + print 'task error:', task.error, task.message |
| 42 | + raise SystemExit |
| 43 | +
|
| 44 | + while True: |
| 45 | + status = task.status() |
| 46 | + print '{0} | {1} | {2} | error: {3}'.format(VIDO_URL, |
| 47 | + status.get('status'), |
| 48 | + status.get('percent'), |
| 49 | + status.get('error'), |
| 50 | + status.get('error_description')) |
| 51 | + if status['error']: |
| 52 | + break |
| 53 | + if status['status'] == 'completed': |
| 54 | + break |
| 55 | + time.sleep(15) |
| 56 | +
|
| 57 | +
|
| 58 | +if __name__ == '__main__': |
| 59 | + start_encode() |
| 60 | +```` |
| 61 | + |
| 62 | +**Usage by custom parameters** |
| 63 | + |
| 64 | +```` |
| 65 | +import sys |
| 66 | +import os.path |
| 67 | +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) |
| 68 | +import qencode |
| 69 | +import time |
| 70 | +
|
| 71 | +API_KEY = 'Your API KEY' |
| 72 | +
|
| 73 | +params = qencode.custom_params() |
| 74 | +
|
| 75 | +FORMAT = qencode.format() |
| 76 | +STREAM = qencode.stream() |
| 77 | +DESTINATION = qencode.destination() |
| 78 | +VIDEO_CODEC = qencode.x264_video_codec() |
| 79 | +
|
| 80 | +
|
| 81 | +DESTINATION.url = "..." |
| 82 | +DESTINATION.key = "..." |
| 83 | +DESTINATION.secret = "..." |
| 84 | +DESTINATION.remove_null_params() |
| 85 | +
|
| 86 | +VIDEO_CODEC.vprofile = "baseline" |
| 87 | +VIDEO_CODEC.level = 31 |
| 88 | +VIDEO_CODEC.coder = 0 |
| 89 | +VIDEO_CODEC.flags2 = "-bpyramid+fastpskip-dct8x8" |
| 90 | +VIDEO_CODEC.partitions = "+parti8x8+parti4x4+partp8x8+partb8x8" |
| 91 | +VIDEO_CODEC.directpred = 2 |
| 92 | +VIDEO_CODEC.remove_null_params() |
| 93 | +
|
| 94 | +STREAM.profile = "baseline" |
| 95 | +STREAM.size = "1920x1080" |
| 96 | +STREAM.audio_bitrate = 128 |
| 97 | +STREAM.video_codec_parameters = VIDEO_CODEC |
| 98 | +STREAM.remove_null_params() |
| 99 | +
|
| 100 | +FORMAT.stream = [STREAM] |
| 101 | +FORMAT.output = "advanced_hls" |
| 102 | +FORMAT.destination = DESTINATION |
| 103 | +FORMAT.remove_null_params() |
| 104 | +
|
| 105 | +params.source = 'your source url' |
| 106 | +params.format = [FORMAT] |
| 107 | +
|
| 108 | +
|
| 109 | +def start_encode(): |
| 110 | +
|
| 111 | + """ |
| 112 | + Create client object |
| 113 | + :param api_key: string. required |
| 114 | + :param api_url: string. not required |
| 115 | + :param api_version: int. not required. default 'v1' |
| 116 | + :return: client object |
| 117 | + """ |
| 118 | + client = qencode.client(API_KEY) |
| 119 | + client.create() |
| 120 | + if client.error: |
| 121 | + print 'encoder error:', client.error, client.message |
| 122 | + raise SystemExit |
| 123 | +
|
| 124 | + """ |
| 125 | + Create task |
| 126 | + :return: task object |
| 127 | + """ |
| 128 | +
|
| 129 | + task = client.create_task() |
| 130 | + task.custom_start(params) |
| 131 | + if task.error: |
| 132 | + print 'task error:', task.error, task.message |
| 133 | + raise SystemExit |
| 134 | +
|
| 135 | + while True: |
| 136 | + status = task.status() |
| 137 | + print '{0} | {1} | {2} | error: {3}'.format(params.source, |
| 138 | + status.get('status'), |
| 139 | + status.get('percent'), |
| 140 | + status.get('error'), |
| 141 | + status.get('error_description')) |
| 142 | + if status['error']: |
| 143 | + break |
| 144 | + if status['status'] == 'completed': |
| 145 | + break |
| 146 | + time.sleep(15) |
| 147 | +
|
| 148 | +
|
| 149 | +if __name__ == '__main__': |
| 150 | + start_encode() |
| 151 | +```` |
| 152 | +**Usage with callback methods** |
| 153 | + |
| 154 | +```` |
| 155 | +def my_callback(e): |
| 156 | + print e |
| 157 | +
|
| 158 | +def my_callback2(e): |
| 159 | + print e |
| 160 | + |
| 161 | +... |
| 162 | +
|
| 163 | +task.start(TRANSCODING_PROFILEID, VIDO_URL) |
| 164 | +if task.error: |
| 165 | + raise SystemExit |
| 166 | +
|
| 167 | +task.progress_changed(my_callback) |
| 168 | +task.task_completed(my_callback2) |
| 169 | +```` |
| 170 | + |
| 171 | +**Documentation** |
| 172 | + |
| 173 | +Documentation is available at <https://docs.qencode.com> |
0 commit comments