Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- If the Developers add or remove a button on the right toolbar, please change
- -- numOfButtons to reflect how many buttons are natural TPT buttons.
- -- You can also change buttonIcon to change the button label.
- local numOfButtons = 6
- local buttonIcon = "V"
- -- Code below.
- -- Check if code already loaded.
- if mods_tnmm == true then
- tpt.message_box("MovieMaker", "MovieMaker is already loaded.")
- return false
- end
- mods_tnmm = true
- -- LuaSrcDiet purposes
- local tpt,math,Button,tostring = tpt,math,Button,tostring
- -- Check if the Videos folder exists, create it if it doesn't, show a mesagebox if creating it failed
- if not fs.exists("Videos") then
- if not fs.makeDirectory("Videos") then
- tpt.message_box("MovieMaker - Creating folder failed","Please create folder 'Videos' in\nTPTs directory manually.")
- end
- end
- --[[
- -- Need to fix this code so it checks for windows.
- -- Check if ffmpeg.exe exists.
- if not fs.exists("ffmpeg.exe") then
- tpt.message_box("MovieMaker - FFMPEG not found","Please copy an version of FFMPEG in\nTPTs directory and name it 'ffmpeg.exe'.")
- end
- --]]
- local recording = 0
- local recordfps = 30
- local recordqual = 3
- local recordframes = 0
- local recordft = ".avi"
- local recorduiseen = 0
- local recorduitype = 0
- local recordhud = 0
- local recordcf = 0
- local recordds
- if package.config:sub(1,1) == "\\" then
- recordds = "\\"
- else
- recordds = "/"
- end
- local uix = math.floor((612 / 2) - (149 / 2))
- local uiy = math.floor((384 / 2) - (59 / 2))
- local function load_last()
- local f = io.open("MovieMakerSettings.txt", "rb")
- if f ~= nil then
- while true do
- line = f:read("*l")
- if line == nil then
- break
- elseif line ~= "" then
- local key, val = line:match("(.-) (.*)")
- if key == "FPS" then
- recordfps = tonumber(val)
- elseif key == "COD" then
- recordft = val
- elseif key == "FUL" then
- recordhud = tonumber(val)
- elseif key == "QUA" then
- recordqual = tonumber(val)
- elseif key == "FOC" then
- recordcf = tonumber(val)
- end
- end
- end
- f:close()
- end
- end
- -- Save settings to a file
- local function save_last()
- local savetable = {
- FPS = recordfps,
- COD = recordft,
- FUL = recordhud,
- QUA = recordqual,
- FOC = recordcf,
- }
- local savestring = ""
- for k,v in pairs(savetable) do
- savestring = savestring .. k .. " " .. tostring(v) .. "\n"
- end
- savestring = savestring:sub(1,-2)
- local f = io.open("MovieMakerSettings.txt", "wb")
- if f ~= nil then
- f:write(savestring)
- f:close()
- end
- end
- -- Show S button, recorded seconds, and recorded frames when recording.
- local function recordsui()
- recordframes = recordframes + 1
- tpt.drawtext(5,385,tostring(math.floor(recordframes / 60)) .. " s")
- tpt.drawtext(5,395,tostring(math.floor(recordframes)) .. " F")
- end
- -- Screenshot wrapper for HUD mode.
- local function screensh()
- tpt.screenshot(recordhud, recordcf == 1 and 0 or 2)
- end
- load_last()
- -- Create Buttons and stuff.
- local toolButton = Button:new(613, (numOfButtons * 16) + 1, 15, 15, buttonIcon)
- local toolButton2 = Button:new(613 - uix, ((numOfButtons * 16) + 1) - uiy, 15, 15, buttonIcon)
- local testWindowMenu = Button:new(109, 2, 38, 13, "Options")
- local testWindow = Window:new(uix, uiy, 149, 59)
- local testWindowAVI = Checkbox:new(0, 0, 13, 13, "AVI Out")
- testWindowAVI:checked(recordft == ".avi")
- local testWindowGIF = Checkbox:new(53, 0, 13, 13, "GIF Out")
- testWindowGIF:checked(recordft ~= ".avi")
- local testWindowClean = Button:new(2, 30, 72, 13, "Clean folder")
- local testWindowRec = Button:new(75, 30, 72, 13, "Record")
- local testWindowCONV = Button:new(2, 44, 145, 13, "Convert")
- local testWindowFOC = Checkbox:new(0, 0, 13, 13, "Frame Compress")
- testWindowFOC:checked(recordcf == 1)
- local testWindowHUD = Checkbox:new(0, 13, 13, 13, "Record HUD")
- testWindowHUD:checked(recordhud == 1)
- local testWindowFPSL = Label:new(2, 30, tpt.textwidth("Video framerate:"), 13, "Video framerate:")
- local testWindowFPSM = Button:new(99, 30, 13, 13, "-")
- local testWindowFPST = Textbox:new(113, 30, 20, 13, tostring(recordfps), "FPS")
- testWindowFPST:readonly(true)
- local testWindowFPSP = Button:new(134, 30, 13, 13, "+")
- local testWindowCOMPL = Label:new(2, 44, tpt.textwidth("Compression:"), 13, "Compression:")
- local testWindowCOMPM = Button:new(99, 44, 13, 13, "-")
- local testWindowCOMPT = Textbox:new(113, 44, 20, 13, tostring(recordqual), "FPS")
- testWindowCOMPT:readonly(true)
- local testWindowCOMPP = Button:new(134, 44, 13, 13, "+")
- -- Add controls to windows.
- interface.addComponent(toolButton)
- testWindow:addComponent(toolButton2)
- testWindow:addComponent(testWindowMenu)
- -- Main Controls
- testWindow:addComponent(testWindowAVI)
- testWindow:addComponent(testWindowGIF)
- testWindow:addComponent(testWindowClean)
- testWindow:addComponent(testWindowRec)
- testWindow:addComponent(testWindowCONV)
- -- Options Controls
- testWindow:addComponent(testWindowFOC)
- testWindow:addComponent(testWindowHUD)
- testWindow:addComponent(testWindowFPSL)
- testWindow:addComponent(testWindowFPSM)
- testWindow:addComponent(testWindowFPST)
- testWindow:addComponent(testWindowFPSP)
- testWindow:addComponent(testWindowCOMPL)
- testWindow:addComponent(testWindowCOMPM)
- testWindow:addComponent(testWindowCOMPT)
- testWindow:addComponent(testWindowCOMPP)
- -- Add control handlers.
- local function showMain()
- testWindowAVI:visible(true)
- testWindowGIF:visible(true)
- testWindowClean:visible(true)
- testWindowRec:visible(true)
- testWindowCONV:visible(true)
- testWindowFOC:visible(false)
- testWindowHUD:visible(false)
- testWindowFPSL:visible(false)
- testWindowFPSM:visible(false)
- testWindowFPST:visible(false)
- testWindowFPSP:visible(false)
- testWindowCOMPL:visible(false)
- testWindowCOMPM:visible(false)
- testWindowCOMPT:visible(false)
- testWindowCOMPP:visible(false)
- end
- local function showOptions()
- testWindowAVI:visible(false)
- testWindowGIF:visible(false)
- testWindowClean:visible(false)
- testWindowRec:visible(false)
- testWindowCONV:visible(false)
- testWindowFOC:visible(true)
- testWindowHUD:visible(true)
- testWindowFPSL:visible(true)
- testWindowFPSM:visible(true)
- testWindowFPST:visible(true)
- testWindowFPSP:visible(true)
- testWindowCOMPL:visible(true)
- testWindowCOMPM:visible(true)
- testWindowCOMPT:visible(true)
- testWindowCOMPP:visible(true)
- end
- local function showWindow()
- interface.showWindow(testWindow)
- if recorduitype == 0 then
- showMain()
- else
- showOptions()
- end
- end
- local function toolButtonHDR(self)
- if recording == 0 then
- recorduiseen = 1 - recorduiseen
- if recorduiseen == 1 then
- showWindow()
- else
- interface.closeWindow(testWindow)
- end
- tpt.set_pause(recorduiseen)
- save_last()
- else
- tpt.unregister_step(recordsui)
- tpt.unregister_step(screensh)
- showWindow()
- tpt.set_pause(1)
- recording = 0
- recorduiseen = 1
- tpt.hud(1)
- tpt.message_box("MovieMaker - Recording finished", "Recorded " .. tostring(math.floor(recordframes / 60)) .. " seconds.\nDon't forget to Convert frames to a video!")
- end
- end
- local function testWindowSwitch(self)
- recorduitype = 1 - recorduitype
- if recorduitype == 0 then
- showMain()
- else
- showOptions()
- end
- save_last()
- end
- local function testWindowAVIHdr(self)
- testWindowAVI:checked(true)
- testWindowGIF:checked(false)
- recordft = ".avi"
- end
- local function testWindowGIFHdr(self)
- testWindowAVI:checked(false)
- testWindowGIF:checked(true)
- recordft = ".gif"
- end
- local function cleanFolder(self)
- local list = fs.list(".")
- local delcount = 0
- for k,v in pairs(list) do
- if v:sub(1,11) == "screenshot_" then
- fs.removeFile(v)
- delcount = delcount + 1
- end
- end
- tpt.message_box("MovieMaker - Cleanup finished", "Deleted " .. tostring(math.floor(delcount / 60)) .. " seconds of video.")
- recordframes = 0
- end
- local function record(self)
- -- Start recording.
- save_last()
- tpt.hud(recordhud)
- interface.closeWindow(testWindow)
- tpt.register_step(recordsui)
- tpt.register_step(screensh)
- tpt.set_pause(0)
- recording = 1
- end
- local function convertVid(self)
- -- Slide frame indexes down.
- local list = fs.list(".")
- table.sort(list)
- local index = 0
- for k, v in ipairs(list) do
- if v:sub(1,11) == "screenshot_" then
- fs.move(v, "screenshot_" .. string.format("%06d", index) .. "." .. (recordcf == 1 and "png" or "ppm"))
- index = index + 1
- end
- end
- -- Convert frames to video
- local videocount = 1
- while fs.exists("Videos" .. recordds .. "tptvideo" .. string.format("%04d",videocount) .. recordft) == true do
- videocount = videocount + 1
- end
- os.execute("ffmpeg -r 60 -i screenshot_%06d." .. (recordcf == 1 and "png" or "ppm") .. " -q:v " .. recordqual .. " -r " .. recordfps .. " Videos" .. recordds .. "tptvideo" .. string.format("%04d",videocount) .. recordft)
- tpt.message_box("MovieMaker - Converting finished", "Converted " .. math.floor( index / 60 ) .. " seconds of video.\nDon't forget to clean your folder!")
- end
- local function testWindowSPD(self)
- recordcf = self:checked() == true and 1 or 0
- end
- local function testWindowFUL(self)
- recordhud = self:checked() == true and 1 or 0
- end
- local function testWindowFPSS(self)
- if recordfps > 1 then recordfps = recordfps - 1 end
- testWindowFPST:text(tostring(recordfps))
- end
- local function testWindowFPSA(self)
- if recordfps < 60 then recordfps = recordfps + 1 end
- testWindowFPST:text(tostring(recordfps))
- end
- local function testWindowCOMPS(self)
- if recordqual > 1 then recordqual = recordqual - 1 end
- testWindowCOMPT:text(tostring(recordqual))
- end
- local function testWindowCOMPA(self)
- if recordqual < 31 then recordqual = recordqual + 1 end
- testWindowCOMPT:text(tostring(recordqual))
- end
- toolButton:action(toolButtonHDR)
- toolButton2:action(toolButtonHDR)
- testWindowMenu:action(testWindowSwitch)
- testWindowAVI:action(testWindowAVIHdr)
- testWindowGIF:action(testWindowGIFHdr)
- testWindowClean:action(cleanFolder)
- testWindowRec:action(record)
- testWindowCONV:action(convertVid)
- testWindowFOC:action(testWindowSPD)
- testWindowHUD:action(testWindowFUL)
- testWindowFPSM:action(testWindowFPSS)
- testWindowFPSP:action(testWindowFPSA)
- testWindowCOMPM:action(testWindowCOMPS)
- testWindowCOMPP:action(testWindowCOMPA)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement