index.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * SCRIPT UNDER DEVELOPMENT - DO NOT USE IN PRODUCTION
  4. * This script converts the uploaded file to webm or ogv and stores it
  5. * into the underlying upload/ directory. The objective of this script is to
  6. * serve as a base to create a video converter inside the Chamilo interface
  7. * as a plugin (because it is likely to require considerable CPU time to process
  8. * the uploaded videos)
  9. * @todo integrate as library and generate video tags to play the result
  10. * @package chamilo.misc.dev.video-converter
  11. * @requires ffmpeg installed on the server
  12. * @requires GNU/Linux
  13. * @requires Possibly requires the existence of specific codecs on the system
  14. */
  15. /**
  16. * Initialization - removing all limits possibly affecting this process
  17. */
  18. ini_set('memory_limit',0);
  19. ini_set('max_execution_time',0);
  20. ini_set('upload_max_filesize',0);
  21. ini_set('post_max_size',0);
  22. /**
  23. * Print form
  24. */
  25. ?>
  26. <html>
  27. <body>
  28. <p>
  29. <form method="post" action="" enctype="multipart/form-data">
  30. <table>
  31. <tr><td><label for="video"><?php echo get_lang('VideoToConvert');?></label></td><td><input type="file" name="video"/></td></tr>
  32. <tr><td><label for="codec"><?php echo get_lang('VideoCodecWantedForConversionDest');?></td>
  33. <td>
  34. <select name="codec">
  35. <option value="webm" selected>WebM</option>
  36. <option value="ogv">OGV</option>
  37. </select>
  38. </td>
  39. </tr>
  40. <tr><td colspan="2"><input type="submit" name="convert" value="<?php echo get_lang('Convert'); ?>"></tr>
  41. </table>
  42. </form>
  43. </p>
  44. <p>
  45. <?php
  46. /**
  47. * Deal with uploaded files
  48. */
  49. if (!empty($_FILES['video'])) {
  50. error_log($_FILES['video']['name']);
  51. $orig = dirname(__FILE__).'/upload/'.md5(uniqid(rand(),true)).'-'.$_FILES['video']['name'];
  52. $dest = dirname(__FILE__).'/upload/'.md5(uniqid(rand(),true)).'-'.substr($_FILES['video']['name'],0,-3).(($_POST['codec']!='ogv')?'webm':'ogv');
  53. error_log($dest);
  54. $res = @move_uploaded_file($_FILES['video']['tmp_name'],$orig);
  55. if ($res === false) { error_log("Error al mover el video: ".$php_error_msg); }
  56. error_log('Calling '.'ffmpeg -i '.$orig.' -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 345k -v quiet -s 1080x720 '.$dest);
  57. $ffmpeg = @exec('ffmpeg -i '.$orig.' -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 345k -v quiet -s 1080x720 '.$dest);
  58. if ($ffmpeg === false) { error_log('no'); }
  59. }
  60. ?>
  61. </p>
  62. <p>
  63. <?php
  64. /**
  65. * Prints a list of files inside the upload directory (with links)
  66. */
  67. echo get_lang('VideoFilesInFolder')."<br />";
  68. $list = scandir(dirname(__FILE__).'/upload');
  69. if (is_array($list)) {
  70. foreach ($list as $file) {
  71. if (substr($file,0,1) == '.') {
  72. continue;
  73. } else {
  74. echo '<a href="http://virtualdes.icpna.edu.pe/video/upload/'.$file.'">'.$file.'</a><br />'."\n";
  75. }
  76. }
  77. }
  78. ?>
  79. </p>
  80. </body>
  81. </html>