Skip to content

Instantly share code, notes, and snippets.

@elizov
Last active June 11, 2022 05:56
Show Gist options
  • Save elizov/6b030923a179d6a72758c0eae674a680 to your computer and use it in GitHub Desktop.
Save elizov/6b030923a179d6a72758c0eae674a680 to your computer and use it in GitHub Desktop.
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use FFMpeg\FFMpeg;
class MaxVideoBitRate implements Rule
{
protected $maxBitRate;
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct(int $maxBitRate)
{
$this->maxBitRate = $maxBitRate;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$video = FFMpeg::create()->open($value->getRealPath());
$videoInfo = $video->getStreams()->videos()->first();
return $this->maxBitRate >= $videoInfo->get('bit_rate');
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Exceeded the maximum allowed bitrate value.';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment