/** * Opens a file in order to be processed. * * @param string $pathfile A pathfile * * @return Audio|Video * * @throws InvalidArgumentException */ public function open($pathfile) { if (null === ($streams = $this->ffprobe->streams($pathfile))) { throw new RuntimeException(sprintf('Unable to probe "%s".', $pathfile)); } if (0 < count($streams->videos())) { return new Video($pathfile, $this->driver, $this->ffprobe); } elseif (0 < count($streams->audios())) { return new Audio($pathfile, $this->driver, $this->ffprobe); } throw new InvalidArgumentException('Unable to detect file format, only audio and video supported'); }
/** * Opens a file in order to be processed. * * @param string $pathfile A pathfile * * @return Audio|Video * * @throws InvalidArgumentException */ public function open($pathfile) { if (!file_exists($pathfile)) { throw new InvalidArgumentException(sprintf('File %s does not exists', $pathfile)); } $streams = $this->ffprobe->streams($pathfile); if (0 < count($streams->videos())) { return new Video($pathfile, $this->driver, $this->ffprobe); } elseif (0 < count($streams->audios())) { return new Audio($pathfile, $this->driver, $this->ffprobe); } throw new InvalidArgumentException('Unable to detect file format, only audio and video supported'); }
/** * {@inheritdoc} */ public function read($filename) { $meta = new ValueBag(); try { $format = $this->ffprobe->format($filename); if ($format->has('format_name')) { $meta->set('media.format_name', new MetaValue($format->get('format_name'))); } if ($format->has('format_long_name')) { $meta->set('media.format_long_name', new MetaValue($format->get('format_long_name'))); } if ($format->has('duration')) { $meta->set('media.duration', new MetaValue($format->get('duration'))); } if ($format->has('bit_rate')) { $meta->set('media.bit_rate', new MetaValue($format->get('bit_rate'))); } if ($format->has('width')) { $meta->set('media.width', new MetaValue($format->get('width'))); } if ($format->has('height')) { $meta->set('media.height', new MetaValue($format->get('height'))); } if ($format->has('nb_streams')) { $meta->set('media.number_of_streams', new MetaValue($format->get('nb_streams'))); } $streams = $this->ffprobe->streams($filename); foreach ($streams as $stream) { $index = $stream->get('index'); $prefix = 'stream_' . $index; $type = 'media'; if ($stream->isVideo()) { $type = 'video'; } elseif ($stream->isAudio()) { $type = 'audio'; } if ($stream->has('codec_type')) { $meta->set("{$type}.{$prefix}.codec_type", new MetaValue($stream->get('codec_type'))); } if ($stream->has('codec_name')) { $meta->set("{$type}.{$prefix}.codec_name", new MetaValue($stream->get('codec_name'))); } if ($stream->has('codec_long_name')) { $meta->set("{$type}.{$prefix}.codec_long_name", new MetaValue($stream->get('codec_long_name'))); } if ($stream->has('codec_time_base')) { $meta->set("{$type}.{$prefix}.codec_time_base", new MetaValue($stream->get('codec_time_base'))); } if ($stream->has('codec_tag_string')) { $meta->set("{$type}.{$prefix}.codec_tag", new MetaValue($stream->get('codec_tag_string'))); } if ($stream->has('bit_rate')) { $meta->set("{$type}.{$prefix}.bit_rate", new MetaValue($stream->get('bit_rate'))); } if ($stream->has('display_aspect_ration')) { $meta->set("{$type}.{$prefix}.aspect_ratio", new MetaValue($stream->get('display_aspect_ratio'))); } if ($stream->has('avg_frame_rate')) { $meta->set("{$type}.{$prefix}.frame_rate", new MetaValue($stream->get('avg_frame_rate'))); } if ($stream->has('bits_per_sample')) { $meta->set("{$type}.{$prefix}.bits_per_sample", new MetaValue($stream->get('bits_per_sample'))); } if ($stream->has('channels')) { $meta->set("{$type}.{$prefix}.channels", new MetaValue($stream->get('channels'))); } } } catch (\Exception $e) { } return $meta; }