Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function generateSources(Files $iFile, $resolutions, $doneUri)
- {
- $iSource = $iFile->getSource();
- $pathSource = $this->FilesService->getPathForSource($iSource);
- $iStorage = $iSource->getStorage();
- $rabbitData = explode(':', $doneUri);
- $this->messageData['id'] = $rabbitData[1];
- $this->messageData['fileid'] = (string)$iFile->getId();
- $mp4file = $this->convertToMp4($iSource);
- $height = $mp4file['resolution'];
- $width = $mp4file['width'];
- $duration = $mp4file['duration'];
- $mp4Source = $this->addFormat($iSource, $mp4file);
- if(strtolower(pathinfo($pathSource, PATHINFO_EXTENSION)) == 'mp4'){
- $jpgfile = $this->getImageFromVideo($iSource);
- $subPath = $this->FilesService->genSubPathForSourceFile('jpg');
- $path = $this->FilesService->getPathForStorageFiles($iStorage);
- $this->FilesService->mkdir(dirname($path.DIRECTORY_SEPARATOR.$subPath));
- copy($jpgfile, $path.DIRECTORY_SEPARATOR.$subPath);
- unlink($jpgfile);
- $this->addFormat($iSource, [
- 'hash' => md5_file($path),
- 'path' => $subPath,
- 'size' => filesize($path),
- 'ext' => 'jpg',
- 'preview' => 1,
- 'resolution'=> $height,
- 'storage' => $iStorage,
- ]);
- }
- $mp4animation = $this->convertToGif($mp4Source, $height, $width);
- $mp4animation['resolution'] = $height;
- $this->addFormat($iSource, $mp4animation);
- $resolutions = array_reverse($resolutions);
- foreach ($resolutions as $resolution){
- if ($this->checkIssetResolution($mp4Source, $resolution['height']))
- continue;
- $data = $this->scaleFile($mp4Source, (int)$resolution['width'], (int)$resolution['height'], $duration);
- $newSource = $this->addFormat($iSource, $data);
- $this->addFormat($iSource, $data['image']);
- $this->SimLink->getAllForFile($iFile);
- $this->sendDoneMessage($rabbitData[0]);
- }
- // Создать оригинал
- if(count($resolutions) && !$this->entityManager->getRepository(\Entity\Formats::class)->findOneBy(['source'=>$iSource, 'formatSource'=>$iSource])){
- try{
- $ffmpeg = FFMpeg::create(array(
- 'ffmpeg.binaries' => exec('which ffmpeg'),
- 'ffprobe.binaries' => 'ffprobe', 'timeout' => 3600, 'ffmpeg.threads' => 12
- ), $this->logger);
- }catch (\Exception $e){
- throw new \Exception($e->getMessage());
- }
- $video = $ffmpeg->open($pathSource);
- // Получаем данные о ролике, нас интересуют размеры
- $streams = $video->getStreams();
- $streamsData = null;
- /** @var FFProbe\DataMapping\Stream $stream */
- foreach ($streams as $stream){
- $streamsProperties = $stream->all();
- if(!isset($streamsProperties['height']) && !isset($streamsProperties['width'])){
- continue;
- }else{
- $streamsData = $streamsProperties;
- break;
- }
- }
- $height = $streamsData['height'];
- $newSource = $this->addFormat($iSource, [
- 'ext' => strtolower($iSource->getExt()),
- 'preview' => 0,
- 'resolution' => $height,
- ], true);
- $this->SimLink->getAllForFile($iFile);
- $this->sendDoneMessage($rabbitData[0]);
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement