Added MUX mp4 support

Change-Id: I886aa7c211b28bc3c506bc180d6b7ca24382fa89
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2020-10-29 09:14:09 -03:00
parent 395ee0add9
commit 49ccaa19c5
4 changed files with 120 additions and 16 deletions

@ -0,0 +1,57 @@
<?php namespace App\Console\Commands;
/**
* Copyright 2020 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\Model\IPresentationVideoMediaUploadProcessor;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
/**
* Class EnableMP4SupportAtMUXCommand
* @package App\Console\Commands
*/
class EnableMP4SupportAtMUXCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'summit:enable-mp4-support-mux';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'summit:enable-mp4-support-mux {event_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enable MP4 Support at Mux';
/**
* @param IPresentationVideoMediaUploadProcessor $service
*/
public function handle(IPresentationVideoMediaUploadProcessor $service)
{
$event_id = $this->argument('event_id');
if(empty($event_id))
throw new \InvalidArgumentException("event_id is required");
$service->enableMP4Support(intval($event_id));
}
}

@ -45,6 +45,7 @@ class Kernel extends ConsoleKernel
\App\Console\Commands\SummitEmailFlowTypeSeederCommand::class,
\App\Console\Commands\PresentationMaterialsCreateMUXAssetsCommand::class,
\App\Console\Commands\RecalculateAttendeesStatusCommand::class,
\App\Console\Commands\EnableMP4SupportAtMUXCommand::class,
];
/**

@ -32,4 +32,9 @@ interface IPresentationVideoMediaUploadProcessor
* @return bool
*/
public function processEvent(int $event_id, ?string $mountingFolder):bool;
/**
* @param int $event_id
*/
public function enableMP4Support(int $event_id):void;
}

