-
Notifications
You must be signed in to change notification settings - Fork 5
/
multiple_uploads_parallel.html
304 lines (275 loc) · 10.7 KB
/
multiple_uploads_parallel.html
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>video-transcoder.online</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="tus.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/2.2.8/shaka-player.compiled.js"></script>
<script src="qencode.js"></script>
<link rel="stylesheet" href="progress-bar.css" />
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="form">
<div class="col-2">
<h2><a href="https://cloud.qencode.com">Qencode</a> Custom Job API Example:</h2>
<div>Choose file</div>
<div>
<input type="file" name="file" multiple>
</div>
<div>Or insert URL</div>
<div>
<input type="text" id="video_url" class="form-element" value="https://qa.qencode.com/static/1.mp4" />
</div>
<div>Output Format</div>
<div>
<select id="output_format" class="form-element" onchange="load_codecs()">
<option value="mp4">MP4</option>
<option value="advanced_hls">HLS</option>
<option value="advanced_dash">MPEG - DASH</option>
<option value="webm">WEBM</option>
</select>
</div>
<div>Video Codec</div>
<div>
<select id="video_codec" class="form-element">
<option value="libx264">H.264 (MPEG-4 Part 10)</option>
<option value="libx265">H.265 (MPEG-H PART2/HEVC)</option>
</select>
</div>
<div>Destination</div>
<div>
<input type="text" id="destination" class="form-element" />
</div>
<div>Size, px</div>
<div>
<input type="text" id="size_w" class="form-element-2" value="320" /> x
<input type="text" id="size_h" class="form-element-2" value="240" />
</div>
<div>Rotate, degrees</div>
<div>
<input type="text" id="rotate" class="form-element" value="0" />
</div>
<div>Framerate</div>
<div>
<input type="text" id="framerate" class="form-element" value="25" />
</div>
<div>Bitrate, kbps</div>
<div>
<input type="text" id="bitrate" class="form-element" value="300" />
</div>
<div>Pix Format</div>
<div>
<input type="text" id="pix_format" class="form-element" value="yuv420p" />
</div>
<div>Audio Codec</div>
<div>
<select id="audio_codec" class="form-element">
<option value="aac">AAC</option>
</select>
</div>
<div>Audio Bitrate</div>
<div>
<input type="text" id="audio_bitrate" class="form-element" value="64" />
</div>
<div>Audio Sample Rate</div>
<div>
<input type="text" id="audio_sample_rate" class="form-element" value="44100" />
</div>
<div id="segment_duration_block" class="invisible">
<div>Segment Duration, seconds</div>
<div>
<input type="text" id="segment_duration" class="form-element" value="8" />
</div>
</div>
<div id="keyframe_block" class="invisible">
<div>Keyframe interval</div>
<div>
<input type="text" id="keyframe" class="form-element" value="60" />
</div>
</div>
<div>
<button id="btn_ok2" class="form-element">OK</button>
</div>
<div>
<a href="/start_encode.html">See Preset Job API Example</a>
</div>
</div>
<div class="col-2">
<div class="wrapper" id="file_list">
</div>
<!-- <div class="progress-striped active">
<div class="progress-bar-0" id="bar-0" style="height: 20px;"></div>
<div class="progress-bar" id="bar" style="height: 20px;"></div>
</div> -->
<div class="player-container">
<video id="video" controls autoplay></video>
</div>
</div>
</div>
</body>
<script src="common.js"></script>
<script>
var btn = document.getElementById("btn_ok2");
btn.addEventListener("click", click_ok_btn);
var webm_codecs = {
"VP8": "libvpx",
"VP9": "libvpx-vp9"
};
var codecs = {
"H.264 (MPEG-4 Part 10)": "libx264",
"H.265 (MPEG-H PART2/HEVC)": "libx265"
};
var webm_audio = {
"Vorbis": "vorbis"
};
var audio = {
"AAC": "aac"
};
load_codecs = function() {
var $el2 = $("#audio_codec");
$el2.empty();
var $el = $("#video_codec");
$el.empty();
var output_format = $("#output_format option:selected").val();
if (output_format == 'webm') {
$.each(webm_codecs, function(key, value) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
$.each(webm_audio, function(key, value) {
$el2.append($("<option></option>")
.attr("value", value).text(key));
});
} else {
$.each(codecs, function(key, value) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
$.each(audio, function(key, value) {
$el2.append($("<option></option>")
.attr("value", value).text(key));
});
if (output_format != "advanced_hls") {
$("#segment_duration_block").addClass("invisible");
$("#keyframe_block").addClass("invisible");
} else {
$("#segment_duration_block").removeClass("invisible");
$("#keyframe_block").removeClass("invisible");
}
}
};
var qencode_arr = [];
function click_ok_btn() {
if (token != '') {
var output_format = $("#output_format option:selected").val();
var format = {
"output": $("#output_format option:selected").val(),
"destination": $("#destination").val()
};
if (output_format == "advanced_hls" || output_format == "advanced_dash") {
var stream = {
"size": $("#size_w").val() + "x" + $("#size_h").val(),
"rotate": $("#rotate").val(),
"framerate": $("#framerate").val(),
"bitrate": $("#bitrate").val(),
"pix_format": $("#pix_format").val(),
"video_codec": $("#video_codec option:selected").val(),
"audio_codec": $("#audio_codec option:selected").val(),
"audio_bitrate": $("#audio_bitrate").val(),
"audio_sample_rate": $("#audio_sample_rate").val()
};
if (output_format == "advanced_hls") {
stream['keyframe'] = $("#keyframe").val();
format["segment_duration"] = $("#segment_duration").val();
}
format["stream"] = [stream];
} else {
format["size"] = $("#size_w").val() + "x" + $("#size_h").val();
format["rotate"] = $("#rotate").val();
format["framerate"] = $("#framerate").val();
format["bitrate"] = $("#bitrate").val();
format["pix_format"] = $("#pix_format").val();
format["video_codec"] = $("#video_codec option:selected").val();
format["audio_codec"] = $("#audio_codec option:selected").val();
format["audio_bitrate"] = $("#audio_bitrate").val();
format["audio_sample_rate"] = $("#audio_sample_rate").val();
}
var data = [];
var file_input = $("input[name=file]").get(0);
if (file_input.files.length == 0) {
data.push({
"source": $("#video_url").val(),
"format": [format]
});
} else {
for (var i = 0; i < file_input.files.length; ++i) {
data.push({
"file": file_input.files[i],
"format": [format]
});
}
}
var options = {
interval: 15, //status polling interval
endpoint: 'https://api-qa.qencode.com' //api endpoint
};
if (qencode_arr) {
clear_previous_job_miltiple_uploads(qencode_arr);
}
for (var i = 0; i < data.length; i++) {
// var nn = 'Name'+i;
// var oo = new TestObject(nn);
// oo.start_custom();
run_qencode(data[i], options)
}
}
}
async function run_qencode(data, options) {
var name = '';
if (data.file) {
name = data.file.name;
} else {
var url = data.source.split("/");
var file_uuid = url[url.length - 1];
name = file_uuid;
}
var ss = new Qencode(token, {
"query": data
}, options);
qencode_arr.push(ss);
var is_good = await ss.create_task(function(start_response) {
if (!start_response.error) {
ss.status({
token: start_response.task_token,
url: start_response.status_url,
filename: name
},
poll_job_status_multiple_uploads
);
} else {
console.log("Error!!!")
console.log(start_response)
}
});
if (is_good) {
add_progress_bar(ss.task_token);
ss.start_custom(function(start_response) {
if (!start_response.error) {
ss.status({
token: start_response.task_token,
url: start_response.status_url,
filename: name
},
poll_job_status_multiple_uploads
);
} else {
console.log("Error!!!")
console.log(start_response)
}
}, update_multiple_upload_progress, 0, 10);
}
}
</script>
</html>