Created
July 21, 2016 09:41
-
-
Save Dubiy/c9d90c3f851bccd32f9bba012ce89753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Service; | |
use Aws\ElasticTranscoder\ElasticTranscoderClient; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
use Symfony\Component\Security\Core\SecurityContext; | |
use Symfony\Component\Validator\Validator; | |
use Doctrine\Bundle\DoctrineBundle\Registry; | |
/** | |
* Description of ElasticTranscoderService | |
* | |
* @author igor | |
*/ | |
class ElasticTranscoderService | |
{ | |
protected $credentials; | |
public function __construct($elasticTranscoderClient, $pipelineId, $presetId, $preset240pId, $preset360pId, $preset480pId, $preset720pId) | |
{ | |
$this->elasticTranscoderClient = $elasticTranscoderClient; | |
$this->pipelineId = $pipelineId; | |
$this->presetId = $presetId; | |
$this->preset240pId = $preset240pId; | |
$this->preset360pId = $preset360pId; | |
$this->preset480pId = $preset480pId; | |
$this->preset720pId = $preset720pId; | |
} | |
public function createJob($key, $thumb = false) { | |
$keyParts = explode('.', $key); | |
if (count($keyParts) > 1) { | |
unset($keyParts[count($keyParts) - 1]); | |
} | |
$baseFilename = implode('.', $keyParts); | |
$job = [ | |
'PipelineId' => $this->pipelineId, | |
'Input' => [ | |
'Key' => $key, | |
], | |
'Outputs' => [ | |
[ | |
'Key' => $baseFilename . '.mp4', | |
'PresetId' => $this->presetId | |
], | |
[ | |
'Key' => $baseFilename . '-hls-240p', | |
'PresetId' => $this->preset240pId, | |
'SegmentDuration' => '10', | |
], | |
[ | |
'Key' => $baseFilename . '-hls-360p', | |
'PresetId' => $this->preset360pId, | |
'SegmentDuration' => '10', | |
], | |
[ | |
'Key' => $baseFilename . '-hls-480p', | |
'PresetId' => $this->preset480pId, | |
'SegmentDuration' => '10', | |
], | |
[ | |
'Key' => $baseFilename . '-hls-720p', | |
'PresetId' => $this->preset720pId, | |
'SegmentDuration' => '10', | |
] | |
], | |
'Playlists' => [ | |
[ | |
'Name' => $baseFilename, | |
'Format' => 'HLSv3', | |
'OutputKeys' => [ | |
$baseFilename . '-hls-240p', | |
$baseFilename . '-hls-360p', | |
$baseFilename . '-hls-480p', | |
$baseFilename . '-hls-720p' | |
], | |
] | |
], | |
]; | |
if ($thumb) { | |
$job['Outputs'][0]['ThumbnailPattern'] = $baseFilename . '{count}'; | |
} | |
$result = $this->elasticTranscoderClient->createJob($job); | |
return $result; | |
} | |
public function readJob($jobId){ | |
$result = $this->elasticTranscoderClient->readJob(array( | |
'Id' => $jobId, | |
)); | |
return $result; | |
} | |
public function cancelJob($jobId){ | |
$result = $this->elasticTranscoderClient->cancelJob(array( | |
'Id' => $jobId, | |
)); | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment