ffmpeg_converter.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. include '../auth.php';
  3. ?>
  4. <html>
  5. <head>
  6. <title>ArOZ Onlineβ</title>
  7. <link rel="stylesheet" href="../script/tocas/tocas.css">
  8. <link rel="stylesheet" href="../script/css/font-awesome.min.css">
  9. <script src="../script/tocas/tocas.js"></script>
  10. <script src="../script/jquery.min.js"></script>
  11. </head>
  12. <body style="background-color:white;">
  13. <div id="headerSection" class="ts borderless basic fluid menu">
  14. <a href="../index.php" class="item">ArOZβ</a>
  15. <div class="header stretched center aligned item">Music Bank</div>
  16. <a class="item">
  17. <i class="bed icon"></i>
  18. </a>
  19. </div>
  20. <div class="ts segment">
  21. <div class="ts active inverted dimmer">
  22. <div class="ts text loader">Processing Uploads</div>
  23. </div>
  24. <h3>Experimental FFmpeg based mp4 to mp3 converter</h3>
  25. Build v1.12 with FFmpeg build 12620a-win32-static OR ffmpeg.js if you run this on linux<br>
  26. <i class="caution circle icon"></i>WARNING! PLEASE BE PATIENT WHILE WAITING FOR THE CONVERSION<br>
  27. <i class="caution circle icon"></i>DO NOT CLOCSE THIS PAGE UNTIL THE PROCESS HAS BEEN FINISHED<br>
  28. <i class="coffee icon"></i>If you are using linux, you will see below a list of convert pending files.<br>
  29. White Blocks are files that is waiting to convert.<br>
  30. Blue Blocks and yello blocks are both converting files. But blue blocks means it is converting in local and yelow means converting on server side.<br>
  31. Lastly, Green Blocks means it has been converted and ready to stream!
  32. </div>
  33. <?php
  34. $isWindows = false;
  35. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { #Change this to !== "WIN" if you are debugging on window or want to use Linux Upload Mode
  36. //This is a window machine, use ffmpeg.exe to convert mp4 to mp3
  37. echo '<script>
  38. window.onload = function () { window.location.replace("ffmpeg_handler.php"); }
  39. </script>';
  40. $isWindows = true;
  41. }else{
  42. //This is a raspberry pi, use client devices to convert mp4 into aac first and fix the aac with server processing power
  43. //echo '<button onClick="nextFile();" class="ts button">Click here to start</button>';
  44. echo '<iframe id="convertWindow" src="" style="width:100%;height:50%;display:none;"></iframe>';
  45. echo '<div class="ts narrow container segment"><div class="ts segmented list"><div class="item selected">Convert Pending Files</div>';
  46. $convertTarget = [];
  47. $filenames = [];
  48. $count = 0;
  49. foreach (glob("uploads/*.mp4") as $filename) {
  50. array_push($convertTarget,$filename);
  51. array_push($filenames,basename($filename));
  52. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  53. if (ctype_xdigit(str_replace("inith","",$filename)) && strlen(str_replace("inith","",$filename)) % 2 == 0) {
  54. $realName = hex2bin(str_replace("inith","",basename($filename,"." . $ext))) . ".$ext";
  55. }else{
  56. $realName = basename($filename,"." . $ext).".$ext";
  57. }
  58. echo '<div class="item" id="file'.$count.'" style="width:100%;overflow-wrap: break-word;overflow-x:hidden;"><i id="icon'.$count.'" class="loading spinner icon"></i>&nbsp&nbsp&nbsp'.$realName.'</div>';
  59. $count++;
  60. }
  61. echo '</div></div>';
  62. }
  63. //FFMPEG JS sample command
  64. //input.mp4 need not to be changed as it is automaically mapped to the "filename" variable.
  65. // /ffmpegjs/?cmd=-i input.mp4 -vn -b:a 128K -strict -2 -y inithe381bbe38293e381a8e381afe381adefbca0e38199e3818ee38284e381bee38090e6ad8ce381a3e381a6e381bfe3819fe38091.aac&filename=../uploads/inithe381bbe38293e381a8e381afe381adefbca0e38199e3818ee38284e381bee38090e6ad8ce381a3e381a6e381bfe3819fe38091.mp4
  66. ?>
  67. <script>
  68. var filesToBeConverted = <?php echo json_encode($convertTarget);?>;
  69. var fileNames = <?php echo json_encode($filenames);?>;
  70. var convertingID = 0;
  71. var VDI = !(!parent.isFunctionBar);
  72. var isWindows = <?php echo $isWindows ? "true" : "false";?>;
  73. $(document).ready(function(){
  74. if (isWindows == false){
  75. nextFile();
  76. }
  77. if (VDI){
  78. $('#headerSection').hide();
  79. }
  80. });
  81. function serverProcessing(){
  82. //Show that the file is being processed on the server side.
  83. $('#file' + (convertingID - 1)).css('background-color','#eaff96');
  84. }
  85. function nextFile(){
  86. //This was called within the iframe for converting the next item in array.
  87. if (filesToBeConverted.length > convertingID){
  88. $('#convertWindow').attr('src',"ffmpegjs.php?cmd=-i input.mp4 -vn -b:a 128K -strict -2 -y " + fileNames[convertingID].replace(".mp4",".aac") + "&filename=" + filesToBeConverted[convertingID]);
  89. $('#file' + (convertingID - 1)).css('background-color','#b2ffc8');
  90. $('#icon' + (convertingID - 1)).removeClass("loading spinner").addClass("checkmark");
  91. $('#file' + convertingID).css('background-color','#b2f8ff');
  92. convertingID ++;
  93. }else{
  94. //The conversion has been finished
  95. window.location.href = "index.php";
  96. }
  97. }
  98. </script>
  99. </body>
  100. </html>