diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 87145e4..f13e84a 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":350:{a:2:{s:7:"defects";a:1:{s:88:"/Users/glenn/Documents/Projects/laravel-media-converter/tests/MediaConverterTest.php::it";i:5;}s:5:"times";a:2:{s:88:"/Users/glenn/Documents/Projects/laravel-media-converter/tests/MediaConverterTest.php::it";d:2.233;s:86:"/Users/glenn/Documents/Projects/laravel-media-converter/tests/ExampleTest.php::example";d:0.029;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":349:{a:2:{s:7:"defects";a:1:{s:88:"/Users/glenn/Documents/Projects/laravel-media-converter/tests/MediaConverterTest.php::it";i:4;}s:5:"times";a:2:{s:88:"/Users/glenn/Documents/Projects/laravel-media-converter/tests/MediaConverterTest.php::it";d:1.83;s:86:"/Users/glenn/Documents/Projects/laravel-media-converter/tests/ExampleTest.php::example";d:0.029;}}} \ No newline at end of file diff --git a/config/config.php b/config/config.php index 949f1a2..a023a0a 100644 --- a/config/config.php +++ b/config/config.php @@ -67,7 +67,7 @@ 'settings' => [ 'OutputGroups' => [ - // thumbnail generation + // first thumbnails for sprite generation [ 'CustomName' => 'Thumbnails', 'Name' => 'File Group', @@ -114,7 +114,7 @@ ], ], - // optimize mp4 output setting + // third mp4 [ 'CustomName' => 'MP4', 'Name' => 'File Group', diff --git a/tests/MediaConverterTest.php b/tests/MediaConverterTest.php index dfadcfc..dd85274 100644 --- a/tests/MediaConverterTest.php +++ b/tests/MediaConverterTest.php @@ -4,10 +4,7 @@ beforeEach(function () { $this->initializeDotEnv(); - $this->setDestination(); - $this->setFileInput(); - $this->setQvbrSettings(); - $this->setSpriteImageSettings(); + $this->initializeSettings(); }); it('it can successfully initialize settings', function () { diff --git a/tests/MediaConverterTestCase.php b/tests/MediaConverterTestCase.php index 10cbf86..6acf688 100644 --- a/tests/MediaConverterTestCase.php +++ b/tests/MediaConverterTestCase.php @@ -22,104 +22,10 @@ public function initializeDotEnv() $dotenv->load(); } - public function setDestination() + public function initializeSettings() { - $config = config('media-converter.settings'); - $this->settings = $config; + $configFile = file_get_contents(__DIR__.'/config/job.json'); - $destination = 's3://meema-stage/'; - - $this->settings['OutputGroups'][0]['OutputGroupSettings']['FileGroupSettings']['Destination'] = $destination.'/thumbnails/'; - $this->settings['OutputGroups'][1]['OutputGroupSettings']['HlsGroupSettings']['Destination'] = $destination.'/hls/'; - $this->settings['OutputGroups'][2]['OutputGroupSettings']['FileGroupSettings']['Destination'] = $destination.'/mp4/'; - } - - public function setFileInput() - { - $fileDestination = 's3://meema-stage/test-me.mp4'; - - $this->settings['Inputs'][0]['FileInput'] = $fileDestination; - } - - /** - * @see https://docs.aws.amazon.com/mediaconvert/latest/ug/cbr-vbr-qvbr.html?icmpid=docs_mediaconvert_errormsg - */ - public function setQvbrSettings() - { - $this->sizes = [ - 'width' => 1024, - 'height' => 768, - ]; - - $height = $this->sizes['height'] ?? 721; // default to a medium bitrate - - if ($height > 1080) { - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['MaxBitrate'] = 6000000; - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['QvbrSettings']['QvbrQualityLevel'] = 9; - - return; - } - - if ($height > 720) { - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['MaxBitrate'] = 2000000; - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['QvbrSettings']['QvbrQualityLevel'] = 7; - - return; - } - - if ($height > 480) { - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['MaxBitrate'] = 1000000; - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['QvbrSettings']['QvbrQualityLevel'] = 7; - - return; - } - - if ($height > 360) { - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['MaxBitrate'] = 700000; - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['QvbrSettings']['QvbrQualityLevel'] = 7; - - return; - } - - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['MaxBitrate'] = 350000; - $this->settings['OutputGroups'][2]['Outputs'][0]['VideoDescription']['CodecSettings']['H264Settings']['QvbrSettings']['QvbrQualityLevel'] = 7; - } - - /** - * @see https://aws.amazon.com/blogs/media/create-a-poster-frame-and-thumbnail-images-for-videos-using-aws-elemental-mediaconvert/ - */ - public function setSpriteImageSettings() - { - $framesToBeCaptured = $this->getFramesToBeCaptured(); - $totalFrameCount = 500; - $fps = 24; - - $this->settings['OutputGroups'][0]['Outputs'][0]['VideoDescription']['CodecSettings']['FrameCaptureSettings'] = [ - 'FramerateNumerator' => $fps, - 'FramerateDenominator' => ceil($totalFrameCount / $framesToBeCaptured), - 'MaxCaptures' => $framesToBeCaptured, - 'Quality' => 80, - ]; - - // Netflix, Disney Plus and other big streaming platforms use 240px width for the thumbnails within the sprite - $this->settings['OutputGroups'][0]['Outputs'][0]['VideoDescription']['Width'] = 240; - } - - protected function getFramesToBeCaptured() - { - $totalFrameCount = 500; - $defaultAmountOfFrames = 250; // technically, we could also name this variable $minAmountOfFrames - $durationInSeconds = 60; - $framesToBeCaptured = 500; - - if ($framesToBeCaptured > $defaultAmountOfFrames) { - return $framesToBeCaptured; - } - - if ($framesToBeCaptured > $totalFrameCount) { - return $totalFrameCount; - } - - return $defaultAmountOfFrames; + $this->settings = json_decode($configFile, true); } } diff --git a/tests/config/job.json b/tests/config/job.json new file mode 100644 index 0000000..3daadc8 --- /dev/null +++ b/tests/config/job.json @@ -0,0 +1,168 @@ +{ + "OutputGroups":[ + { + "CustomName":"Thumbnails", + "Name":"File Group", + "Outputs":[ + { + "ContainerSettings":{ + "Container":"RAW" + }, + "VideoDescription":{ + "ScalingBehavior":"DEFAULT", + "TimecodeInsertion":"DISABLED", + "AntiAlias":"ENABLED", + "Sharpness":50, + "CodecSettings":{ + "Codec":"FRAME_CAPTURE", + "FrameCaptureSettings":{ + "FramerateNumerator":30, + "FramerateDenominator":60, + "MaxCaptures":3, + "Quality":80 + } + }, + "AfdSignaling":"NONE", + "DropFrameTimecode":"ENABLED", + "RespondToAfd":"NONE", + "ColorMetadata":"INSERT", + "Width":240 + }, + "NameModifier":".$w$x$h$" + } + ], + "OutputGroupSettings":{ + "Type":"FILE_GROUP_SETTINGS", + "FileGroupSettings":{ + "Destination":"s3:\/\/meema-stage\/\/thumbnails\/", + "DestinationSettings":{ + "S3Settings":{ + "AccessControl":{ + "CannedAcl":"PUBLIC_READ" + } + } + } + } + } + }, + { + "CustomName":"MP4", + "Name":"File Group", + "Outputs":[ + { + "ContainerSettings":{ + "Container":"MP4", + "Mp4Settings":{ + "CslgAtom":"INCLUDE", + "FreeSpaceBox":"EXCLUDE", + "MoovPlacement":"PROGRESSIVE_DOWNLOAD" + } + }, + "VideoDescription":{ + "ScalingBehavior":"DEFAULT", + "TimecodeInsertion":"DISABLED", + "AntiAlias":"ENABLED", + "Sharpness":50, + "CodecSettings":{ + "Codec":"H_264", + "H264Settings":{ + "InterlaceMode":"PROGRESSIVE", + "NumberReferenceFrames":3, + "Syntax":"DEFAULT", + "Softness":0, + "GopClosedCadence":1, + "GopSize":90, + "Slices":1, + "GopBReference":"DISABLED", + "MaxBitrate":8000000, + "SlowPal":"DISABLED", + "SpatialAdaptiveQuantization":"ENABLED", + "TemporalAdaptiveQuantization":"ENABLED", + "FlickerAdaptiveQuantization":"DISABLED", + "EntropyEncoding":"CABAC", + "FramerateControl":"INITIALIZE_FROM_SOURCE", + "RateControlMode":"QVBR", + "QvbrSettings":{ + "QvbrQualityLevel":7, + "QvbrQualityLevelFineTune":0 + }, + "CodecProfile":"MAIN", + "Telecine":"NONE", + "MinIInterval":0, + "AdaptiveQuantization":"HIGH", + "CodecLevel":"AUTO", + "FieldEncoding":"PAFF", + "SceneChangeDetect":"ENABLED", + "QualityTuningLevel":"SINGLE_PASS", + "FramerateConversionAlgorithm":"DUPLICATE_DROP", + "UnregisteredSeiTimecode":"DISABLED", + "GopSizeUnits":"FRAMES", + "ParControl":"INITIALIZE_FROM_SOURCE", + "NumberBFramesBetweenReferenceFrames":2, + "RepeatPps":"DISABLED" + } + }, + "AfdSignaling":"NONE", + "DropFrameTimecode":"ENABLED", + "RespondToAfd":"NONE", + "ColorMetadata":"INSERT" + }, + "AudioDescriptions":[ + { + "AudioTypeControl":"FOLLOW_INPUT", + "CodecSettings":{ + "Codec":"AAC", + "AacSettings":{ + "AudioDescriptionBroadcasterMix":"NORMAL", + "Bitrate":96000, + "RateControlMode":"CBR", + "CodecProfile":"LC", + "CodingMode":"CODING_MODE_2_0", + "RawFormat":"NONE", + "SampleRate":48000, + "Specification":"MPEG4" + } + }, + "LanguageCodeControl":"FOLLOW_INPUT" + } + ] + } + ], + "OutputGroupSettings":{ + "Type":"FILE_GROUP_SETTINGS", + "FileGroupSettings":{ + "Destination":"s3:\/\/meema-stage\/\/mp4\/", + "DestinationSettings":{ + "S3Settings":{ + "AccessControl":{ + "CannedAcl":"PUBLIC_READ" + } + } + } + } + } + } + ], + "AdAvailOffset":0, + "Inputs":[ + { + "AudioSelectors":{ + "Audio Selector 1":{ + "Offset":0, + "DefaultSelection":"DEFAULT", + "ProgramSelection":1 + } + }, + "VideoSelector":{ + "ColorSpace":"FOLLOW" + }, + "FilterEnable":"AUTO", + "PsiControl":"USE_PSI", + "FilterStrength":0, + "DeblockFilter":"DISABLED", + "DenoiseFilter":"DISABLED", + "TimecodeSource":"EMBEDDED", + "FileInput":"s3:\/\/meema-stage\/test-me.mp4" + } + ] + }