-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
194 lines (178 loc) · 7.21 KB
/
index.html
File metadata and controls
194 lines (178 loc) · 7.21 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet">
<style>
:root {
--font: 'Work Sans', sans-serif;
--background: #151515;
--input: #353535;
--text: #fafafa;
--accent: #1f5e92;
}
body {
background-color: var(--background);
color: var(--text);
font-family: var(--font);
padding: 10px;
}
textarea,
button,
input:not([type=checkbox]) {
width: 100%;
width: -webkit-fill-available;
width: -moz-available;
font-family: var(--font);
padding: 10px;
border-radius: 8px;
border: 1px solid var(--text);
color: var(--text);
}
button {
background-color: var(--accent);
transition: 0.2s ease-in-out;
}
button:hover {
filter: brightness(150%);
}
button:active {
filter: brightness(175%);
scale: 0.95;
}
textarea,
input {
background-color: var(--input);
}
textarea {
height: 25vh;
}
.flex {
display: flex;
}
.hcenter {
align-items: center;
}
.gap {
gap: 10px;
}
a {
color: var(--text)
}
</style>
<title>FFmpeg Chapter</title>
</head>
<body>
<h1>FFmpeg Chapter Creator</h1>
<p>Paste the description timestamps here, or <span id="fileRead" style="text-decoration: underline;">read from a
file</span></p>
<textarea id="text"></textarea><br><br>
<label class="flex hcenter gap">
Divider:
<input id="divider" type="text">
</label><br>
<label class="flex hcenter gap">
Video length (in HH:MM:ss):
<input type="text" id="length">
<button id="getLength">Get from video</button>
</label><br>
<label class="flex hcenter gap">
<input type="checkbox" id="timestampRight"> The timestamp is at the right
</label>
<br><br>
<div class="flex gap">
<button id="download">Download FFmetadata
text</button>
<button id="share">Share file</button>
</div>
<div>
</div>
<br><br>
<p>You can add metadata in this way:
<code>ffmpeg -i video.mp4 -ffmetadata -i ffmetadata.txt -map_metadata 1 -c copy out.mp4</code><br>Otherwise,
<a target="_blank" href="https://dinoosauro.github.io/ffmpeg-merge-command/">click here to automatically
generate the script to copy</a> (you'll just need to choose the files and the
output extension)
</p>
<p>You can find more on the <a target="_blank" href="https://github.com/dinoosauro/ffmpeg-chapters-fetcher">GitHub
repository</a></p>
<script>
function getStr() {
let str = ";FFMETADATA1";
const divider = document.getElementById("divider").value;
const textSplit = document.getElementById("text").value;
const textSplitted = textSplit.split("\n");
for (let i = 0; i < textSplitted.length; i++) {
const currentStr = textSplitted[i];
const { timestamp, text } = getTimestampAndText(currentStr, divider);
if (currentStr.indexOf(divider) === -1) continue;
str += `\n[CHAPTER]\nTIMEBASE=1/1000000000\nSTART=${formatTimestamp(timestamp)}\nEND=${formatTimestamp(textSplitted[i + 1] ? getTimestampAndText(textSplitted[i + 1], divider).timestamp : (document.getElementById("length").value.trim() || "0"))}\ntitle=${text}`;
}
return str;
}
document.getElementById("download").onclick = () => {
Object.assign(document.createElement("a"), {
href: URL.createObjectURL(new Blob([getStr()], { type: "text/plain" })),
download: `ffmetadata-${Date.now()}.txt`
}).click();
};
document.getElementById("share").onclick = () => {
navigator.share({
files: [new File(getStr(), `ffmetadata-${Date.now()}.txt`, { type: "text/plain" })]
});
}
function getTimestampAndText(str, divider) {
const isTimestampAtRight = document.getElementById("timestampRight").checked;
const timestamp = str.substring(isTimestampAtRight ? str.lastIndexOf(divider) + divider.length : 0, isTimestampAtRight ? undefined : str.indexOf(divider));
const text = str.substring(isTimestampAtRight ? 0 : str.indexOf(divider) + divider.length, isTimestampAtRight ? str.lastIndexOf(divider) : undefined);
return { timestamp, text };
}
function formatTimestamp(timestamp) {
let returnInt = 0;
const splittedTimestamp = timestamp.split(":");
if (splittedTimestamp.length === 3) returnInt = (+splittedTimestamp[0] * 3600) + (+splittedTimestamp[1] * 60) + +splittedTimestamp[2]; else returnInt = (+splittedTimestamp[0] * 60) + +splittedTimestamp[1];
return `${returnInt}000000000`;
}
document.getElementById("getLength").onclick = () => {
Object.assign(document.createElement("input"), {
type: "file",
onchange: function (e) {
const video = Object.assign(document.createElement("video"), {
src: URL.createObjectURL(e.target.files[0]),
onloadedmetadata: function (e) {
let duration = e.target.duration;
let outputFormat = "";
let hoursAdded = false;
if (duration >= 3600) {
const hours = Math.floor(duration / 3600);
duration -= (hours * 3600);
outputFormat += `${hours}:`;
hoursAdded = true;
}
if (duration < 60 && hoursAdded) hoursAdded += "00:";
if (duration >= 60) {
const minutes = Math.floor(duration / 60);
duration -= (minutes * 60);
outputFormat += `${minutes}:`;
}
outputFormat += `${Math.floor(duration)}`;
document.getElementById("length").value = outputFormat;
}
})
}
}).click();
}
document.getElementById("fileRead").onclick = () => {
Object.assign(document.createElement("input"), {
type: "file",
onchange: async function (e) {
const text = await e.target.files[0].text();
document.getElementById("text").value = text;
}
}).click();
}
</script>
</body>
</html>