Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…verter into main
  • Loading branch information
chrisbbreuer committed Mar 14, 2021
2 parents 9c9bb76 + e227688 commit c698d72
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -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;}}}
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;}}}
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

'settings' => [
'OutputGroups' => [
// thumbnail generation
// first thumbnails for sprite generation
[
'CustomName' => 'Thumbnails',
'Name' => 'File Group',
Expand Down Expand Up @@ -114,7 +114,7 @@
],
],

// optimize mp4 output setting
// third mp4
[
'CustomName' => 'MP4',
'Name' => 'File Group',
Expand Down
5 changes: 1 addition & 4 deletions tests/MediaConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
100 changes: 3 additions & 97 deletions tests/MediaConverterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
168 changes: 168 additions & 0 deletions tests/config/job.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit c698d72

Please sign in to comment.