Skip to content

Instantly share code, notes, and snippets.

@jflemer
Last active August 7, 2020 04:41
Show Gist options
  • Save jflemer/60ae8d3d2e6c5e221c57c17f9cd20b07 to your computer and use it in GitHub Desktop.
Save jflemer/60ae8d3d2e6c5e221c57c17f9cd20b07 to your computer and use it in GitHub Desktop.
FCEUX LUA script to automate capture of unique NES ROMs screenshots
#!/bin/sh
rm ~/.fceux/fceux.cfg
for i in *.nes; do
fceux --loadlua screenshot.lua "$i"
mv screen.01.png "$i".png
rm screen.??.png 2>/dev/null
done
--
-- Lua script for FCEUX for capturing a screenshot
--
-- Generates screenshots for a ROM. Output is "screen.01.png" for each. Change
-- the call to ss() at the bottom to change number of unique screenshots to
-- capture etc.
--
-- Usage:
--
-- apt install -y fceux
-- fceux --loadlua screenshot.lua any_rom.nes
--
function md5 (file)
local fh = io.popen(string.format("md5sum '%s'", string.gsub(file, "'", [['\'']])))
local res = fh:read("*a")
fh:close()
return string.gsub(res, '%s.+', '');
end
function contains (arr, val)
local v = '';
local i = 0;
for i,v in ipairs(arr) do
if ( val == v ) then
return true
end
end
return false
end
function ss (num_to_save, interval, max_frames)
local ss_num = 1;
local last_ss_frame = 0;
local md5s = { '306d572ee2b10e99d608f67fad5cf1fd' }; -- start with all black
while ( ss_num <= num_to_save and emu.framecount() <= max_frames ) do
local i = emu.framecount();
emu.frameadvance();
if ( i >= last_ss_frame + interval ) then
local ss_name = string.format("%s.%02d.png", "screen", ss_num);
emu.print(string.format("Saving screenshot: %s (at frame %d)", ss_name, i));
gui.savescreenshotas(ss_name);
last_ss_frame = i;
emu.frameadvance();
emu.pause();
local cur_md5 = md5(ss_name);
if contains(md5s, cur_md5) then
os.execute(string.format("rm '%s'", string.gsub(ss_name, "'", [['\'']])));
else
table.insert(md5s, cur_md5);
ss_num = ss_num + 1;
end
emu.unpause();
end
end
end
emu.print("Init...")
-- about 60 fps
-- ss(num_unquie_screens, frames_between_shots, max_frames)
ss(5, 21, 15*60)
os.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment