improve random segment generation

make sure random segment start time is also randomized
also clamp end time
pull/1437/head
Mikael Finstad 2023-01-20 00:12:19 +09:00
rodzic 4f018b0f12
commit 16c9f8b002
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 25AB36E3E81CBC26
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -359,8 +359,8 @@ export async function createRandomSegments(fileDuration) {
const randomInRange = (min, max) => min + Math.random() * (max - min);
const edl = [];
for (let start = 0; start < fileDuration && edl.length < maxSegments; start += randomInRange(gapMin, gapMax)) {
const end = start + randomInRange(durationMin, durationMax);
for (let start = randomInRange(gapMin, gapMax); start < fileDuration && edl.length < maxSegments; start += randomInRange(gapMin, gapMax)) {
const end = Math.min(fileDuration, start + randomInRange(durationMin, durationMax));
edl.push({ start, end });
start = end;
}