$hls_64k_audio_preset_id,
'hls0400k' => $hls_0400k_preset_id,
'hls0600k' => $hls_0600k_preset_id,
'hls1000k' => $hls_1000k_preset_id,
'hls1500k' => $hls_1500k_preset_id,
'hls2000k' => $hls_2000k_preset_id,
);
// HLS Segment duration that will be targeted.
$segment_duration = '2';
//All outputs will have this prefix prepended to their output key.
$output_key_prefix = 'elastic-transcoder-samples/output/hls/';
// Create the client for Elastic Transcoder.
$transcoder_client = ElasticTranscoderClient::factory(['region' => $region, 'default_caching_config' => '/tmp']);
function create_hls_job(
$transcoder_client,
$pipeline_id,
$input_key,
$output_key_prefix,
$hls_presets,
$segment_duration
) {
// Set up the job input using the provided input key.
$input = ['Key' => $input_key];
//Set up the job outputs using the HLS presets.
$output_key = hash('sha256', utf8_encode($input_key));
// Specify the outputs based on the hls presets array specified.
$outputs = [];
foreach ($hls_presets as $prefix => $preset_id) {
$outputs[] = ['Key' => "$prefix/$output_key", 'PresetId' => $preset_id, 'SegmentDuration' => $segment_duration];
}
// Setup master playlist which can be used to play using adaptive bitrate.
$playlist = [
'Name' => 'hls_' . $output_key,
'Format' => 'HLSv3',
'OutputKeys' => array_map(function ($x) {
return $x['Key'];
}, $outputs)
];
// Create the job.
$create_job_request = [
'PipelineId' => $pipeline_id,
'Input' => $input,
'Outputs' => $outputs,
'OutputKeyPrefix' => "$output_key_prefix$output_key/",
'Playlists' => [$playlist]
];
$create_job_result = $transcoder_client->createJob($create_job_request)->toArray();
return $job = $create_job_result['Job'];
}
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// If the request method is GET, return the form which will allow the user to
// specify pipeline and input key.
echo "Create an Elastic Transcoder HLS job.
';
echo "HLS job has been created:\n";
echo json_encode($job, JSON_PRETTY_PRINT);
echo '';
}
// snippet-end:[elastictranscoder.php.creation.sample]