PHP code example of juzaweb / laravel-hls-converter

1. Go to this page and download the library: Download juzaweb/laravel-hls-converter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juzaweb / laravel-hls-converter example snippets


use Juzaweb\HLSConverter\HLSConverter;

$input = storage_path('app/videos/sample.mp4');
$output = storage_path('app/hls/single');

app(HLSConverter::class)->convert($input, $output);

use Juzaweb\HLSConverter\HLSConverter;

$input = storage_path('app/videos/sample.mp4');
$output = storage_path('app/hls/multi');

$resolutions = [
    '360p' => ['w' => 640,  'h' => 360,  'bitrate' => '800k'],
    '480p' => ['w' => 854,  'h' => 480,  'bitrate' => '1200k'],
    '720p' => ['w' => 1280, 'h' => 720,  'bitrate' => '2500k'],
];

app(HLSConverter::class)->convert($input, $output, $resolutions);

use Juzaweb\HLSConverter\HLSConverter;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ConvertVideoToHLSJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 3;

    public $timeout = 120;

    public function __construct(
        protected string $input,
        protected string $output,
        protected ?array $resolutions = null
    ) {}

    public function handle()
    {
        app(HLSConverter::class)->convert($this->input, $this->output, $this->resolutions);
    }
}