dash manifest

This commit is contained in:
shimon
2022-08-05 11:38:32 +03:00
parent 6ca361d0b0
commit e8c96e8452
2 changed files with 36 additions and 22 deletions
+28 -14
View File
@@ -744,18 +744,25 @@ App::get('/v1/videos/:videoId/streams/:streamId')
$template = new View(__DIR__ . '/../../views/videos/hls-master.phtml');
$template->setParam('paramsSubtitles', $paramsSubtitles);
$template->setParam('paramsRenditions', $paramsRenditions);
$response->setContentType('application/x-mpegurl')->send($template->render(false));
$response->setContentType('application/x-mpegurl')
->send($template->render(false))
;
} else {
$adaptationsSubs = [];
$adaptations = [];
$adaptationId = 0;
foreach ($renditions ?? [] as $rendition) {
$metadata = $rendition->getAttribute('metadata');
$xml = simplexml_load_string($metadata['mpd']);
if (empty($xml)) {
continue;
}
$attributes = (array)$xml->attributes();
$mpd = $attributes['@attributes'] ?? [];
$representationId = 0;
foreach ($xml->Period->AdaptationSet ?? [] as $adaptation) {
$representation = [];
$representation['id'] = $representationId;
@@ -763,45 +770,52 @@ App::get('/v1/videos/:videoId/streams/:streamId')
$representation['attributes'] = $attributes['@attributes'] ?? [];
$attributes = (array)$adaptation->Representation->SegmentList->attributes();
$representation['segmentList']['attributes'] = $attributes['@attributes'] ?? [];
$segments = Authorization::skip(fn() => $dbForProject->find('videos_renditions_segments', [
new Query('renditionId', Query::TYPE_EQUAL, [$rendition->getId()]),
new Query('representationId', Query::TYPE_EQUAL, [$representationId]),
], 1000, 0, ['representationId']));
if (count($segments) === 0) {
continue;
}
foreach ($segments ?? [] as $segment) {
if ($segment->getAttribute('isInit')) {
$representation['segmentList']['init'] = $segment->getId();
continue;
}
$representation['segmentList']['media'][] = $segment->getId();
}
$attributes = (array)$adaptation->attributes();
$adaptations[] = ['attributes' => $attributes['@attributes'] ?? [],
'id' => $adaptationId,
$adaptations[] = [
'attributes' => $attributes['@attributes'] ?? [],
'group' => $adaptationId,
'baseUrl' => $baseUrl . '/renditions/' . $rendition->getId() . '/' . 'segments/',
'representation' => $representation,
];
$adaptationId++;
$representationId++;
}
}
foreach ($subtitles ?? [] as $subtitle) {
$adaptationsSubs[] = [
'id' => $adaptationId,
'baseUrl' => $baseUrl . '/subtitles/' . $subtitle->getId(),
'code' => $subtitle->getAttribute('code'),
];
$adaptationId++;
}
foreach ($subtitles ?? [] as $subtitle) {
$adaptationsSubs[] = [
'id' => $adaptationId,
'baseUrl' => $baseUrl . '/subtitles/' . $subtitle->getId(),
'code' => $subtitle->getAttribute('code'),
];
$adaptationId++;
}
$template = new View(__DIR__ . '/../../views/videos/dash.phtml');
$template->setParam('mpd', $mpd);
$template->setParam('adaptations', $adaptations);
$template->setParam('subtitles', $adaptationsSubs);
$template->setParam('params', $adaptations);
$response->setContentType('application/dash+xml')->send($template->render(false));
$response->setContentType('application/dash+xml')
->send($template->render(false))
;
}
});
+8 -8
View File
@@ -1,19 +1,19 @@
<?php
$mpd = $this->getParam('mpd', []);
echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT13.2S" maxSegmentDuration="PT6.0S" minBufferTime="PT16.6S">
profiles="<?php if (isset($mpd['profiles'])): echo ($mpd['profiles']); endif;?>" type="<?php if (isset($mpd['type'])): echo ($mpd['type']); endif;?>" mediaPresentationDuration="<?php if (isset($mpd['maxSegmentDuration'])): echo ($mpd['mediaPresentationDuration']); endif;?>" maxSegmentDuration="<?php if (isset($mpd['maxSegmentDuration'])): echo ($mpd['maxSegmentDuration']); endif;?>" minBufferTime="<?php if (isset($mpd['minBufferTime'])): echo ($mpd['minBufferTime']); endif;?>">
<ProgramInformation></ProgramInformation>
<ServiceDescription id="0"></ServiceDescription>
<Period id="0" start="PT0.0S">
<?php foreach ($this->getParam('params', []) as $param):
$representation = $param['representation'];
<?php foreach ($this->getParam('adaptations', []) as $adaptation):
$representation = $adaptation['representation'];
?>
<AdaptationSet <?php if (isset($param['id'])):?> id="<?php echo $param['id']; ?>"<?php endif;?><?php if (isset($param['attributes']['contentType'])): ?> contentType="<?php echo $param['attributes']['contentType']; ?>"<?php endif;?><?php if (isset($param['attributes']['startWithSAP'])): ?> startWithSAP="<?php echo $param['attributes']['startWithSAP']; ?>"<?php endif;?><?php if (isset($param['attributes']['segmentAlignment'])): ?> segmentAlignment="<?php echo $param['attributes']['segmentAlignment']; ?>"<?php endif;?><?php if (isset($param['attributes']['bitstreamSwitching'])): ?> bitstreamSwitching="<?php echo $param['attributes']['bitstreamSwitching']; ?>"<?php endif;?><?php if (isset($param['attributes']['frameRate'])): ?> frameRate="<?php echo $param['attributes']['frameRate']; ?>"<?php endif;?><?php if (isset($param['attributes']['maxWidth'])): ?> maxWidth="<?php echo $param['attributes']['maxWidth']; ?>"<?php endif;?><?php if (isset($param['attributes']['par'])): ?> par="<?php echo $param['attributes']['par']; ?>"<?php endif;?><?php if (isset($param['attributes']['lang'])): ?> lang="<?php echo $param['attributes']['lang']; ?>"<?php endif;?>>
<AdaptationSet <?php if (isset($adaptation['group'])):?> group="<?php echo ($adaptation['group']); endif;?>"<?php if (isset($adaptation['attributes']['contentType'])): ?> contentType="<?php echo $adaptation['attributes']['contentType']; ?>"<?php endif;?><?php if (isset($adaptation['attributes']['startWithSAP'])): ?> startWithSAP="<?php echo $adaptation['attributes']['startWithSAP']; ?>"<?php endif;?><?php if (isset($adaptation['attributes']['segmentAlignment'])): ?> segmentAlignment="<?php echo $adaptation['attributes']['segmentAlignment']; ?>"<?php endif;?><?php if (isset($adaptation['attributes']['bitstreamSwitching'])): ?> bitstreamSwitching="<?php echo $adaptation['attributes']['bitstreamSwitching']; ?>"<?php endif;?><?php if (isset($adaptation['attributes']['frameRate'])): ?> frameRate="<?php echo $adaptation['attributes']['frameRate']; ?>"<?php endif;?><?php if (isset($adaptation['attributes']['maxWidth'])): ?> maxWidth="<?php echo $adaptation['attributes']['maxWidth']; ?>"<?php endif;?><?php if (isset($adaptation['attributes']['par'])): ?> par="<?php echo $adaptation['attributes']['par']; ?>"<?php endif;?><?php if (isset($adaptation['attributes']['lang'])): ?> lang="<?php echo $adaptation['attributes']['lang']; ?>"<?php endif;?>>
<Representation <?php if (isset($representation['attributes']['id'])):?> id="<?php echo $representation['attributes']['id']; ?>"<?php endif;?><?php if (isset($representation['attributes']['mimeType'])):?> mimeType="<?php echo $representation['attributes']['mimeType']; ?>"<?php endif;?><?php if (isset($representation['attributes']['codecs'])):?> codecs="<?php echo $representation['attributes']['codecs']; ?>"<?php endif;?><?php if (isset($representation['attributes']['width'])):?> width="<?php echo $representation['attributes']['width']; ?>"<?php endif;?><?php if (isset($representation['attributes']['height'])):?> height="<?php echo $representation['attributes']['height']; ?>"<?php endif;?><?php if (isset($representation['attributes']['sar'])):?> sar="<?php echo $representation['attributes']['sar']; ?>"<?php endif;?><?php if (isset($representation['attributes']['audioSamplingRate'])):?> audioSamplingRate="<?php echo $representation['attributes']['audioSamplingRate']; ?>"<?php endif;?>>
<BaseURL><?php if (isset($param['baseUrl'])): echo $param['baseUrl']; endif;?></BaseURL>
<?php if (isset($param['attributes']['contentType']) && $param['attributes']['contentType'] === 'audio' ):?>
<BaseURL><?php if (isset($adaptation['baseUrl'])): echo $adaptation['baseUrl']; endif;?></BaseURL>
<?php if (isset($adaptation['attributes']['contentType']) && $adaptation['attributes']['contentType'] === 'audio' ):?>
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2" />
<?php endif;?>
<SegmentList<?php if (isset($representation['segmentList']['attributes']['timescale'])): ?> timescale="<?php echo $representation['segmentList']['attributes']['timescale']; ?>"<?php endif;?><?php if (isset($representation['segmentList']['attributes']['duration'])): ?> duration="<?php echo $representation['segmentList']['attributes']['duration']; ?>"<?php endif;?><?php if (isset($representation['segmentList']['attributes']['startNumber'])): ?> startNumber="<?php echo $representation['segmentList']['attributes']['startNumber']; ?>"<?php endif;?>>
@@ -28,7 +28,7 @@ echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
</AdaptationSet>
<?php endforeach; ?>
<?php foreach ($this->getParam('subtitles', []) as $subtitle):?>
<AdaptationSet id="<?php if (isset($subtitle['id'])): echo $subtitle['id']; endif;?>" contentType="text" lang="<?php if (isset($subtitle['code'])): echo $subtitle['code']; endif;?>" mimeType="text/vtt">
<AdaptationSet group="<?php if (isset($subtitle['id'])): echo $subtitle['id']; endif;?>" contentType="text" lang="<?php if (isset($subtitle['code'])): echo $subtitle['code']; endif;?>" mimeType="text/vtt">
<Role value="main" />
<Representation id="<?php if (isset($subtitle['id'])): echo $subtitle['id']; endif;?>" bandwidth="1000">
<BaseURL><?php if (isset($subtitle['baseUrl'])): echo $subtitle['baseUrl']; endif;?></BaseURL>