Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. public function generateSources(Files $iFile, $resolutions, $doneUri)
  2. {
  3. $iSource = $iFile->getSource();
  4. $pathSource = $this->FilesService->getPathForSource($iSource);
  5. $iStorage = $iSource->getStorage();
  6. $rabbitData = explode(':', $doneUri);
  7. $this->messageData['id'] = $rabbitData[1];
  8. $this->messageData['fileid'] = (string)$iFile->getId();
  9.  
  10. $mp4file = $this->convertToMp4($iSource);
  11. $height = $mp4file['resolution'];
  12. $width = $mp4file['width'];
  13. $duration = $mp4file['duration'];
  14. $mp4Source = $this->addFormat($iSource, $mp4file);
  15. if(strtolower(pathinfo($pathSource, PATHINFO_EXTENSION)) == 'mp4'){
  16. $jpgfile = $this->getImageFromVideo($iSource);
  17. $subPath = $this->FilesService->genSubPathForSourceFile('jpg');
  18. $path = $this->FilesService->getPathForStorageFiles($iStorage);
  19. $this->FilesService->mkdir(dirname($path.DIRECTORY_SEPARATOR.$subPath));
  20. copy($jpgfile, $path.DIRECTORY_SEPARATOR.$subPath);
  21. unlink($jpgfile);
  22. $this->addFormat($iSource, [
  23. 'hash' => md5_file($path),
  24. 'path' => $subPath,
  25. 'size' => filesize($path),
  26. 'ext' => 'jpg',
  27. 'preview' => 1,
  28. 'resolution'=> $height,
  29. 'storage' => $iStorage,
  30. ]);
  31. }
  32.  
  33. $mp4animation = $this->convertToGif($mp4Source, $height, $width);
  34. $mp4animation['resolution'] = $height;
  35. $this->addFormat($iSource, $mp4animation);
  36. $resolutions = array_reverse($resolutions);
  37. foreach ($resolutions as $resolution){
  38. if ($this->checkIssetResolution($mp4Source, $resolution['height']))
  39. continue;
  40. $data = $this->scaleFile($mp4Source, (int)$resolution['width'], (int)$resolution['height'], $duration);
  41. $newSource = $this->addFormat($iSource, $data);
  42. $this->addFormat($iSource, $data['image']);
  43.  
  44. $this->SimLink->getAllForFile($iFile);
  45.  
  46. $this->sendDoneMessage($rabbitData[0]);
  47. }
  48.  
  49. // Создать оригинал
  50. if(count($resolutions) && !$this->entityManager->getRepository(\Entity\Formats::class)->findOneBy(['source'=>$iSource, 'formatSource'=>$iSource])){
  51. try{
  52. $ffmpeg = FFMpeg::create(array(
  53. 'ffmpeg.binaries' => exec('which ffmpeg'),
  54. 'ffprobe.binaries' => 'ffprobe', 'timeout' => 3600, 'ffmpeg.threads' => 12
  55. ), $this->logger);
  56. }catch (\Exception $e){
  57. throw new \Exception($e->getMessage());
  58. }
  59. $video = $ffmpeg->open($pathSource);
  60. // Получаем данные о ролике, нас интересуют размеры
  61. $streams = $video->getStreams();
  62. $streamsData = null;
  63. /** @var FFProbe\DataMapping\Stream $stream */
  64. foreach ($streams as $stream){
  65. $streamsProperties = $stream->all();
  66.  
  67. if(!isset($streamsProperties['height']) && !isset($streamsProperties['width'])){
  68. continue;
  69. }else{
  70. $streamsData = $streamsProperties;
  71. break;
  72. }
  73. }
  74. $height = $streamsData['height'];
  75. $newSource = $this->addFormat($iSource, [
  76. 'ext' => strtolower($iSource->getExt()),
  77. 'preview' => 0,
  78. 'resolution' => $height,
  79. ], true);
  80.  
  81. $this->SimLink->getAllForFile($iFile);
  82.  
  83. $this->sendDoneMessage($rabbitData[0]);
  84. };
  85.  
  86.  
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement