koel/app/Services/Streamer/Adapters/TranscodingStreamerAdapter.php

24 lines
705 B
PHP
Raw Normal View History

2024-02-24 07:28:49 +00:00
<?php
namespace App\Services\Streamer\Adapters;
use App\Models\Song;
use App\Services\Streamer\Adapters\Concerns\StreamsLocalPath;
use App\Values\TranscodeResult;
2024-02-24 07:28:49 +00:00
use Illuminate\Support\Arr;
class TranscodingStreamerAdapter implements StreamerAdapter
{
use StreamsLocalPath;
2024-02-24 07:28:49 +00:00
public function stream(Song $song, array $config = []): void
{
abort_unless(is_executable(config('koel.streaming.ffmpeg_path')), 500, 'ffmpeg not found or not executable.');
2024-02-24 07:28:49 +00:00
$bitRate = filter_var(Arr::get($config, 'bit_rate'), FILTER_SANITIZE_NUMBER_INT)
?: config('koel.streaming.bitrate');
$this->streamLocalPath(TranscodeResult::getForSong($song, $bitRate)->path);
2024-02-24 07:28:49 +00:00
}
}