timotheeg / nestrischamps

A web-based OCR and restreamer system for NES Classic Tetris players
MIT License
45 stars 11 forks source link

Increase size of frame buffer to correct interlacing anomalies #109

Closed timotheeg closed 2 years ago

timotheeg commented 2 years ago

Depending on multiple factor, like the capture frame rate, the source console or clone, or the make of the AV capture device, ocr anomalies may persists over multiple frames and mess up with nestrischamps stats tracking. See the sequence of score from a game during the Illinois qualifier 2022:

NTC has a 1 frame buffer to catch and correct anomalies, but it looks like it is not enough. Experiment with increasing the size of the frame buffer to 2, 3, or even 4 frames (or some manual entry). a larger frame buffer adds delay in relation to the player video, but it might be worth it, 4 frame at 60fps is 64ms, 4 frames at 30fps capture is 128ms.

...
151620
157380 // wrong
157380 // wrong - accepted
152380 // single - ignored
...
152380
153140 // single - ignored
...
153140
153900 // single - ignored
...
153900
155800 // double - ignored
...
155800
156560 // single - ignored
...
156560 
157320 // single - ignored
...
157320
158080 // single - accepted (bigger than 157380!)
...
158080
159980 // double
...
159980
187780 // wrong
187780 // wrong - accepted
182780 // tetris - ignored
...
182780
705580 // wrong - accepted immediately, ntc was waiting for a good frame
205580 // tetris - ignored
...
<frozen at 705580 - needs refresh>
timotheeg commented 2 years ago

Done and released with https://github.com/timotheeg/nestrischamps/commit/cad79765569500fef05b118047c8e81d79be0694

Add parameter fixbuffer=N, where N is between 1 and 5 to the OCR page's URL to use a larger buffer.

I streamed with fixbuffer=4 yesterday and things worked just fineon my setup, with the delay hardly noticeable in relation to the player cam video.

I might consider making this the default 🤔

I also corrected unnecessary complicated code to make changes with this simple logic: level can only change when lines change lines can only change when score change score can change on its own (drop down point)

Therefore, we only need to monitor changes in score and read the 3 values of score, lines, level together after the stabilization period has elapsed.

timotheeg commented 2 years ago

Made more changes as part of the unification work. There's now 2 frames of buffer at OCR time, and there's no longer a query string arg to change that.