1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 18:32:34 +01:00

improve random segment generation

make sure random segment start time is also randomized
also clamp end time
This commit is contained in:
Mikael Finstad 2023-01-20 00:12:19 +09:00
parent 4f018b0f12
commit 16c9f8b002
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

View File

@ -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;
}