even more aard updates

This commit is contained in:
Tamius Han 2024-12-31 03:14:29 +01:00
parent 9c65300fc4
commit 14e1d6aad3
3 changed files with 44 additions and 21 deletions

View File

@ -10,7 +10,7 @@ import { GlCanvas } from './gl/GlCanvas';
import { AardCanvasStore } from './interfaces/aard-canvas-store.interface'; import { AardCanvasStore } from './interfaces/aard-canvas-store.interface';
import { AardDetectionSample, generateSampleArray, resetSamples } from './interfaces/aard-detection-sample.interface'; import { AardDetectionSample, generateSampleArray, resetSamples } from './interfaces/aard-detection-sample.interface';
import { AardStatus, initAardStatus } from './interfaces/aard-status.interface'; import { AardStatus, initAardStatus } from './interfaces/aard-status.interface';
import { AardTestResults, initAardTestResults, resetAardTestResults } from './interfaces/aard-test-results.interface'; import { AardTestResults, initAardTestResults, resetAardTestResults, resetGuardLine } from './interfaces/aard-test-results.interface';
import { AardTimers, initAardTimers } from './interfaces/aard-timers.interface'; import { AardTimers, initAardTimers } from './interfaces/aard-timers.interface';
@ -477,8 +477,12 @@ export class Aard {
if (this.testResults.notLetterbox) { if (this.testResults.notLetterbox) {
// TODO: reset aspect ratio to "AR not applied" // TODO: reset aspect ratio to "AR not applied"
this.testResults.lastStage = 1; this.testResults.lastStage = 1;
// we have a few things to do
// console.log('NOT LETTERBOX - resetting letterbox data')
this.testResults.letterboxWidth = 0; this.testResults.letterboxWidth = 0;
this.testResults.letterboxOffset = 0; this.testResults.letterboxOffset = 0;
resetGuardLine(this.testResults);
break; break;
} }
@ -500,7 +504,14 @@ export class Aard {
this.settings.active.arDetect.canvasDimensions.sampleCanvas.height this.settings.active.arDetect.canvasDimensions.sampleCanvas.height
); );
if (! this.testResults.guardLine.invalidated) { // If guardline was invalidated, letterbox width and offset are unreliable.
// If guardLine is fine but imageLine is invalidated, we still keep last letterbox settings
if (this.testResults.guardLine.invalidated) {
// console.log('GUARD LINE INVALIDATED - resetting letterbox data')
this.testResults.letterboxWidth = 0;
this.testResults.letterboxOffset = 0;
} else {
this.checkLetterboxGrow( this.checkLetterboxGrow(
imageData, imageData,
this.settings.active.arDetect.canvasDimensions.sampleCanvas.width, this.settings.active.arDetect.canvasDimensions.sampleCanvas.width,
@ -514,10 +525,6 @@ export class Aard {
// TODO: ensure no aspect ratio changes happen // TODO: ensure no aspect ratio changes happen
this.testResults.lastStage = 2; this.testResults.lastStage = 2;
break; break;
} else {
// our current letterbox width is now no longer accurate. Time to wipe.
this.testResults.letterboxWidth = 0;
this.testResults.letterboxOffset = 0;
} }
// STEP 3: // STEP 3:
@ -539,19 +546,17 @@ export class Aard {
// If forceFullRecheck is set, then 'not letterbox' should always force-reset the aspect ratio // If forceFullRecheck is set, then 'not letterbox' should always force-reset the aspect ratio
// (as aspect ratio may have been set manually while autodetection was off) // (as aspect ratio may have been set manually while autodetection was off)
if (this.testResults.notLetterbox) { if (this.testResults.notLetterbox) {
this.videoData.resizer.updateAr({ // console.log('————not letterbox')
type: AspectRatioType.AutomaticUpdate, this.updateAspectRatio(this.defaultAr);
ratio: this.defaultAr,
})
} }
// if detection is uncertain, we don't do anything at all (unless if guardline was broken, in which case we reset) // if detection is uncertain, we don't do anything at all (unless if guardline was broken, in which case we reset)
if (this.testResults.aspectRatioUncertain && this.testResults.guardLine.invalidated) { if (this.testResults.aspectRatioUncertain && this.testResults.guardLine.invalidated) {
console.info('aspect ratio not certain:', this.testResults.aspectRatioUncertainReason); // console.info('aspect ratio not certain:', this.testResults.aspectRatioUncertainReason);
console.warn('check finished:', JSON.parse(JSON.stringify(this.testResults)), JSON.parse(JSON.stringify(this.canvasSamples)), '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'); // console.warn('check finished:', JSON.parse(JSON.stringify(this.testResults)), JSON.parse(JSON.stringify(this.canvasSamples)), '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n');
if (this.testResults.guardLine.invalidated) { if (this.testResults.guardLine.invalidated) {
this.videoData.resizer.setAr({type: AspectRatioType.AutomaticUpdate, ratio: this.defaultAr}); this.updateAspectRatio(this.defaultAr);
} }
return; return;
@ -560,10 +565,11 @@ export class Aard {
// TODO: emit debug values if debugging is enabled // TODO: emit debug values if debugging is enabled
this.testResults.isFinished = true; this.testResults.isFinished = true;
console.warn( // console.warn(
`[${(+new Date() % 10000) / 100} | ${this.arid}]`,'check finished — aspect ratio updated:', this.testResults.aspectRatioUpdated, // `[${(+new Date() % 10000) / 100} | ${this.arid}]`,'check finished — aspect ratio updated:', this.testResults.aspectRatioUpdated,
'\nis video playing?', this.getVideoPlaybackState() === VideoPlaybackState.Playing, // '\ndetected ar:', this.testResults.activeAspectRatio, '->', this.getAr(),
'\n\n', JSON.parse(JSON.stringify(this.testResults)), JSON.parse(JSON.stringify(this.canvasSamples)), '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'); // '\nis video playing?', this.getVideoPlaybackState() === VideoPlaybackState.Playing,
// '\n\n', JSON.parse(JSON.stringify(this.testResults)), JSON.parse(JSON.stringify(this.canvasSamples)), '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n');
// if edge width changed, emit update event. // if edge width changed, emit update event.
// except aspectRatioUpdated doesn't get set reliably, so we just call update every time, and update // except aspectRatioUpdated doesn't get set reliably, so we just call update every time, and update
@ -1793,6 +1799,8 @@ export class Aard {
} }
this.testResults.aspectRatioUncertain = false; this.testResults.aspectRatioUncertain = false;
console.log('Updating letterboxWidth - as normal')
this.testResults.letterboxWidth = candidateAvg; this.testResults.letterboxWidth = candidateAvg;
this.testResults.letterboxOffset = diff; this.testResults.letterboxOffset = diff;
this.testResults.aspectRatioUpdated = true; this.testResults.aspectRatioUpdated = true;
@ -1801,14 +1809,14 @@ export class Aard {
/** /**
* Updates aspect ratio if new aspect ratio is different enough from the old one * Updates aspect ratio if new aspect ratio is different enough from the old one
*/ */
private updateAspectRatio() { private updateAspectRatio(overrideAr?: number) {
const ar = this.getAr(); const ar = overrideAr ?? this.getAr();
// Calculate difference between two ratios // Calculate difference between two ratios
const maxRatio = Math.max(ar, this.testResults.activeAspectRatio); const maxRatio = Math.max(ar, this.testResults.activeAspectRatio);
const diff = Math.abs(ar - this.testResults.activeAspectRatio); const diff = Math.abs(ar - this.testResults.activeAspectRatio);
if ((diff / maxRatio) > this.settings.active.arDetect.allowedArVariance) { if (overrideAr || (diff / maxRatio) > this.settings.active.arDetect.allowedArVariance) {
this.videoData.resizer.updateAr({ this.videoData.resizer.updateAr({
type: AspectRatioType.AutomaticUpdate, type: AspectRatioType.AutomaticUpdate,
ratio: this.getAr(), ratio: this.getAr(),

View File

@ -85,6 +85,21 @@ export function initAardTestResults(settings: AardSettings): AardTestResults {
} }
} }
export function resetGuardLine(results: AardTestResults) {
results.guardLine.top = -1;
results.guardLine.bottom = -1;
results.imageLine.invalidated = false;
results.guardLine.invalidated = false;
results.guardLine.cornerViolated[0] = false;
results.guardLine.cornerViolated[1] = false;
results.guardLine.cornerViolated[2] = false;
results.guardLine.cornerViolated[3] = false;
results.guardLine.cornerPixelsViolated[0] = 0;
results.guardLine.cornerPixelsViolated[1] = 0;
results.guardLine.cornerPixelsViolated[2] = 0;
results.guardLine.cornerPixelsViolated[3] = 0;
}
export function resetAardTestResults(results: AardTestResults): void { export function resetAardTestResults(results: AardTestResults): void {
results.isFinished = false; results.isFinished = false;
results.lastStage = 0; results.lastStage = 0;

View File

@ -112,7 +112,7 @@ class PageInfo {
} }
destroy() { destroy() {
this.logger.log('info', ['debug', 'init'], "[PageInfo::destroy] destroying all videos!") // this.logger.log('info', ['debug', 'init'], "[PageInfo::destroy] destroying all videos!")
if(this.rescanTimer){ if(this.rescanTimer){
clearTimeout(this.rescanTimer); clearTimeout(this.rescanTimer);
} }