+class ProcessVideoQueueCommand extends ContainerAwareCommand
+ protected $videoManager = null;
+ protected $videoRepository = null;
+ protected $ffmpeg = null;
+ protected function configure()
+ ->setName('video:convert:queue')
+ ->setDescription('Run queue of video encoding')
+ protected function execute(InputInterface $input, OutputInterface $output)
+ $container = $this->getContainer();
+ $this->videoManager = $container->get('VideoManager');
+ $this->em = $container->get('doctrine.orm.entity_manager');
+ $this->videoRepository = $this->em->getRepository('AppBundle:Video');
+ $logger = $container->get('logger');
+ $ffmprobe = FFMPEG/FFProbe::create()
+ $this->ffmpeg =FFMPEG/FFMpeg::create();
+ $this->ffmpeg->setProber($ffmprobe);
+ $videos = $this->videoRepository->getPendingVideos();
+ $logger->info('Number of VIDEOS TO PROCCESS: '.count($videos));
+ foreach ($videos as $video) {
+ protected function encode($video)
+ $container = $this->getContainer();
+ $logger = $container->get('logger');
+ $logger->info('Proccessing video: '.$video->getId());
+ $video->setStatus(Video::STATUS_ENCODING);
+ $video->setEncodingStarted(new \DateTime());
+ $x264Format = new FFMpeg\Format\Video\X264();
+ $formats = array($x264Format);
+ foreach ($formats as $format) {
+ ->open($this->videoManager->getVideoRootFile($video))
+ $this->videoManager->getVideoRootPath($video).'/'.$format->getFilename()
+ $video->setUpdated(new \DateTime('now'));
+ $video->setEncodingFinished(new \DateTime('now'));
+ $video->setStatus(Video::STATUS_COMPLETED);
+ } catch (\FFMpeg\Exception\RuntimeException $e) {
+ $logger->info('MSG: '.$e->getMessage());
+ $video->setStatus(Video::STATUS_ERROR);
+ $video->setEncodingErrors(
+ $video->getEncodingErrors()."\n".
+ 'Format failed: '.get_class($current)