@ -28,6 +28,8 @@ use GuzzleHttp\Client as GuzzleHttpClient;
use MuxPhp\Models\InputSettings as MuxInputSettings;
use MuxPhp\Models\CreateAssetRequest as MuxCreateAssetRequest;
use MuxPhp\Models\PlaybackPolicy as MuxPlaybackPolicy;
use MuxPhp\Models\UpdateAssetMP4SupportRequest as MuxUpdateAssetMP4SupportRequest;
/**
* Class PresentationVideoMediaUploadProcessor
* @package App\Services\Model\Imp
@ -65,10 +67,10 @@ final class PresentationVideoMediaUploadProcessor
$mux_user = Config::get("mux.user", null);
$mux_password = Config::get("mux.password", null);
if(empty($mux_user)){
if (empty($mux_user)) {
throw new \InvalidArgumentException("missing setting mux.user");
}
if(empty($mux_password)){
if (empty($mux_password)) {
throw new \InvalidArgumentException("missing setting mux.password");
}
@ -93,11 +95,11 @@ final class PresentationVideoMediaUploadProcessor
public function processPublishedPresentationFor(int $summit_id, ?string $mountingFolder = null): int
{
Log::debug(sprintf("PresentationVideoMediaUploadProcessor::processPublishedPresentationFor summit id %s mountingFolder %s", $summit_id, $mountingFolder));
$event_ids = $this->tx_service->transaction(function() use($summit_id){
$event_ids = $this->tx_service->transaction(function () use ($summit_id) {
return $this->event_repository->getPublishedEventsIdsBySummit($summit_id);
});
foreach($event_ids as $event_id){
foreach ($event_ids as $event_id) {
Log::warning(sprintf("PresentationVideoMediaUploadProcessor::processPublishedPresentationFor processing event %s", $event_id));
$this->processEvent(intval($event_id), $mountingFolder);
}
@ -110,7 +112,8 @@ final class PresentationVideoMediaUploadProcessor
* @param string|null $mountingFolder
* @return bool
*/
public function processEvent(int $event_id, ?string $mountingFolder):bool{
public function processEvent(int $event_id, ?string $mountingFolder): bool
{
try {
return $this->tx_service->transaction(function () use ($event_id, $mountingFolder) {
try {
@ -120,23 +123,23 @@ final class PresentationVideoMediaUploadProcessor
return false;
}
if(!$event->isPublished()){
if (!$event->isPublished()) {
Log::warning(sprintf("PresentationVideoMediaUploadProcessor::processEvent event %s not published", $event_id));
return false;
}
Log::debug(sprintf("PresentationVideoMediaUploadProcessor::processEvent processing event %s (%s)", $event->getTitle(), $event_id));
if(!empty($event->getMuxAssetId())){
if (!empty($event->getMuxAssetId())) {
Log::warning(sprintf("PresentationVideoMediaUploadProcessor::processEvent event %s already has assigned an asset id %s", $event_id, $event->getMuxAssetId()));
return false;
}
$has_video = false;
foreach($event->getMediaUploads() as $mediaUpload){
foreach ($event->getMediaUploads() as $mediaUpload) {
if($mediaUpload->getMediaUploadType()->isVideo()){
if($has_video){
if ($mediaUpload->getMediaUploadType()->isVideo()) {
if ($has_video) {
Log::warning(sprintf("PresentationVideoMediaUploadProcessor::processEvent event %s processing media upload %s (%s) already has a video processed!.", $event_id, $mediaUpload->getId(), $mediaUpload->getFilename()));
continue;
}
@ -147,9 +150,8 @@ final class PresentationVideoMediaUploadProcessor
if (!is_null($strategy)) {
$relativePath = $mediaUpload->getRelativePath(IStorageTypesConstants::PrivateType, $mountingFolder);
Log::debug(sprintf("PresentationVideoMediaUploadProcessor::processEvent event %s processing media upload %s relativePath %s", $event_id, $mediaUpload->getId(), $relativePath));
$assetUrl = $strategy->getUrl($relativePath);
if($assetUrl == '#')
{
$assetUrl = $strategy->getUrl($relativePath);
if ($assetUrl == '#') {
Log::debug(sprintf("PresentationVideoMediaUploadProcessor::processEvent event %s processing media upload %s got asset url %s is not valid", $event_id, $mediaUpload->getId(), $assetUrl));
return false;
}
@ -157,7 +159,7 @@ final class PresentationVideoMediaUploadProcessor
// Create Asset Request
$input = new MuxInputSettings(["url" => $assetUrl]);
$createAssetRequest = new MuxCreateAssetRequest(["input" => $input, "playback_policy" => [MuxPlaybackPolicy::PUBLIC_PLAYBACK_POLICY] ]);
$createAssetRequest = new MuxCreateAssetRequest(["input" => $input, "playback_policy" => [MuxPlaybackPolicy::PUBLIC_PLAYBACK_POLICY]]);
// Ingest
$result = $this->assets_api->createAsset($createAssetRequest);
@ -179,10 +181,49 @@ final class PresentationVideoMediaUploadProcessor
}
return true;
});
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
Log::error($ex);
return false;
}
}
/**
* @param int $event_id
* @throws \Exception
*/
public function enableMP4Support(int $event_id): void
{
$this->tx_service->transaction(function () use ($event_id) {
$event = $this->event_repository->getByIdExclusiveLock($event_id);
if (is_null($event) || !$event instanceof Presentation) {
Log::warning(sprintf("PresentationVideoMediaUploadProcessor::enableMP4Support event %s not found", $event_id));
return;
}
if (!$event->isPublished()) {
Log::warning(sprintf("PresentationVideoMediaUploadProcessor::enableMP4Support event %s not published", $event_id));
return;
}
Log::debug(sprintf("PresentationVideoMediaUploadProcessor::enableMP4Support processing event %s (%s)", $event->getTitle(), $event_id));
$assetId = $event->getMuxAssetId();
if (empty($assetId)) {
// try to get from stream url
$streamUrl = $event->getStreamingUrl();
if(preg_match('/https\:\/\/stream\.mux\.com\/(.*)\.m3u8/', $streamUrl, $re)){
$playbackId = $re[1];
$this->assets_api->getAssetPlaybackId()
}
if(empty($assetId)){
Log::warning(sprintf("PresentationVideoMediaUploadProcessor::enableMP4Support event %s asset id is empty", $event_id));
return;
}
}
$request = new MuxUpdateAssetMP4SupportRequest(['mp4_support' => MuxUpdateAssetMP4SupportRequest::MP4_SUPPORT_STANDARD]);
$result = $this->assets_api->updateAssetMp4Support($assetId, $request);
Log::debug(sprintf("PresentationVideoMediaUploadProcessor::enableMP4Support event %s enable mp4 support response %s", $event_id, json_encode($result)));
});
}
}