Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ###################################################################
- -- VIREEN
- -- by nucular
- local Version = "One"
- -- ###################################################################
- -- The new VIdeo REcorder and ENcoder for TPT!
- -- Licensed under Creative Commons Attribution 3.0 Unported (CC BY 3.0)
- -- Look at http://creativecommons.org/licenses/by/3.0/
- -- ####################################################################
- -- Look at it as a successor of my mod of gamax92's Moviemaker.
- -- Please post wishes, your own code and bug reports there:
- local Forum_Thread = "http://powdertoy.co.uk/Discussions/Thread/View.html?Thread=15965"
- --
- -- The newest version can be found there:
- local Download_Page = "http://pastebin.com/10kvD95u"
- --
- --
- -- THATS NEW IN VIREEN:
- -- - Completely rewritten and ported to the Interface API.
- -- - Many formats to support.
- -- - Appears now as a addition to the TPT-intern R keybind, so its as fast as C++ can! (And thats far more than LUA)
- -- - Flawless support of TPT++ and newer versions.
- -- - Programmed for the newest version of FFMPEG.
- -- CHANGES:
- -- - FROM A BIT OF DUST TO ONE:
- -- - Everything.
- -- KNOWN BUGS:
- -- - Doesn't record interface or HUD now due to TPTs recording function (unable to fix for now)
- -- - TPT freezes when converting / deleting many frames (already at TODO)
- -- TODO:
- -- - Allow user to place the script in subdirectory of TPT
- -- - More converting options
- -- - Add debugging function if needed
- -- - Use asynchrous os.execute to avoid freezing TPT (i think thats impossible without extern libraries)
- --set up default settings and vars
- local setting_compatibility = 1 --set to 1 if youre using a older version of ffmpeg
- local setting_fps = 25
- local setting_format = ".avi"
- local setting_comp = 3
- local var_framesrecorded = 0
- local tpt_records = false
- local window = Window:new(-1, -1, 200, 100)
- local help = Window:new(-1, -1, 200, 222)
- --check platform (win or linux) from moviemaker
- if package.config:sub(1,1) == "\\" then
- var_backslash = "\\"
- else
- var_backslash = "/"
- end
- --nice little func to open a website
- local function openwebsite(url)
- if var_backslash == "\\" then
- os.execute("explorer " .. url) --Windows
- else
- os.execute("x-www-browser " .. url) --Linux
- end
- end
- -- check if Videos folder exists, create it if not, show mesagebox if creating failed
- if not fs.exists("Videos") then
- if not fs.makeDirectory("Videos") then
- tpt.message_box("ViReEn - Creating folder failed","Please create folder 'Videos' in\nTPTs directory manually.")
- end
- end
- -- check if FFMPEG exists
- if not fs.exists("ffmpeg.exe") then
- tpt.message_box("ViReEn - FFMPEG not found","Please download FFMPEG from this\nwebsite and copy it in TPTs folder.")
- if var_backslash == "\\" then
- openwebsite("http://www.ffmpeg.org/download.html#WindowsBuilds") --open windows builds website
- else
- openwebsite("http://www.ffmpeg.org/download.html#LinuxBuilds") --open linux builds website
- end
- end
- --returns false if user pressed cancel on recording-message
- --returns true if user pressed continue
- local function pressed(mousex,mousey)
- if mousex >= 189 and mousey >= 231 and mousex <= 362 and mousey <= 246 then
- return false
- elseif mousex >= 364 and mousey >= 231 and mousex <= 438 and mousey <= 246 then
- return true
- end
- end
- --show introduction
- local function introduction()
- tpt.log("Welcome to ViReEn.")
- tpt.log("To start recording, press [R].")
- end
- --helper function from mniip's xstptirc
- local function textwidth(s)
- return select(2,pcall(tpt.textwidth,s))
- end
- --ADD A FEW GUI COMPONENTS
- local var_codecstring = ", .gif, .mp4, .mpg"
- local label_codec_info = Label:new(102,14,textwidth(var_codecstring),14,var_codecstring)
- window:addComponent(label_codec_info)
- --Codec Button
- local button_codec = Button:new(70,14,30,14,setting_format,"Change output codec")
- window:addComponent(button_codec)
- --END
- --save settings
- local function save_last()
- local savestring = "FPS "..tostring(setting_fps).."\nCOD "..setting_format.."\nCOM "..tostring(setting_comp).."\nINF "..label_codec_info:text()
- local f = io.open("vireen.pref","w")
- if f then
- f:write(savestring)
- f:close()
- end
- end
- -- load settings based on code from cracker64's awesome Autorun Script Manager
- local function load_last()
- local f = io.open("vireen.pref","r")
- if f then
- local lines = {}
- local line = f:read("*l")
- while line do
- table.insert(lines,line)
- line = f:read("*l")
- end
- f:close()
- for i=1, #lines do
- local tok=lines[i]:sub(1,3)
- local str=lines[i]:sub(5)
- if tok=="FPS" then
- setting_fps = tonumber(str)
- elseif tok=="COD" then
- setting_format = str
- button_codec:text(str)
- elseif tok=="COM" then
- setting_comp = tonumber(str)
- elseif tok=="INF" then
- label_codec_info:text(str)
- end
- end
- else
- introduction()
- save_last()
- end
- end
- load_last()
- --hack for getting selected button.
- --by mniip
- local checkloop
- checkloop=function()
- local x,y = tpt.mousex,tpt.mousey
- tpt_records = pressed(x,y)
- tpt.unregister_step(checkloop)
- end
- --check if user presses the R key
- local function checkR(key, numkey, modifier, event)
- --tpt.log("key pressed")
- if key == "r" and event == 1 then
- if tpt_records == false then
- tpt.register_step(checkloop)
- else
- tpt_records = false
- interface.showWindow(window)
- end
- end
- end
- --convert video
- local function convert()
- if setting_compatibility == 1 then
- os.execute("ffmpeg -r " .. tostring(setting_fps) .. " -qscale " .. setting_comp .. " -i frame_%06d.ppm Videos" .. var_backslash .. "tptvideo" .. tostring(os.time()).. setting_format)
- else
- os.execute("ffmpeg -r " .. tostring(setting_fps) .. " -q:s " .. setting_comp .. " -i frame_%06d.ppm Videos" .. var_backslash .. "tptvideo" .. tostring(os.time()).. setting_format)
- end
- end
- --UI DESIGN BEGINS HERE
- --Help screen
- local helptext = "ViReEn " .. Version .. "\n" ..
- "by\n\n" ..
- "Press R to start recording.\n" ..
- "In your TPT folder will appear a bunch\n" ..
- "of .ppm files. These are the recorded\n" ..
- "frames. After you pressed R again, the\n" ..
- "ViReEn Interface will pop up. Set the\n" ..
- "settings and press 'Save Video'.\n" ..
- "You can delete the raw frames by\n" ..
- "pressing 'Delete *.ppm'."
- local label_help = Label:new(5,5,185,130,helptext)
- help:addComponent(label_help)
- local button_forum = Button:new(5,150,select(1,window:size())-10,14,"Open Forum Thread","Open ViReEn's forum thread in browser")
- button_forum:action(
- function(sender)
- openwebsite(Forum_Thread)
- end
- )
- help:addComponent(button_forum)
- local button_update = Button:new(5,166,select(1,window:size())-10,14,"Open Download Page","Open ViReEn's downloading page in browser")
- button_update:action(
- function(sender)
- openwebsite(Download_Page)
- end
- )
- help:addComponent(button_update)
- local button_profile = Button:new(20,16,40,14,"nucular","Open nucular's user profile")
- button_profile:action(
- function(sender)
- openwebsite("http://www.tpt.io/@nucular")
- end
- )
- help:addComponent(button_profile)
- local label_discl = Label:new(3,140,185,130,"Licensed under Creative Commons\nAttribution 3.0 Unported (CC BY 3.0)")
- help:addComponent(label_discl)
- local button_exithlp = Button:new(select(1,window:size())-16,2,14,14,"X","Close Help")
- button_exithlp:action(
- function(sender)
- save_last()
- interface.closeWindow(help)
- --tpt.log("closed interface")
- end
- )
- help:addComponent(button_exithlp)
- --Exit Button
- local button_exit = Button:new(select(1,window:size())-16,2,14,14,"X","Close ViReEn")
- button_exit:action(
- function(sender)
- save_last()
- interface.closeWindow(window)
- --tpt.log("closed interface")
- end
- )
- window:addComponent(button_exit)
- --Help Button
- local button_help = Button:new(select(1,window:size())-31,2,14,14,"?","Show help")
- button_help:action(
- function(sender)
- interface.showWindow(help)
- end
- )
- window:addComponent(button_help)
- --Various Labels
- local label_codec = Label:new(5,14,textwidth("Codec:"),14,"Codec:")
- window:addComponent(label_codec)
- local label_fps = Label:new(5,30,textwidth("Frame Rate:"),14,"Frame Rate:")
- window:addComponent(label_fps)
- local label_comp = Label:new(5,46,textwidth("Compression:"),14,"Compression:")
- window:addComponent(label_comp)
- local label_info = Label:new(5,select(2,window:size())-16,textwidth("ViReEn " .. tostring(Version) .. " by nucular"),14,"ViReEn " .. tostring(Version) .. " by nucular")
- window:addComponent(label_info)
- local label_fps_info = Label:new(70,30,textwidth(tostring(setting_fps)),14,tostring(setting_fps))
- window:addComponent(label_fps_info)
- local label_comp_info = Label:new(70,46,textwidth(tostring(setting_comp)),14,tostring(setting_comp))
- window:addComponent(label_comp_info)
- --FPS Slider
- local slider_fps = Slider:new(90,30,select(1,window:size())-104,14,50)
- slider_fps:value(setting_fps)
- slider_fps:onValueChanged(
- function(sender, value)
- setting_fps = slider_fps:value()+10
- label_fps_info:text(tostring(setting_fps))
- label_fps_info:size(textwidth(tostring(setting_fps)),14)
- end
- )
- window:addComponent(slider_fps)
- --Compression Slider
- local slider_comp = Slider:new(90,46,select(1,window:size())-104,14,30)
- slider_comp:value(setting_comp)
- slider_comp:onValueChanged(
- function(sender, value)
- setting_comp = slider_comp:value()+1
- label_comp_info:text(tostring(setting_comp))
- label_comp_info:size(textwidth(tostring(setting_comp)),14)
- end
- )
- window:addComponent(slider_comp)
- --Convert Button
- local button_convert = Button:new(select(1,window:size())-82,select(2,window:size())-16,80,14,"Save Video","Convert raw frames and save video")
- button_convert:action(convert)
- window:addComponent(button_convert)
- --Delete Button
- local button_delete = Button:new(select(1,window:size())-82,select(2,window:size())-31,80,14,"Clear *.ppm","Delete raw frames")
- button_delete:action(
- function(sender)
- if var_backslash == "\\" then
- os.execute("del frame_*.ppm")
- else
- os.execute("rm frame_*.ppm")
- end
- end
- )
- window:addComponent(button_delete)
- --Do button_codec and label_codec_info text change
- local function button_codec_change()
- if setting_format == ".avi" then
- setting_format = ".gif"
- label_codec_info:text(", .mp4, .mpg, .avi")
- elseif setting_format == ".gif" then
- setting_format = ".mp4"
- label_codec_info:text(", .mpg, .avi, .gif")
- elseif setting_format == ".mp4" then
- setting_format = ".mpg"
- label_codec_info:text(", .avi, .gif, .mp4")
- elseif setting_format == ".mpg" then
- setting_format = ".avi"
- label_codec_info:text(", .gif, .mp4, .mpg")
- end
- button_codec:text(setting_format)
- label_codec_info:size(textwidth(label_codec_info:text()),14)
- end
- button_codec:action(
- function(sender)
- button_codec_change()
- end
- )
- tpt.register_keypress(checkR)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement