Skip to content

Commit

Permalink
Merge pull request #30 from ChrisToxz/feat/VideoHelper_Settings_in_Job
Browse files Browse the repository at this point in the history
feat: Use VideoHelper in CreateSlip job
  • Loading branch information
ChrisToxz authored Jul 12, 2023
2 parents 0205bc3 + a8d2606 commit 9220073
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
33 changes: 33 additions & 0 deletions app/Helpers/VideoHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Helpers;

use App\Settings\GeneralSettings;

class VideoHelper
{

public static function getSupportedFormats()
{

$qualities = [
2160 => [3840, 2160],
1440 => [2560, 1440],
1080 => [1920, 1080],
720 => [1280, 720],
480 => [854, 480],
360 => [640, 360],
];

$collection = collect($qualities)->map(function ($value, $key) {
return (object)[
'resolution' => $key,
'height' => $value[1],
'width' => $value[0],
'bitrate' => app(GeneralSettings::class)->streaming_bitrates[$key]
];
});
return $collection;
}

}
23 changes: 8 additions & 15 deletions app/Jobs/CreateSlip.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ public function handle(): void
case VideoType::HLS:
$output->writeln("Running HLS Process");

// TODO: Config or so
$qualities = [
2160 => [3840, 2160, 4000],
1440 => [2560, 1440, 3000],
1080 => [1920, 1080, 2000],
720 => [1280, 720, 1000],
480 => [854, 480, 750],
360 => [640, 360, 500],
];

$ff = FFMpeg::fromDisk('local')
->open($this->tmpPath)
Expand All @@ -106,12 +97,14 @@ public function handle(): void
});


foreach ($qualities as $quality) {
// if ($ff->getVideoStream()->get('height') >= $quality[1]) {
$ff->addFormat((new X264('libmp3lame', 'libx264'))->setKiloBitrate($quality[2]), function ($media) use ($quality) {
$media->scale($quality[0], $quality[1]);
});
// }
foreach (\VideoHelper::getSupportedFormats() as $key => $quality) {

if ($ff->getVideoStream()->get('height') >= $quality->height) {
$output->writeln("Quality: {$key} - {$quality->width}x{$quality->height}");
$ff->addFormat((new X264('libmp3lame', 'libx264'))->setKiloBitrate($quality->bitrate), function ($media) use ($quality) {
$media->scale($quality->width, $quality->height);
});
}
}

$ff->useSegmentFilenameGenerator(function ($name, $format, $key, callable $segments, callable $playlist) {
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
*/

'aliases' => Facade::defaultAliases()->merge([
// 'Example' => App\Facades\Example::class,
'VideoHelper' => App\Helpers\VideoHelper::class
])->toArray(),

];

0 comments on commit 9220073

Please sign in to comment.