-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
144 lines (134 loc) · 5.44 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CrafyVideoJS</title>
<script src="MP4Box_minified.js"></script>
<script src="CrafyVideoJS.js"></script>
<style>
body {
color: #fff;
background-color: #000;
}
video {
max-width: 100%;
}
</style>
</head>
<body>
<h1>CrafyVideoJS</h1>
<a href="simple.html">Simple version</a>
<p><b>Input video:</b></p>
<div>
<span>Start time:</span>
<input type="number" placeholder="Seconds" id="start_time_input" oninput="updateInputConfigs();">
</div>
<div>
<span>End time:</span>
<input type="number" placeholder="Seconds" id="end_time_input" oninput="updateInputConfigs();">
</div>
<div>
<span>Max bitrate:</span>
<input type="number" placeholder="Bitrate" id="max_bitrate_input" oninput="updateInputConfigs();">
</div>
<div>
<span>Max resolution:</span>
<select id="max_resolution_select" oninput="updateInputConfigs();">
<option value="">off</option>
<option value="3840">4K</option>
<option value="1920">1080p</option>
<option value="1280">720p</option>
<option value="640">480p</option>
</select>
</div>
<input type="file" onchange="onInputFileChange(event.target.files[0])" accept="video/mp4"></input>
<p id="progress_text"></p>
<p><b>Output video:</b></p>
<video src="" id="output_video" controls></video>
<script>
var CrafyVideoJS_instance = new CrafyVideoJS(true);
var startTime = false;
var endTime = false;
var maxBitrate = false;
var maxResolution = false;
var start_time_input = document.getElementById('start_time_input');
var end_time_input = document.getElementById('end_time_input');
var max_bitrate_input = document.getElementById('max_bitrate_input');
var max_resolution_select = document.getElementById('max_resolution_select');
function updateInputConfigs() {
if (parseInt(start_time_input.value) > 0) {
startTime = parseInt(start_time_input.value) * 1000000;
} else {
startTime = false;
}
if (parseInt(end_time_input.value) > 0) {
endTime = parseInt(end_time_input.value) * 1000000;
} else {
endTime = false;
}
if (parseInt(max_bitrate_input.value) > 0) {
maxBitrate = parseInt(max_bitrate_input.value);
} else {
maxBitrate = false;
}
if (parseInt(max_resolution_select.value) > 0) {
maxResolution = parseInt(max_resolution_select.value);
} else {
maxResolution = false;
}
}
function onInputFileChange(file) {
var reader = new FileReader();
reader.onload = async function () {
CrafyVideoJS_instance.onResult = function (result) {
console.log('Result:', result);
document.getElementById('progress_text').innerText = 'Completed in ' + result['reencoding_time_seconds'] + ' seconds. ';
if (result['reencoding_video_fps']) {
document.getElementById('progress_text').innerText += 'Video processing: ' + result['reencoding_video_fps'] + ' fps. ';
}
if (result['reencoding_audio_fps']) {
document.getElementById('progress_text').innerText += 'Audio processing: ' + result['reencoding_audio_fps'] + ' fps. ';
}
document.getElementById('output_video').src = URL.createObjectURL(new Blob([result['video_array_buffer']], { type: "video/mp4" }));
};
CrafyVideoJS_instance.onProgress = function (progressData) {
document.getElementById('progress_text').innerText = '';
if (progressData['video']) {
document.getElementById('progress_text').innerText += `
Video: `+ progressData['video']['decoding']['percentage'] + `% decoded, total: ` + progressData['video']['decoding']['count'] + `, ` + progressData['video']['encoding']['percentage'] + `% encoded.
Decoding ETA: `+ Math.round(progressData['video']['decoding']['eta'] / 1000) + ` seconds.
Encoding ETA: `+ Math.round(progressData['video']['encoding']['eta'] / 1000) + ` seconds.
`;
}
if (progressData['audio']) {
document.getElementById('progress_text').innerText += `
Audio: `+ progressData['audio']['decoding']['percentage'] + `% decoded, ` + progressData['audio']['encoding']['percentage'] + `% encoded.
`;
}
if (progressData['video']['eta']) {
document.getElementById('progress_text').innerText += `
Total ETA: `+ Math.round(progressData['video']['eta'] / 1000) + ` seconds.
`;
}
};
CrafyVideoJS_instance.onError = function (error) {
CrafyVideoJS_instance.onProgress = function (progressData) { };
document.getElementById('progress_text').innerText = 'Processing error!';
console.error('Handled error:', error);
};
CrafyVideoJS_instance.processVideo({
file: this.result,
start_timestamp: startTime,
end_timestamp: endTime,
max_video_bitrate: maxBitrate,
max_video_resolution: maxResolution
});
};
reader.readAsArrayBuffer(file);
}
</script>
<p>Github repository: <a href="https://github.com/chijete/CrafyVideoJS">https://github.com/chijete/CrafyVideoJS</a></p>
<p>Made with 💙 by <a href="https://chijete.com/">Crafy Holding</a>.</p>
</body>
</html>