ffmpeg_converter.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $realName = hex2bin(str_replace("inith","",basename($filename,"." . $ext))) . ".$ext";
  54. 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>';
  55. $count++;
  56. }
  57. echo '</div></div>';
  58. }
  59. //FFMPEG JS sample command
  60. //input.mp4 need not to be changed as it is automaically mapped to the "filename" variable.
  61. // /ffmpegjs/?cmd=-i input.mp4 -vn -b:a 128K -strict -2 -y inithe381bbe38293e381a8e381afe381adefbca0e38199e3818ee38284e381bee38090e6ad8ce381a3e381a6e381bfe3819fe38091.aac&filename=../uploads/inithe381bbe38293e381a8e381afe381adefbca0e38199e3818ee38284e381bee38090e6ad8ce381a3e381a6e381bfe3819fe38091.mp4
  62. ?>
  63. <script>
  64. var filesToBeConverted = <?php echo json_encode($convertTarget);?>;
  65. var fileNames = <?php echo json_encode($filenames);?>;
  66. var convertingID = 0;
  67. var VDI = !(!parent.isFunctionBar);
  68. var isWindows = <?php echo $isWindows ? "true" : "false";?>;
  69. $(document).ready(function(){
  70. if (isWindows == false){
  71. nextFile();
  72. }
  73. if (VDI){
  74. $('#headerSection').hide();
  75. }
  76. });
  77. function serverProcessing(){
  78. //Show that the file is being processed on the server side.
  79. $('#file' + (convertingID - 1)).css('background-color','#eaff96');
  80. }
  81. function nextFile(){
  82. //This was called within the iframe for converting the next item in array.
  83. if (filesToBeConverted.length > convertingID){
  84. $('#convertWindow').attr('src',"ffmpegjs.php?cmd=-i input.mp4 -vn -b:a 128K -strict -2 -y " + fileNames[convertingID].replace(".mp4",".aac") + "&filename=" + filesToBeConverted[convertingID]);
  85. $('#file' + (convertingID - 1)).css('background-color','#b2ffc8');
  86. $('#icon' + (convertingID - 1)).removeClass("loading spinner").addClass("checkmark");
  87. $('#file' + convertingID).css('background-color','#b2f8ff');
  88. convertingID ++;
  89. }else{
  90. //The conversion has been finished
  91. window.location.href = "index.php";
  92. }
  93. }
  94. </script>
  95. </body>
  96. </html>