1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

thumbnail queue algorithm

Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
This commit is contained in:
mrjvs 2023-10-21 14:17:14 +02:00
parent 3f9f072ab7
commit 46cb7793c2

View file

@ -5,6 +5,22 @@ import { ThumbnailImage } from "@/stores/player/slices/thumbnails";
import { usePlayerStore } from "@/stores/player/store"; import { usePlayerStore } from "@/stores/player/store";
import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities"; import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities";
function makeQueue(layers: number): number[] {
const output = [0, 1];
let segmentSize = 0.5;
let lastSegmentAmount = 0;
for (let layer = 0; layer < layers; layer += 1) {
const segmentAmount = 1 / segmentSize - 1;
for (let i = 0; i < segmentAmount - lastSegmentAmount; i += 1) {
const offset = i * segmentSize * 2;
output.push(offset + segmentSize);
}
lastSegmentAmount = segmentAmount;
segmentSize /= 2;
}
return output;
}
class ThumnbnailWorker { class ThumnbnailWorker {
interrupted: boolean; interrupted: boolean;
@ -86,12 +102,7 @@ class ThumnbnailWorker {
if (!vid) return; if (!vid) return;
await this.initVideo(); await this.initVideo();
// TODO make a queue based on refinement algorithm const queue = makeQueue(6); // 7 layers is 63 thumbnails evenly distributed
const sections = 50;
const queue = Array(sections + 1)
.fill(0)
.map((_, i) => i / sections);
for (let i = 0; i < queue.length; i += 1) { for (let i = 0; i < queue.length; i += 1) {
if (this.interrupted) return; if (this.interrupted) return;
await this.takeSnapshot(vid.duration * queue[i]); await this.takeSnapshot(vid.duration * queue[i]);