Post subject: NesVideoAgent's automatic screenshot feature works like this
TASVideoAgent
They/Them
Moderator
Joined: 8/3/2004
Posts: 15629
Location: 127.0.0.1
This post attempts to explain how NesVideoAgent's automatic screenshot feature works. It should answer all questions, though it is a little technically oriented. <h3><a name="Architecture"></a>Architecture</h3><div class="deeper"> <h4><a name="OuterLayerAPhpProgram"></a>Outer layer: A php program</h4><div class="deeper"> It is run manually by a site admin, though it could be run automatically too. This commandline program searches the database for submissions that match these rules: <ul><li> Status is not published, rejected or canceled </li><li> Has no screenshots yet </li><li> Is for NES, SNES, GB, SGB, GBC, GBA or Genesis </li></ul><p/>For each matching submission, it does the following: <ul><li> Tries to determine which ROM should be used to watch the submission <ul><li> Scans the list of Good* ROM names and selects ~90 ones that most closely match the submitted ROM name or game's name </li><li> If it finds one whose checksum (CRC32, MD5 or other) matches what the submitted movie file has, uses it </li></ul></li><li> Runs the emulator with specific parameters <ul><li> A requirement is that the emulator can run on parameters without need for keyboard or mouse input </li><li> The emulator must also accept the fact that it can't produce sound (server has no soundcard) </li><li> The emulator is run under Xvfb so it can be graphical yet non-interactive </li></ul></li><li> Updates the submission message with <ul><li> links to images produced by the emulator </li><li> notes about the ROM selection </li></ul></li></ul></div><h4><a name="InnerLayerModifiedEmulator"></a>Inner layer: Modified emulator</h4><div class="deeper"> The emulator is slightly patched version of the normal emulator used to run the movies. <ul><li> It is completely uninteractive (movie file, sync options, play length specified on command line) </li><li> It includes a beauty analysis module. </li></ul></div></div><h3><a name="BeautyAnalysisModule"></a>The beauty analysis module</h3><div class="deeper"> The beauty analysis module is a component in the emulator that works like this: <p/><ul><li> At every frame when the movie plays, it observes the emulated screen (in a similar manner as AVI encoder does). </li><li> At every frame, it can also save or load a savestate, or terminate the emulator. </li></ul><h4><a name="DescriptionOfOperation"></a>Description of operation</h4><div class="deeper"> First, it plays the movie normally. <ul><li> Every frame, it analyses the image for beauty, and records it as a numeric value for that particular frame. </li><li> Every 100 frames, it makes a savestate. </li></ul>When the movie ends (actually, 2 frames before but that's a detail): <ul><li> It divides the movie into N evenly long sections <ul><li> Where N is selected so that N <= 50 but that a section length must be at least 1 second and not more than 10 seconds </li><li> And from that section, it determines the most beautiful shot, using the numeric values recorded earlier. </li><li> Then it picks the 20 most beatiful sections, and remembers the frame numbers where the single most beatiful screen occured during that section. </li></ul></li><li> For each selected beauty: <ul><li> It loads the latest savestate that was recorded before that particular frame </li><li> Runs the emulator until the framenumber matches the desired frame </li><li> And saves the screen as a PNG file. </li></ul></li><li> Then it terminates the emulator. </li></ul></div><h4><a name="AnalysisOfBeauty"></a>Analysis of beauty</h4><div class="deeper"> The algorithm used by the emulator for determining the beauty of a particular screenshot is written hoping to meet the following guidelines. A good screenshot contains: <ul><li> distinctly different colours at different sections of the screen (saturated colors preferred over grayish ones) </li><li> a lot of movement at each portion of the screen (less desirable to have it localized in a single corner) </li></ul><p/>The algorithm works by dividing the screen into 12 sections (4 horizontally, 3 vertically), and for each section, determining: <ul><li> The average tint on that section of the screen </li><li> The number of sprites that have changed position on that section of screen compared to the previous frame </li></ul><p/>The score is determined by the sum of sprite jitter in all sections, and matching each diagonal pair of sections and calculating how much the tint differs in them. <p/>The tint is calculated by sampling the pixels in that section (actually, about a third of them in a random gridlike pattern for speed but that's again an implementation detail), converting them to the YIQ colorspace and calculating average of the complex number comprised by the I and Q components, weighted using the Y value, and the final number weighted using a logarithmic transformation. </div></div>
JXQ
Experienced player (761)
Joined: 5/6/2005
Posts: 3132
Neato. :) How long does it take to run this entire process for a modest-sized (20 minutes or so) movie (that isn't GB, so colors > 4)?
<Swordless> Go hug a tree, you vegetarian (I bet you really are one)
Post subject: Re: NesVideoAgent's automatic screenshot feature works like
Player (36)
Joined: 9/11/2004
Posts: 2631
bbcode-ized [Edit by Bisqwit: Thanks, but it is now redundant :) ]
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Post subject: Re: NesVideoAgent's automatic screenshot feature works like
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Bisqwit wrote:
The algorithm used by the emulator for determining the beauty of a particular screenshot is written hoping to meet the following guidelines.
It doesn't sound to me like it calculated the "beautiful" the frame is but how "busy" it is. In other words, the more color variation and movement there is, or in other words, the busier the image is, the more points. :P
Joined: 4/3/2005
Posts: 575
Location: Spain
Could a TAS creator trick somehow the Automatic Screenshot feature to take a screenshot at his favourite scene in the movie?
No.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
JXQ wrote:
How long does it take to run this entire process for a modest-sized (20 minutes or so) movie (that isn't GB, so colors > 4)?
It depends entirely on how fast the emulator can execute (not on the number of colors). By average, they seem to run at around 200 fps.
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
DrJones wrote:
Could a TAS creator trick somehow the Automatic Screenshot feature to take a screenshot at his favourite scene in the movie?
Actually instead of a trick I think it would be a cool feature if the author could put some special code in his submission text which bot interprets as a frame number (or a series of frame numbers, up to a certain limit) and then includes that frame (or frames) with the others. (Or, even better, the submission form could have a field for suggesting snapshot frame numbers. Leave blank if there's no suggestion.)
Former player
Joined: 8/1/2004
Posts: 2687
Location: Seattle, WA
Useless Ideological Opinion: While I commend that you set out to make a script that is able to determine "beauty," I don't think that's really something that you can determine by such a simple determination of action and color differentiation. How does the color factor in to grayscale Gameboy submissions? How does the activity factor in to games like Deja Vu, where "action" is more of less an instance of text?
hi nitrodon streamline: cyn-chine
Joined: 10/24/2005
Posts: 1080
Location: San Jose
Obviously "beauty" is a user-defined traited. I believe the main function of this feature is to provide a good sample of what the game has to offer. I guess it would give a user who was unfamiliar with the game a chance to see if he or she would enjoy the game before watching the tas. That being said, I agree that beauty is a bad word to use, hence Bisqwit's use of quotes when using the word. A better word (I can't think of one) would imply some sort of "usefulness" or "functionality" factor, something that is not mutually exclusive to the word "beauty." However, if you guys want to discuss how to interpret beauty from a somewhat technical perspective, I'm game for that. I just want to make clear that I think "beauty" is not the main goal of this feature (Bisqwit, correct me if I'm wrong).
<agill> banana banana banana terracotta pie! <Shinryuu> ho-la terracotta barba-ra anal-o~
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
I think "action" would be much closer to the interpretation of the algorithm. Most movement + most color variation = most action.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
The purpose of the algorithm is to produce interesting & eye-pleasing screenshots of the movie without requiring user aid. If you have better ideas for how to implement that, sure, I'm listening :)
Reviewer, Active player (288)
Joined: 12/14/2006
Posts: 717
Can you tell the bot to try another ROM if he uses the wrong one?
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
arkiandruski wrote:
Can you tell the bot to try another ROM if he uses the wrong one?
Manually, sure. But what's the point of "automatic" if it's not actually automatic? Notice the thread title. Or are you implying that the bot could somehow see as it watches the movie, "oops, this must be the wrong ROM because the player character is doing actions that don't make any sense"? Not doable without a highly intelligent AI. For the explanation of the algorithm currently employed for maximizing the chances of finding the right ROM, see the first post of this thread.
Chamale
He/Him
Player (182)
Joined: 10/20/2006
Posts: 1355
Location: Canada
The problem with looking for "makes sense" is that a lot of runs make no sense. Hell, some submission texts even say, "If ______ happens, no, it's not a desynch".
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Chamale wrote:
The problem with looking for "makes sense" is that a lot of runs make no sense. Hell, some submission texts even say, "If ______ happens, no, it's not a desynch".
Indeed. But for a computer, the problem is far more profound. Even writing a program that identifies which object on the screen is the player character, is something I would refuse to do because it is too difficult (without extensively customized algorithms for each and every game), let alone understand what the character is doing and how it's faring.
Joined: 5/29/2006
Posts: 138
Bisqwit wrote:
Indeed. But for a computer, the problem is far more profound. Even writing a program that identifies which object on the screen is the player character, is something I would refuse to do because it is too difficult (without extensively customized algorithms for each and every game), let alone understand what the character is doing and how it's faring.
I don't think it would be too difficult to determine the player character in most games - it's the object that moves left when the player presses left, etc. Even with jumping and attacking options, it should be fairly easy to determine which object moved directly because of the player input. Of course there are games that would break this and even after finding which object on screen is the character there isn't a lot to do with the information. I wouldn't want to even try to figure out whether the character is doing well or not.
Joined: 5/2/2006
Posts: 1020
Location: Boulder, CO
In many games, the character doesnt move at all, rather the background moves the other way to make it give the illusion of movement. bisqwit was smart to not try to write something like that, because it would be damn near impossable.
Has never colored a dinosaur.
Player (64)
Joined: 11/2/2007
Posts: 100
Location: Toronto, Canada
Clicking on the "View latest post" link in any submission thread with lots of screenshots posted by NesVideoAgent doesn't work properly, because the vertical location of the latest post gets pushed down after you jump to it, by all the screenshots that get loaded. Adding width and height attributes in the <img> tag should fix this.
P.JBoy
Any
Editor
Joined: 3/25/2006
Posts: 850
Location: stuck in Pandora's box HELLPP!!!
If you're using firefox then you can click the "Go" button next to the address bar after the page has completly loaded
Player (64)
Joined: 11/2/2007
Posts: 100
Location: Toronto, Canada
True, but this requires additional effort on my part. Offtopic: I like your avatar.
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
plusminus wrote:
True, but this requires additional effort on my part.
I see that with all kinds of sites... so far the only solution seems to be to wait until the page is loaded, then doing what P.JBoy said (or F6 + Enter).
Skilled player (1652)
Joined: 11/15/2004
Posts: 2202
Location: Killjoy
How are screenshots able to contain multiple desyncs? I know for a fact that a set of screen shots were taken that show a desync BEFORE it would be possible to ever reach another part of the game, given the desync in my run. Does NVA run through the game multiple times?
Sage advice from a friend of Jim: So put your tinfoil hat back in the closet, open your eyes to the truth, and realize that the government is in fact causing austismal cancer with it's 9/11 fluoride vaccinations of your water supply.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
DarkKobold wrote:
How are screenshots able to contain multiple desyncs?
Because the movie syncs properly when NVA first scans through it (and makes dozens of savestates), but when he utilizes those savestates to return to the selected favourite spots, the movie no longer syncs. This seems to be a problem in Gens in particular.
Post subject: but the ROM locator works like this
Banned User
Joined: 12/23/2004
Posts: 1850
Bisqwit wrote:
arkiandruski wrote:
Can you tell the bot to try another ROM if he uses the wrong one?
For the explanation of the algorithm currently employed for maximizing the chances of finding the right ROM, see the first post of this thread.
For a "hands on" example, you can try this. Replace "mario" with whatever. No .NES needed. This is a prototype version of the algorythm used. (It was developed seperately from Bisqwit's, but is ultimately rather similar. This takes more time, but is usually more likely to place the correct result higher on the list, which is pointless when you just need it to be in the top 100-something) Maybe I could use this as a sort of "portable GoodNES checker". Run a tool to create names for all of the ROMs we have, MD5sum them, and then ask for "suspected ROM name" and then the ROM itself. ... Or not...
Perma-banned
P.JBoy
Any
Editor
Joined: 3/25/2006
Posts: 850
Location: stuck in Pandora's box HELLPP!!!
Maybe we would put these screenshots into a tab like this
%%TAB Minimize%%
%%TAB Screenshots%%
[screenshots]
%%TAB_END%%
That way there'd be less spoilers of the movie and the page would load more in the right place when you click the "view latest post" icon