Ejemplo n.º 1
0
 public function execute(SpecificationInterface $spec, MediaInterface $source, $dest)
 {
     if (!$spec instanceof Audio) {
         throw new SpecNotSupportedException('FFMpeg Adapter only supports Audio specs');
     }
     try {
         $audio = $this->container['ffmpeg.ffmpeg']->open($source->getFile()->getPathname());
     } catch (FFMpegException $e) {
         throw new RuntimeException('Unable to transmute audio to audio due to FFMpeg', null, $e);
     }
     /* @var $spec \MediaAlchemyst\Specification\Audio */
     $format = $this->getFormatFromFileType($dest);
     if ($spec->getAudioCodec()) {
         $format->setAudioCodec($spec->getAudioCodec());
     }
     if ($spec->getAudioSampleRate()) {
         $audio->addFilter(new AudioResamplableFilter($spec->getAudioSampleRate()));
     }
     if ($spec->getAudioKiloBitrate()) {
         $format->setAudioKiloBitrate($spec->getAudioKiloBitrate());
     }
     try {
         $audio->save($format, $dest);
     } catch (FFMpegException $e) {
         throw new RuntimeException('Unable to transmute audio to audio due to FFMpeg', null, $e);
     }
 }
Ejemplo n.º 2
0
 public function execute(SpecificationInterface $spec, MediaInterface $source, $dest)
 {
     if (!$spec instanceof Video) {
         throw new SpecNotSupportedException('FFMpeg Adapter only supports Video specs');
     }
     try {
         $video = $this->container['ffmpeg.ffmpeg']->open($source->getFile()->getPathname());
     } catch (FFMpegException $e) {
         throw new RuntimeException('Unable to transmute video to video due to FFMpeg', null, $e);
     }
     /* @var $spec \MediaAlchemyst\Specification\Video */
     $format = $this->getFormatFromFileType($dest);
     $resizeMode = ResizeFilter::RESIZEMODE_FIT;
     if ($spec->getResizeMode()) {
         $resizeMode = $spec->getResizeMode();
     }
     $video->addFilter(new SynchronizeFilter());
     $video->addFilter(new ResizeFilter(new Dimension($spec->getWidth(), $spec->getHeight()), $resizeMode));
     if ($spec->getAudioCodec()) {
         $format->setAudioCodec($spec->getAudioCodec());
     }
     if ($spec->getVideoCodec()) {
         $format->setVideoCodec($spec->getVideoCodec());
     }
     if ($spec->getAudioSampleRate()) {
         $video->addFilter(new AudioResamplableFilter($spec->getAudioSampleRate()));
     }
     if ($spec->getAudioKiloBitrate()) {
         $format->setAudioKiloBitrate($spec->getAudioKiloBitrate());
     }
     if ($spec->getKiloBitrate()) {
         $format->setKiloBitrate($spec->getKiloBitrate());
     }
     if ($spec->getFramerate() && $spec->getGOPSize()) {
         $video->addFilter(new FrameRateFilter(new FrameRate($spec->getFramerate()), $spec->getGOPSize()));
     }
     try {
         $video->save($format, $dest);
         if ($format instanceof X264) {
             $this->container['mp4box']->process($dest);
         }
     } catch (FFMpegException $e) {
         throw new RuntimeException('Unable to transmute video to video due to FFMpeg', null, $e);
     } catch (MP4BoxException $e) {
         throw new RuntimeException('Unable to transmute video to video due to MP4Box', null, $e);
     }
     return $this;
 }
Ejemplo n.º 3
0
 public function execute(SpecificationInterface $spec, MediaInterface $source, $dest)
 {
     if (!$spec instanceof Video) {
         throw new SpecNotSupportedException('FFMpeg Adapter only supports Video specs');
     }
     try {
         $video = $this->container['ffmpeg.ffmpeg']->open($source->getFile()->getPathname());
     } catch (FFMpegException $e) {
         throw new RuntimeException('Unable to transmute video to video due to FFMpeg', null, $e);
     }
     /* @var $spec \MediaAlchemyst\Specification\Video */
     $format = $this->getFormatFromFileType($dest);
     $resizeMode = ResizeFilter::RESIZEMODE_FIT;
     if ($spec->getResizeMode()) {
         $resizeMode = $spec->getResizeMode();
     }
     if (true === static::$autorotate && method_exists($source, 'getOrientation')) {
         switch ($source->getOrientation()) {
             case MediaVorusVideo::ORIENTATION_90:
                 $video->addFilter(new RotateFilter(RotateFilter::ROTATE_90));
                 break;
             case MediaVorusVideo::ORIENTATION_270:
                 $video->addFilter(new RotateFilter(RotateFilter::ROTATE_270));
                 break;
             case MediaVorusVideo::ORIENTATION_180:
                 $video->addFilter(new RotateFilter(RotateFilter::ROTATE_180));
                 break;
             default:
                 break;
         }
     }
     $video->addFilter(new SynchronizeFilter());
     if ($source->getWidth() > $spec->getWidth() || $source->getHeight() > $spec->getHeight()) {
         $video->addFilter(new ResizeFilter(new Dimension($spec->getWidth(), $spec->getHeight()), $resizeMode));
     }
     if ($spec->getAudioCodec()) {
         $format->setAudioCodec($spec->getAudioCodec());
     }
     if ($spec->getVideoCodec()) {
         $format->setVideoCodec($spec->getVideoCodec());
     }
     if ($spec->getAudioSampleRate()) {
         $video->addFilter(new AudioResamplableFilter($spec->getAudioSampleRate()));
     }
     if ($spec->getAudioKiloBitrate()) {
         $format->setAudioKiloBitrate($spec->getAudioKiloBitrate());
     }
     if ($spec->getKiloBitrate()) {
         $format->setKiloBitrate($spec->getKiloBitrate());
     }
     if ($spec->getFramerate() && $spec->getGOPSize()) {
         $video->addFilter(new FrameRateFilter(new FrameRate($spec->getFramerate()), $spec->getGOPSize()));
     }
     try {
         $video->save($format, $dest);
         if ($format instanceof X264) {
             $this->container['mp4box']->process($dest);
         }
     } catch (FFMpegException $e) {
         throw new RuntimeException('Unable to transmute video to video due to FFMpeg', null, $e);
     } catch (MP4BoxException $e) {
         throw new RuntimeException('Unable to transmute video to video due to MP4Box', null, $e);
     }
     return $this;
 }