/** * Extract file meta data * * @param Audio $audio audio file instance * @return array */ protected function extractInformation(Audio $audio) { $tmpFile = $this->temp->create($audio->getContent()); $info = $this->reader->analyze($tmpFile->getPathname()); $tmpFile->destroy(); if (isset($info['audio']['streams'])) { unset($info['audio']['streams']); } return [$info['audio'], $info['playtime_seconds'], $info['bitrate']]; }
/** * 영상에서 snapshot 추출 * * @param string $content media content * @param int $fromSecond 영상에서의 시간(초 단위) * @return string */ public function getSnapshot($content, $fromSecond = 10) { $videoFile = $this->temp->create($content); $imgPathname = $this->temp->getTempPathname(); $video = $this->ffmpeg->open($videoFile->getPathname()); $video->frame(TimeCode::fromSeconds($fromSecond))->save($imgPathname); $imageContent = file_get_contents($imgPathname); $videoFile->destroy(); @unlink($imgPathname); return $imageContent; }
/** * create file * * @param string $content file content * @param string $path directory for saved * @param string $name saved name * @param string|null $disk disk for saved * @param string|null $originId original file id * @param UserInterface $user user instance * @return File */ public function create($content, $path, $name, $disk = null, $originId = null, UserInterface $user = null) { $id = $this->keygen->generate(); $path = $this->makePath($id, $path); $tempFile = $this->tempFiles->create($content); $disk = $disk ?: $this->distributor->allot($tempFile); $user = $user ?: $this->auth->user(); if (!$this->files->store($content, $path . '/' . $name, $disk)) { throw new WritingFailException(); } $file = $this->createModel(); $file->id = $id; $file->userId = $user->getId(); $file->disk = $disk; $file->path = $path; $file->filename = $name; $file->clientname = $name; $file->mime = $tempFile->getMimeType(); $file->size = $tempFile->getSize(); if ($originId !== null) { $file->originId = $originId; } $file->save(); $tempFile->destroy(); return $file; }