Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/hub/controllers/VideoController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class VideoController implements TabController {
private fps: number | null = null;
private totalFrames: number | null = null;
private completedFrames: number | null = null;
private matchStartFrame = -1;
private autoEndFrame = -1;

private locked: boolean = false;
private lockedStartLog: number = 0;
Expand Down Expand Up @@ -328,24 +328,27 @@ export default class VideoController implements TabController {
}

// Lock time when match start frame received
if (this.matchStartFrame <= 0 && data.matchStartFrame > 0 && !this.locked) {
let enabledTime: number | null = null;
if (this.autoEndFrame <= 0 && data.autoEndFrame > 0 && !this.locked) {
let autoEndTime: number | null = null;
let enabledData = getEnabledData(window.log);
if (enabledData) {
let wasEnabledLastCycle: boolean = false;
for (let i = 0; i < enabledData.timestamps.length; i++) {
if (enabledData.values[i]) {
enabledTime = enabledData.timestamps[i];
if (wasEnabledLastCycle && !enabledData.values[i]) {
autoEndTime = enabledData.timestamps[i];
break;
}

wasEnabledLastCycle = enabledData.values[i];
}
}
if (enabledTime !== null) {
if (autoEndTime !== null) {
this.playing = false;
this.locked = true;
this.lockedStartLog = enabledTime - (data.matchStartFrame - 1) / this.fps!;
this.lockedStartLog = autoEndTime - (data.autoEndFrame - 1) / this.fps!;
}
}
this.matchStartFrame = data.matchStartFrame;
this.autoEndFrame = data.autoEndFrame;
} else {
// Start to load new source, reset controls
this.locked = false;
Expand Down
34 changes: 17 additions & 17 deletions src/main/electron/VideoProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class VideoProcessor {
let height = 0;
let durationSecs = 0;
let completedFrames = 0;
let matchStartFrame = -1;
let autoEndFrame = -1;
let timerSample = 0;
let timerValues: { frame: number; text: string }[] = [];
let timerStartFound = false;
Expand Down Expand Up @@ -440,32 +440,32 @@ export class VideoProcessor {
timerValues.push({ frame: sampleFrame, text: timerText });
timerValues.sort((a, b) => a.frame - b.frame);

// Search for 13 -> 12 transition
let lastIs13 = false;
let secs13Frame: number | null = null;
// Search for 4 -> 3 transition
let lastIs4 = false;
let secs4Frame: number | null = null;
for (let i = 0; i < timerValues.length; i++) {
let is13 = timerValues[i].text.includes("13");
let is12 = !is13 && timerValues[i].text.includes("12");
if (lastIs13 && is12) {
secs13Frame = timerValues[i - 1].frame;
let is4 = timerValues[i].text.includes("04");
let is3 = !is4 && timerValues[i].text.includes("03");
if (lastIs4 && is3) {
secs4Frame = timerValues[i - 1].frame;
break;
}
lastIs13 = is13;
lastIs4 = is4;
}
if (secs13Frame === null) return;
if (secs4Frame === null) return;
timerStartFound = true;

// Find exact frame
let jobs: Promise<string>[] = [];
for (let frame = secs13Frame; frame < secs13Frame + fps; frame++) {
for (let frame = secs4Frame; frame < secs4Frame + fps; frame++) {
jobs.push(this.readTimerText(cachePath + zfill(frame.toString(), 8) + ".jpg", width, height));
}
const results = await Promise.all(jobs);
results.forEach((timerText, index) => {
if (matchStartFrame > 0) return;
if (timerText.includes("12")) {
let secs12Frame = secs13Frame! + index;
matchStartFrame = Math.round(secs12Frame - fps * 3);
if (autoEndFrame > 0) return;
if (timerText.includes("03")) {
let secs3Frame = secs4Frame! + index;
autoEndFrame = Math.round(secs3Frame + fps * 3);
}
});
}
Expand All @@ -481,7 +481,7 @@ export class VideoProcessor {
fps: fps,
totalFrames: Math.round(durationSecs * fps),
completedFrames: completedFrames,
matchStartFrame: matchStartFrame
autoEndFrame: autoEndFrame
});
}
});
Expand All @@ -496,7 +496,7 @@ export class VideoProcessor {
fps: fps,
totalFrames: completedFrames, // In case original value was inaccurate
completedFrames: completedFrames,
matchStartFrame: matchStartFrame
autoEndFrame: autoEndFrame
});
} else if (code === 1) {
if (videoCache === VIDEO_CACHE && fullOutput.includes("No space left on device")) {
Expand Down