在Laravel中获取视频长度 [英] Getting video lengths in Laravel
问题描述
有人知道您如何在laravel中获得视频长度(最好是在验证器中)吗?
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.
谢谢.
推荐答案
Laravel 本身不支持视频长度,但您可以扩展验证功能来创建自己的规则.但是您需要依靠一个库来确定视频长度:
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.
ID3库可能可以提供帮助.
这篇关于在Laravel中获取视频长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!