header={ "recipe_version": "1.194", "title": "Convert to mp4", "description": "Convert (almost) any video to an mp4.", "tags": "default", "chef": "BeatRig", "dependencies": "ffprobe,ffmpeg", "instructions": "", "type": "default", "os": "windows,macOS", "palette": "Clean Slate", "spice": "BQ==:G+Hy36kJcnQQYYavb/JV2Il6eCYr6h4hRJHCF9rRbhX5BcazL6cuTgUMdz0xA50VWA5PmmV0Q7aWkiUtNFtbk991l+t0e8IBXMReMIT1GNjnZZDv7n2YRAo0xcSQbY0ixjG6LLH4wGKnspKAoA/v69iLn6N2IH0XzIZwTGdHSo4=", "flavour": "DEjVGAyXooE816AhKMK/ljocfCm2dhNSMA1Grjh7HMPd75E6u3rgAzn+qHqK+kcSLdVUXwO8Rblkw9AeIGH1wJqiyIu8DIZlaBcrhbwFSsMSgji23djoeUm1Z5CiuEHfwgO+i0ynOcBPknL1wtsH72liuk2wOiQKRa/Cn/iwbBE=", "time": 1723851480, "core_version": "0.6.4", "magnetron_version": "1.0.317", "functions": "main,onAbout", "uuid": "c1aee1f2b2a448de8c7fd0db3c0da864" }; // ============================================================================= // GLOBALS // ============================================================================= var framecount = 0; var max_duration = 0; // ============================================================================ // DEFAULTS var settings = { "filesize" : false, "bitrate_video" : "1500", "bitrate_audio" : 128, "customFolder" : false, "customFolder_path" : "", "subFolder" : true, "subFolder_val" : "export", "nametag" : false, "nametag_val" : "-RESIZED", }; // ============================================================================ function main() { // ----------------------------- // START THE MACHINE setProgress(0); // ----------------------------- // GET ALL FILES FROM THE APP var files = getFiles(); // a list containing all valid files for the reference combobox var fileList = []; // LOAD SETTINGS settings = loadSettings(settings); // CHECK IF FFMPEG & FFPROBE ARE AVAILABLE FOR TRUE PEAK LIMITING settings.ffmpeg = !checkDependencies("ffprobe,ffmpeg"); // CHECK IF FFMPEG HAS SOX RESAMPLER BUILT IN // WILL BE TESTET THE FIRST TIME NEEDED settings.sox = "NOTDEFINED"; // loop all files for (i=0;i max_duration ? duration : max_duration); } } // ======================================================================== // AUDIO / VIDEO BITRATE // ======================================================================== var bitrate_video = settings.bitrate_video; var bitrate_audio = settings.bitrate_audio; if(settings.filesize){ bitrate_video = Math.round((settings.filesize_val * 8192 - 128) / max_duration); // -128 to compensate for audio ;) bitrate_audio = 128; } // ======================================================================== // PROCESS // ======================================================================== // loop all files for (i=0;i 0 && framecount > 0){ var progress = parseInt ( searchRegEx(cmd_output, "(?:frame=)(.*?)(?:fps=)", "i", 1)[0] ); progress = Math.round( progress/framecount* 100 ); setProgress(progress); } } // ============================================================================= // ON ABOUT, SHOW POPUP WITH BUTTON TO OPEN WEBSITE function onAbout() { var args = { "info": { "type": "texteditor", "bounds" : { "y" : 70, "w" : 400, "h" : 150 }, "visible": true, "multiline" : true, "wordwrap" : true, "default" : header.description+'\n\nMore information on the recipes page on our website.', "enabled" : false }, "showpage" : { "type" : "button", "label" : "show page", "returns" : 1 }, "close" : { "type" : "button", "label" : "close", "returns" : 0 } }; var r = dialog(header.title, "" , "", args); if (r.showpage == 1) launchInBrowser('https://magnetron.app/recipes/uuid/'+header.uuid+'/'); } // ============================================================================= // STORE SETTINGS ON DRIVE function storeSettings(s){ // A FILE WITH DEFAULT VALUES var deffile = folders.content+gvar.pss+'default.txt'; // REMOVE BUTTONS ETC THAT SHOULD NOT BE STORED s = removeProperty(s, 'returns'); s = removeProperty(s, 'okay'); s = removeProperty(s, 'cancel'); s = removeProperty(s, 'exportRef_reffile'); // s = removeProperty(s, 'ffmpeg'); // WRITE THE FILE writeFile(deffile,objectToString(s)); } // ============================================================================= // LOAD DEFAULT VALUES function loadSettings(settings){ // A FILE WITH DEFAULT VALUES var deffile = folders.content+gvar.pss+'default.txt'; // ADD/UPDATE SETTINGS if ( fileExists(deffile) ){ // GET FILE var t = stringToObject( readFile(deffile) ); // REPLACE VALUES ONE-BY-ONE for (var j = 0; j < getObjectSize(t); j++) { settings[getObjectKey(t, j)] = getObjectValue(t, j); } } // RETURN THE VALUES return settings; } // ============================================================================= function formatBytes(bytes) { if (bytes === 0) return '0 Bytes'; var k = 1024; var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; var i = Math.floor(Math.log(bytes) / Math.log(k)); var rtn = parseFloat((bytes / Math.pow(k, i))); return toFixed(rtn,2)+ ' ' + sizes[i]; }