Advertisement
AnarchyOnline

FFmpeg.xys 0.4

Jun 24th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.24 KB | None | 0 0
  1. "_Initialize"
  2.  {
  3.  // Configuration .ini file
  4.  global $g_ConfigurationFile;
  5.  $g_ConfigurationFile = "<xyscripts>\FFmpeg.ini";
  6.  
  7.  // Execution and buffer files
  8.  global $g_ExecutionFile;
  9.  $g_ExecutionFile = "<xyscripts>\FFmpeg.bat";
  10.  delete (0, 0, $g_ExecutionFile);
  11.  
  12.  global $g_DumpFileFFprobe;
  13.  $g_DumpFileFFprobe = "<xyscripts>\FFprobe.ini";
  14.  delete (0, 0, $g_DumpFileFFprobe);
  15.  
  16.  global $g_ExecutionFileFFprobe;
  17.  $g_ExecutionFileFFprobe = "<xyscripts>\FFprobe.bat";
  18.  delete (0, 0, $g_ExecutionFileFFprobe);
  19.  
  20.  // Configuration keys
  21.  global $g_ScriptVersion;
  22.  $g_ScriptVersion = '0.4';
  23.  
  24.  global $g_FFmpeg;
  25.  global $g_FFprobe;
  26.  global $g_Store;
  27.  
  28.  if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
  29.  
  30.   // Load keys
  31.   $g_FFmpeg = getkey ('FFmpeg', 'Configuration', "$g_ConfigurationFile", );
  32.   $g_FFprobe = getkey ('FFprobe', 'Configuration', "$g_ConfigurationFile", );  
  33.   $g_Store = getkey ('Store', 'Configuration', "$g_ConfigurationFile", );  
  34.  
  35.  } else {
  36.   msg <<<#
  37. Script is not configured.
  38. The configuration wizard will assist you.
  39. #;
  40.  
  41.  sub "_Configure";
  42.  }
  43.  }
  44.  
  45. "_Configure"
  46.  {
  47.  global $g_ConfigurationFile;
  48.  
  49.  msg <<<#
  50. This wizard configures the script for first use. To edit the configuration file click "Edit Configuration" after launching the script. If the configuration file is not found or you upgrade to a new version of this script the wizard will appear automatically.
  51.  
  52. The configuration file is located at:
  53.  
  54. $g_ConfigurationFile
  55.  
  56. Steps:
  57. 1. Select ffmpeg.exe
  58. 2. Select ffprobe.exe
  59. 3. Select location to save files
  60.  
  61. Done!
  62. #;
  63.  
  64.  // Delete old configuration file
  65.  delete (0, 0, "$g_ConfigurationFile");
  66.  
  67.  // Define parameters
  68.  global $g_ScriptVersion;
  69.  global $g_FFmpeg;
  70.  global $g_FFprobe;
  71.  
  72.  $g_FFmpeg = inputfile ('C:\', 'exe', 'Select ffmpeg.exe');
  73. $g_FFprobe = inputfile ('C:\', 'exe', 'Select ffprobe.exe');
  74. $g_Store = inputfolder ('C:', 'Select location to save files');
  75.  
  76. // Write configuration to disk
  77. $Configuration = <<<#
  78. [Configuration]
  79. ScriptVersion=$g_ScriptVersion
  80. FFmpeg=$g_FFmpeg
  81. FFprobe=$g_FFprobe
  82. Store=$g_Store
  83. #;
  84.  
  85. writefile ("$g_ConfigurationFile", "$Configuration", o, t);
  86.  
  87. msg <<<#
  88. Configuration completed.
  89. #;
  90. }
  91.  
  92. "Render - Specify bit rate"
  93. {
  94. global $g_FFmpeg;
  95. global $g_FFprobe;  
  96. global $g_ExecutionFile;
  97.  
  98. $Files = get ('selecteditemspathnames', |, a);
  99. $Files = formatlist ($Files, q, |, );
  100.  
  101. $Type = input('Enter desired file type', , , s, , , );
  102. $Parameters = input('Enter FFMpeg command options', , , s, , , );
  103.  
  104. delete (0, 0, $g_ExecutionFile);
  105.  
  106. foreach ($File, $Files, |){
  107.  $Command = '"'.$g_FFmpeg.'" -i '.$File.' '.$Parameters.' '.regexreplace ($File, '[.][^."]+', ".$Type", 0);
  108.  writefile ($g_ExecutionFile, "$Command<crlf>", a, t);
  109. }
  110. writefile ($g_ExecutionFile, 'del "'.$g_ExecutionFile.'"', a, t);
  111.  
  112. run ($g_ExecutionFile, , 0, 1);  
  113. }
  114.  
  115. "Render - Copy bit rate"
  116. {
  117. global $g_FFmpeg;
  118. global $g_FFprobe;
  119.  
  120. global $g_ExecutionFile;
  121. global $g_ExecutionFileFFprobe;
  122. global $g_DumpFileFFprobe;
  123.  
  124. global $g_Store;
  125.  
  126. $Files = get ('selecteditemspathnames', |, a);
  127. $Files = formatlist ($Files, q, |, );
  128.  
  129. $Type = input('Enter desired file type', , , s, , , );
  130. $Parameters = input('Enter FFMpeg command options', , , s, , , );
  131.  
  132. delete (0, 0, $g_ExecutionFile);
  133. delete (0, 0, $g_ExecutionFileFFprobe);
  134. delete (0, 0, $g_DumpFileFFprobe);
  135.  
  136. foreach ($File, $Files, |){
  137. //write show format command to file ffmpeg.dump.bat
  138.  writefile ($g_ExecutionFileFFprobe, '"'.$g_FFprobe.'" -show_format '.$File.' > "'.$g_DumpFileFFprobe.'"', o, t);
  139.  //execute ffmpeg.dump.bat and wait for completion
  140.  run ($g_ExecutionFileFFprobe, , 2, 1);
  141.  //retrieve bitrate from file ffmpeg.dump.ini
  142.  $Bitrate = getkey ('bit_rate', 'FORMAT', "$g_DumpFileFFprobe", );
  143.  //create ffmpeg command
  144.  $Command = '"'.$g_FFmpeg.'" -i '.$File.' -ab '.$Bitrate.' '.$Parameters.' '.regexreplace ($File, '[.][^."]+', ".$Type", 0);
  145.  writefile ($g_ExecutionFile, "$Command<crlf>", a, t);
  146. }
  147. writefile ($g_ExecutionFile, 'del "'.$g_ExecutionFile.'"', a, t);
  148.  
  149. delete (0, 0, $g_DumpFileFFprobe);
  150. delete (0, 0, $g_ExecutionFileFFprobe);
  151.  
  152. run ($g_ExecutionFile, , 0, 1);  
  153. }
  154.  
  155. "Books - Rename"
  156. {
  157. $Selection = get ('SelectedItemsPathNames', |, );
  158.  
  159. foreach ($Book, $Selection, |){
  160.  
  161.  $Index = '1';  
  162.  $Base = getpathcomponent ($Book, 'base', );
  163.  
  164.  $Author = gettoken ($Base, 1, '-', t, );
  165.  $Title = gettoken ($Base, 2, '-', t, );
  166.  
  167.  $Files = folderreport ('files', 'return', "$Book", , ,|);
  168.  
  169.   foreach ($File, $Files, |){
  170.    $Track = format($Index, '000');
  171.    
  172.     if ($File == ''){
  173.      break; //empty folders are skipped
  174.     } else {
  175.      renameitem ("$Track $Title", "$File", 1, );
  176.     }
  177.     $Index++;
  178.   }
  179. }
  180. }
  181.  
  182. "Books - Convert"
  183. {
  184. global $g_FFmpeg;
  185. global $g_FFprobe;
  186.  
  187. global $g_ExecutionFile;
  188. global $g_ExecutionFileFFprobe;
  189. global $g_DumpFileFFprobe;
  190.  
  191. global $g_Store;
  192.  
  193. $Selection = get ('SelectedItemsPathNames', |, );
  194.  
  195. foreach ($Book, $Selection, |){
  196.  
  197.  $Index = '1';  
  198.  $Base = getpathcomponent ($Book, 'base', );
  199.  
  200.  $Author = gettoken ($Base, 1, '-', t, );
  201.  $Title = gettoken ($Base, 2, '-', t, );
  202.  
  203.  $Files = folderreport ('files', 'return', "$Book", , ,|);
  204.  $Files = formatlist ($Files, q, |, );
  205.  
  206.  new ("$g_Store".'\'."$Base", 'dir', , );
  207.  
  208.   foreach ($File, $Files, |){
  209.  
  210.    writefile ($g_ExecutionFileFFprobe, '"'.$g_FFprobe.'" -show_format '.$File.' > "'.$g_DumpFileFFprobe.'"', o, t);
  211.    run ($g_ExecutionFileFFprobe, , 2, 1);
  212.    $Bitrate = getkey ('bit_rate', 'FORMAT', "$g_DumpFileFFprobe", );  
  213.    $Command = '"'.$g_FFmpeg.'" -i '.$File.' -vn -ab '.$Bitrate.' -metadata Genre="Audiobook" -metadata Artist="'.$Author.'" -metadata Title="'.getpathcomponent ($File, 'base', ).'" -metadata Album="'.$Title.'" -metadata Track="'.$Index.'" "'.$g_Store.'\'.$Base.'\'.getpathcomponent ($File, 'base', ).'.m4a"';
  214.  
  215.    writefile ($g_ExecutionFile, "$Command<crlf>", a, t);
  216.  
  217.    $Index++;
  218.   }
  219. }
  220. writefile ($g_ExecutionFile, 'del "'.$g_ExecutionFile.'"', a, t);
  221.  
  222. delete (0, 0, $g_DumpFileFFprobe);
  223. delete (0, 0, $g_ExecutionFileFFprobe);
  224.  
  225. run ($g_ExecutionFile, , 0, 1);
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement