Apdejt (mp4 generiranje, razne fore)

master
Jure Podgoršek 2017-12-06 00:55:19 +01:00
parent c2f41eec97
commit c3b30dd59f
3 changed files with 111 additions and 29 deletions

View File

@ -66,7 +66,7 @@
animation-timing-function: linear; animation-timing-function: linear;
height: 30px; height: 30px;
width: 30px; width: 30px;
border: 8px solid black; border: 8px solid white;
border-right-color: transparent; border-right-color: transparent;
border-radius: 50%; border-radius: 50%;
display: inline-block; display: inline-block;
@ -84,7 +84,7 @@
</head> </head>
<body> <body>
<div style="font-size: 1.2rem"> <div style="font-size: 1.2rem">
Katero število med 1 in 1000 imaš v mislih? Izberi trejler (1 do 1000):
<input id="stevilo" type="text" style="font-size: 1.2rem;background:black;color:white;border-radius:2px;" /> <input id="stevilo" type="text" style="font-size: 1.2rem;background:black;color:white;border-radius:2px;" />
<button id="gumb" style="font-size: 1.2rem;color:white;background:black;border:1px solid white;border-radius:2px;">klik</button> <button id="gumb" style="font-size: 1.2rem;color:white;background:black;border:1px solid white;border-radius:2px;">klik</button>
</div> </div>
@ -93,7 +93,7 @@
<video style="width: 100%; margin-top: .5rem;" id="televizija" controls> <video style="width: 100%; margin-top: .5rem;" id="televizija" controls>
Žal gostujoč kos tehnike ni adekvaten. Žal gostujoč kos tehnike ni adekvaten.
</video> </video>
<div class="loading-spinner" style="display: none" id="loader"></div> <div class="loading-spinner" style="display: none;" id="loader"></div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
@ -103,6 +103,8 @@
var loader = document.getElementById("loader"); var loader = document.getElementById("loader");
var st = 0; var st = 0;
var loading = null;
function pridobiPosnetek() { function pridobiPosnetek() {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.open("GET", "/nepovednik/nepoved/" + st, true); xhttp.open("GET", "/nepovednik/nepoved/" + st, true);
@ -111,15 +113,12 @@
var resp = this.responseText; var resp = this.responseText;
if (resp === "zacetek" || resp === "cakaj") { if (resp === "zacetek" || resp === "cakaj") {
setTimeout(pridobiPosnetek, 3000); loading = setTimeout(pridobiPosnetek, 3000);
} else { } else {
loader.style.display = "none"; loader.style.display = "none";
//var src = document.createElement("source");
//src.src = resp;
//src.type = "video/webm";
//tv.appendChild(src);
tv.src = '/nepovednik' + resp; tv.src = '/nepovednik' + resp;
tv.play(); tv.play();
loading = null;
} }
} }
}; };
@ -134,16 +133,15 @@
if (isNaN(st) || st < 0 || st > 1000) { if (isNaN(st) || st < 0 || st > 1000) {
stel.style.backgroundColor = "darksalmon"; stel.style.backgroundColor = "darksalmon";
} else { } else {
if (loading) return;
stel.style.backgroundColor = "transparent"; stel.style.backgroundColor = "transparent";
loader.style.display = "block"; loader.style.display = "block";
tv.pause(); tv.pause();
tv.src = null;
pridobiPosnetek(); pridobiPosnetek();
} }
} }
function klik(e) { function klik(e) {
console.log("kliK!");
if (e.keyCode == 13) { if (e.keyCode == 13) {
proziPosnetek(); proziPosnetek();
} }
@ -151,6 +149,12 @@
stel.onkeypress = klik; stel.onkeypress = klik;
// Prvi posnetek je random
var initNum = Math.ceil(Math.random() * 1000);
st = initNum;
stel.value = initNum;
pridobiPosnetek();
</script> </script>
</body> </body>
</html> </html>

7
manjka.sh 100755
View File

@ -0,0 +1,7 @@
#!/bin/bash
for i in $(seq 1 1000); do
if [ ! -e nepovedi/$i.mp4 ] || [ ! -e nepovedi/$i.webm ]; then
echo $i
fi
done

View File

@ -45,11 +45,14 @@ const generator = new MersenneTwister(stTrejlerja);
let videi = []; let videi = [];
let stevec = 0; let stevec = 0;
fs.readdirSync(videiDir).map(file => { function readFolder (path) {
ffmpeg.ffprobe(videiDir + file, (err, metadata) => { fs.readdirSync(path).map(file => {
//console.log(file);
if (fs.lstatSync(path + file).isFile()) {
ffmpeg.ffprobe(path + file, (err, metadata) => {
videi.push({ videi.push({
name: file.substr(0, file.length - 3), name: file.substr(0, file.length - 3),
path: videiDir + file, path: path + file,
length: metadata.streams[0].duration length: metadata.streams[0].duration
}); });
@ -59,10 +62,22 @@ fs.readdirSync(videiDir).map(file => {
}); });
stevec += 1; stevec += 1;
}); } else {
readFolder(path + file + '/');
}
});
}
function imeKosa(st) { readFolder(videiDir);
return stTrejlerja + '_' + st + '.webm';
function imeKosa(st, apple = false) {
let ext = '.webm';
if (apple) {
ext = '.mp4';
}
return stTrejlerja + '_' + st + ext;
} }
@ -83,7 +98,7 @@ function razsekaj(videi) {
trajanje = parseFloat((trenutniV.length - zacetek).toFixed(2)); trajanje = parseFloat((trenutniV.length - zacetek).toFixed(2));
} }
let cmd = "ffmpeg -y -ss " + toHHMMSS(zacetek) + " -i " + trenutniV.path.replace(/([\s()&])/g, "\\$1") + " -t " + toHHMMSS(trajanje) + " -vcodec libvpx -cpu-used -5 -deadline realtime -acodec libvorbis -max_muxing_queue_size 400 ./kosi/" + imeKosa(stKosov); let cmd = "ffmpeg -y -ss " + toHHMMSS(zacetek) + " -i " + trenutniV.path.replace(/([\s()&'])/g, "\\$1") + " -t " + toHHMMSS(trajanje) + " -vcodec libvpx -cpu-used -5 -deadline realtime -vf scale=1280:720 -ac 1 -acodec libvorbis -ab 192k -ar 44100 -max_muxing_queue_size 400 ./kosi/" + imeKosa(stKosov);
exec(cmd, function (error, stdout, stderr) { exec(cmd, function (error, stdout, stderr) {
if (error !== null) { if (error !== null) {
console.log("Napaka!", error); console.log("Napaka!", error);
@ -93,7 +108,26 @@ function razsekaj(videi) {
stKoncanih += 1; stKoncanih += 1;
if ((dolzina > dolzinaT) && (stKoncanih === (stKosov - 1))) { if ((dolzina > dolzinaT) && (stKoncanih === (stKosov - 1)*2)) {
console.log("konvertirani vsi.");
console.log("polna dolzina: " + dolzina);
console.log("dajmo jih zlepit. (" + (stKosov - 1) + ")");
zlepi();
}
});
let cmd_apple = "ffmpeg -y -ss " + toHHMMSS(zacetek) + " -i " + trenutniV.path.replace(/([\s()&'])/g, "\\$1") + " -t " + toHHMMSS(trajanje) + " -vcodec libx264 -b 850k -vf scale=1280:720 -acodec aac -ar 44100 -ab 128k ./kosi/" + imeKosa(stKosov, true);
//console.log(cmd_apple);
exec(cmd_apple, function (error, stdout, stderr) {
if (error !== null) {
console.log("Napaka!", error);
console.log(stderr);
process.exit(1);
}
stKoncanih += 1;
if ((dolzina > dolzinaT) && (stKoncanih === (stKosov - 1)*2)) {
console.log("konvertirani vsi."); console.log("konvertirani vsi.");
console.log("polna dolzina: " + dolzina); console.log("polna dolzina: " + dolzina);
console.log("dajmo jih zlepit. (" + (stKosov - 1) + ")"); console.log("dajmo jih zlepit. (" + (stKosov - 1) + ")");
@ -107,6 +141,8 @@ function razsekaj(videi) {
} }
function zlepi() { function zlepi() {
let lepila = 2;
let cmd = 'mkvmerge -o ./nepovedi/' + stTrejlerja + '.webm ./kosi/' + imeKosa(1); let cmd = 'mkvmerge -o ./nepovedi/' + stTrejlerja + '.webm ./kosi/' + imeKosa(1);
for (let i = 2; i < stKosov; i++) { for (let i = 2; i < stKosov; i++) {
cmd += ' + ./kosi/' + imeKosa(i); cmd += ' + ./kosi/' + imeKosa(i);
@ -124,10 +160,45 @@ function zlepi() {
console.log("Koncano!"); console.log("Koncano!");
for(let j = 1; j < stKosov; j++) { for(let j = 1; j < stKosov; j++) {
//fs.unlinkSync('./kosi/' + imeKosa(j)); fs.unlinkSync('./kosi/' + imeKosa(j));
} }
lepila -= 1;
if (lepila == 0) {
fs.unlinkSync(najava); fs.unlinkSync(najava);
process.exit(0); process.exit(0);
}
});
let cmd_apple = 'MP4Box -force-cat -add ./kosi/' + imeKosa(1, true);
for (let i = 2; i < stKosov; i++) {
cmd_apple += ' -cat ./kosi/' + imeKosa(i, true);
}
cmd_apple += ' -new ./nepovedi/' + stTrejlerja + '.mp4';
exec(cmd_apple, function (error, stdout, stderr) {
if (error !== null) {
console.log("problem pri lepljenju.");
console.log(error);
console.log(stdout);
console.log(stderr);
process.exit(1);
}
console.log("Koncano!");
for(let j = 1; j < stKosov; j++) {
fs.unlinkSync('./kosi/' + imeKosa(j, true));
}
lepila -= 1;
if (lepila == 0) {
fs.unlinkSync(najava);
process.exit(0);
}
}); });
} }