mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
hls master name change
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -272,8 +272,7 @@ App::post('/v1/video/:videoId/rendition/:profileId')
|
||||
->inject('mode')
|
||||
->inject('deviceFiles')
|
||||
->inject('deviceLocal')
|
||||
->action(action: function (string $videoId, string $profileId, ?array $read, ?array $write, Request $request, Response $response, Database $dbForProject, $project, Document $user, Audit $audits, Stats $usage, Event $events, string $mode, Device $deviceFiles, Device $deviceLocal) {
|
||||
/** @var Utopia\Database\Document $project */
|
||||
->action(action: function (string $videoId, string $profileId, ?array $read, ?array $write, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Audit $audits, Stats $usage, Event $events, string $mode, Device $deviceFiles, Device $deviceLocal) {
|
||||
|
||||
$video = Authorization::skip(fn() => $dbForProject->findOne('videos', [new Query('_uid', Query::TYPE_EQUAL, [$videoId])]));
|
||||
|
||||
@@ -319,12 +318,11 @@ App::get('/v1/video/:videoId/:stream/renditions')
|
||||
->param('write', null, new Permissions(), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('usage')
|
||||
->inject('mode')
|
||||
->inject('user')
|
||||
->action(function (string $videoId, string $stream, ?array $read, ?array $write, Response $response, Database $dbForProject, Stats $usage, string $mode, Document $user) {
|
||||
|
||||
/** @var Utopia\Database\Document $project */
|
||||
->action(function (string $videoId, string $stream, ?array $read, ?array $write, Response $response, Database $dbForProject, Document $project, Stats $usage, string $mode, Document $user) {
|
||||
|
||||
$video = Authorization::skip(fn() => $dbForProject->findOne('videos', [new Query('_uid', Query::TYPE_EQUAL, [$videoId])]));
|
||||
|
||||
@@ -371,18 +369,19 @@ App::get('/v1/video/:videoId/:stream/:profile/:fileName')
|
||||
->param('write', null, new Permissions(), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('videosDevice')
|
||||
->inject('usage')
|
||||
->inject('mode')
|
||||
->inject('user')
|
||||
->action(function (string $videoId, string $stream, string $profile, string $fileName, ?array $read, ?array $write, Response $response, Database $dbForProject, Device $videosDevice, Stats $usage, string $mode, Document $user) {
|
||||
/** @var Utopia\Database\Document $project */
|
||||
->action(function (string $videoId, string $stream, string $profile, string $fileName, ?array $read, ?array $write, Response $response, Database $dbForProject, Document $project, Device $videosDevice, Stats $usage, string $mode, Document $user) {
|
||||
|
||||
|
||||
$video = Authorization::skip(fn() => $dbForProject->findOne('videos', [
|
||||
new Query('_uid', Query::TYPE_EQUAL, [$videoId])
|
||||
]));
|
||||
|
||||
if ($video->isEmpty()) {
|
||||
if (empty($video)){
|
||||
throw new Exception('Video not found', 400, Exception::VIDEO_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -420,7 +419,7 @@ App::get('/v1/video/:videoId/:stream/:profile/:fileName')
|
||||
$paramsRenditions = [];
|
||||
foreach ($renditions as $rendition) {
|
||||
$paramsRenditions[] = [
|
||||
'bandwidth' => $rendition->getAttribute('videoBitrate') + $rendition->getAttribute('audioBitrate'),
|
||||
'bandwidth' => ($rendition->getAttribute('videoBitrate') + $rendition->getAttribute('audioBitrate')),
|
||||
'resolution' => $rendition->getAttribute('width') . 'X' . $rendition->getAttribute('height'),
|
||||
'name' => $rendition->getAttribute('name'),
|
||||
'uri' => $baseUrl . $rendition->getAttribute('name') . '/' . $rendition->getAttribute('videoId') . '_' . $rendition->getAttribute('height') . 'p.m3u8',
|
||||
@@ -431,7 +430,7 @@ App::get('/v1/video/:videoId/:stream/:profile/:fileName')
|
||||
$template = new View(__DIR__ . '/../../views/video/hls.phtml');
|
||||
$template->setParam('paramsSubtitles', $paramsSubtitles);
|
||||
$template->setParam('paramsRenditions', $paramsRenditions);
|
||||
$output = $template->render();
|
||||
$output = $template->render(false);
|
||||
} else {
|
||||
$adaptations = [];
|
||||
foreach ($renditions as $rendition) {
|
||||
@@ -449,7 +448,7 @@ App::get('/v1/video/:videoId/:stream/:profile/:fileName')
|
||||
$template = new View(__DIR__ . '/../../views/video/dash.phtml');
|
||||
$template->setParam('params', $adaptations);
|
||||
$response->setContentType($ct[$ext]);
|
||||
$output = $template->render();
|
||||
$output = $template->render(false);
|
||||
}
|
||||
} else {
|
||||
$output = $videosDevice->read($videosDevice->getRoot() . '/' . $videoId . '/' . $profile . '/' . $fileName);
|
||||
|
||||
@@ -843,7 +843,6 @@ App::setResource('project', function ($dbForConsole, $request, $console) {
|
||||
/** @var Utopia\Database\Document $console */
|
||||
|
||||
$projectId = $request->getParam('project', $request->getHeader('x-appwrite-project', 'console'));
|
||||
|
||||
if ($projectId === 'console') {
|
||||
return $console;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#EXTM3U
|
||||
#EXT-X-VERSION:3
|
||||
<?php foreach ($this->getParam('paramsSubtitles', []) as $subtitle): ?>
|
||||
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="<?php echo $subtitle['name']; ?>",DEFAULT=YES,AUTOSELECT=NO,FORCED=NO,LANGUAGE="<?php echo $subtitle['code']; ?>",URI="<?php echo $subtitle['uri']; ?>"<?php echo PHP_EOL?>
|
||||
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="<?php echo $subtitle['name']; ?>",DEFAULT=YES,AUTOSELECT=NO,FORCED=NO,LANGUAGE="<?php echo $subtitle['code']; ?>",URI="<?php echo $subtitle['uri']; ?>"<?php echo PHP_EOL?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php foreach ($this->getParam('paramsRenditions', []) as $rendition): ?>
|
||||
#EXT-X-STREAM-INF:BANDWIDTH="<?php echo $rendition['bandwidth']; ?>" ,RESOLUTION="<?php echo $rendition['resolution']; ?>" ,NAME="<?php echo $rendition['name']; ?>" <?php if($rendition['subs'] !== null): echo $rendition['subs']; endif?><?php echo PHP_EOL?>
|
||||
<?php echo $rendition['uri'] ?>
|
||||
<?php endforeach; ?>
|
||||
}
|
||||
#EXT-X-STREAM-INF:BANDWIDTH="<?php echo $rendition['bandwidth']; ?>" ,RESOLUTION="<?php echo $rendition['resolution']; ?>",NAME="<?php echo $rendition['name']; ?>"<?php if($rendition['subs'] !== null): echo $rendition['subs']; endif?><?php echo PHP_EOL?>
|
||||
<?php echo $rendition['uri'] ?><?php echo PHP_EOL?>
|
||||
<?php endforeach; ?>
|
||||
+18
-13
@@ -6,7 +6,6 @@ use Appwrite\Resque\Worker;
|
||||
use Streaming\Format\StreamFormat;
|
||||
use Streaming\HLSSubtitle;
|
||||
use Streaming\Media;
|
||||
use Streaming\Metadata;
|
||||
use Streaming\Representation;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
@@ -17,7 +16,6 @@ use Utopia\Database\Validator\Authorization;
|
||||
use FFMpeg\FFProbe\DataMapping\StreamCollection;
|
||||
use Utopia\Storage\Compression\Algorithms\GZIP;
|
||||
use Captioning\Format\SubripFile;
|
||||
use Captioning\Format\WebvttFile;
|
||||
|
||||
require_once __DIR__ . '/../init.php';
|
||||
|
||||
@@ -36,6 +34,7 @@ class TranscodingV1 extends Worker
|
||||
const STATUS_ERROR = 'error';
|
||||
|
||||
const STREAM_HLS = 'hls';
|
||||
const STREAM_MPEG_DASH = 'mpeg-dash';
|
||||
|
||||
//protected string $basePath = '/tmp/';
|
||||
protected string $basePath = '/usr/src/code/tests/tmp/';
|
||||
@@ -351,12 +350,15 @@ class TranscodingV1 extends Worker
|
||||
|
||||
$hls->setFormat($format)
|
||||
->setHlsTime($segementSize)
|
||||
->setHlsAllowCache(false)
|
||||
->addRepresentation($representation)
|
||||
->setAdditionalParams($additionalParams)
|
||||
->setHlsBaseUrl($this->getHlsBaseUri())
|
||||
->save($this->outPath);
|
||||
|
||||
$general = $this->getVideoInfo($hls->metadata()->getVideoStreams());
|
||||
$general['videoBitrate'] = $representation->getKiloBitrate() * 1024;
|
||||
$general['audioBitrate'] = $representation->getAudioKiloBitrate() * 1024;
|
||||
$general['width'] = $representation->getWidth();
|
||||
$general['height'] = $representation->getHeight();
|
||||
|
||||
@@ -412,19 +414,22 @@ class TranscodingV1 extends Worker
|
||||
*/
|
||||
private function getVideoInfo(StreamCollection $streams): array
|
||||
{
|
||||
return [
|
||||
'duration' => $streams->videos()->first()->get('duration'),
|
||||
'height' => $streams->videos()->first()->get('height'),
|
||||
'width' => $streams->videos()->first()->get('width'),
|
||||
'videoCodec' => $streams->videos()->first()->get('codec_name') . ',' . $streams->videos()->first()->get('codec_tag_string'),
|
||||
'videoFramerate' => $streams->videos()->first()->get('avg_frame_rate'),
|
||||
'videoBitrate' => (int)$streams->videos()->first()->get('bit_rate'),
|
||||
'audioCodec' => $streams->audios()->first()->get('codec_name') . ',' . $streams->audios()->first()->get('codec_tag_string'),
|
||||
'audioSamplerate' => (int)$streams->audios()->first()->get('sample_rate'),
|
||||
'audioBitrate' => (int)$streams->audios()->first()->get('bit_rate'),
|
||||
];
|
||||
//var_dump($streams->videos()->first()->get('bit_rate'));
|
||||
//var_dump($streams->audios()->first()->get('bit_rate'));
|
||||
return [
|
||||
'duration' => !empty($streams->videos()) ? $streams->videos()->first()->get('duration') : '0',
|
||||
'height' => !empty($streams->videos()) ? $streams->videos()->first()->get('height') : 0,
|
||||
'width' => !empty($streams->videos()) ? $streams->videos()->first()->get('width') : 0,
|
||||
'videoCodec' => !empty($streams->videos()) ? $streams->videos()->first()->get('codec_name') . ',' . $streams->videos()->first()->get('codec_tag_string') : '',
|
||||
'videoFramerate' => !empty($streams->videos()) ? $streams->videos()->first()->get('avg_frame_rate') : '',
|
||||
'videoBitrate' => !empty($streams->videos()) ? (int)$streams->videos()->first()->get('bit_rate') : 0,
|
||||
'audioCodec' => !empty($streams->audios()) ? $streams->audios()->first()->get('codec_name') . ',' . $streams->audios()->first()->get('codec_tag_string') : '',
|
||||
'audioSamplerate' => !empty($streams->audios()) ? (int)$streams->audios()->first()->get('sample_rate') : 0,
|
||||
'audioBitrate' => !empty($streams->audios()) ? (int)$streams->audios()->first()->get('bit_rate') : 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function setRenditionName($profile)
|
||||
{
|
||||
$this->renditionName = $profile->getAttribute('width')
|
||||
|
||||
@@ -15,7 +15,7 @@ class VideoCustomServerTest extends Scope
|
||||
use VideoCustom;
|
||||
use SideServer;
|
||||
|
||||
public function testTranscodeWithSubs() :array
|
||||
public function testTranscodeWithSubs(): array
|
||||
{
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/video/buckets/' . $this->getBucket()['$id'] . '/files/' . $this->getVideo()['$id'], [
|
||||
@@ -82,7 +82,7 @@ class VideoCustomServerTest extends Scope
|
||||
public function testTranscodingRendition(): array
|
||||
{
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/video/buckets/' . $this->getBucket()['$id'] . '/files/' . $this->getVideo()['$id'], [
|
||||
$response = $this->client->call(Client::METHOD_POST, '/video/buckets/' . $this->getBucket()['$id'] . '/files/' . $this->getVideo()['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
@@ -94,29 +94,28 @@ class VideoCustomServerTest extends Scope
|
||||
$videoId = $response['body']['$id'];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/video/profiles', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]);
|
||||
|
||||
|
||||
$profileId = $response['body']['profiles'][0]['$id'];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/video/' . $videoId . '/rendition/' . $profileId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'read' => ['role:all'],
|
||||
'write' => ['role:all']
|
||||
]);
|
||||
|
||||
|
||||
$this->assertNotEmpty($profileId);
|
||||
foreach ($response['body']['profiles'] as $profile) {
|
||||
|
||||
$profileId = $profile['$id'];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/video/' . $videoId . '/rendition/' . $profileId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'read' => ['role:all'],
|
||||
'write' => ['role:all']
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'videoId' => $videoId,
|
||||
'profileId' => $profileId,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -193,7 +192,6 @@ class VideoCustomServerTest extends Scope
|
||||
]);
|
||||
|
||||
var_dump($response['body']);
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
|
||||
Reference in New Issue
Block a user