Reputation: 109
Does anyone know how you get get video lengths in laravel (preferably in the validator)?
I know its possible to check for video extension and the file size but I want to get the actual length of the video too.
Thank you.
Upvotes: 0
Views: 2919
Reputation: 3
With using ID3 library
$getID3 = new \getID3;
$file = $getID3->analyze($video_path);
$duration = date('H:i:s.v', $file['playtime_seconds']);
Upvotes: 0
Reputation: 15457
Laravel doesn't support video length natively, but you can extend the Validation functionality to create your own rule. But you'll need to rely on a library to determine the video length:
// Rule
$rules = [
'video' => 'required|file|video_length:5000',
];
// Custom validation rule
Validator::extend('video_length', function( $attribute, $value, $parameters ) {
$length = 0; // check length using library
return $length <= $parameters[0];
});
You'll need to upload the video to your server. Check the length of the video using the library of your choice and return error if it exceeds your restrictions.
The ID3 library may be able to help.
Upvotes: 2