minuteoflaravel / laravel-audio-video-validator
Laravel 视频和音频文件验证器
1.1
2022-06-15 19:20 UTC
Requires
- php: ^7.4|^8.0|^8.1
- pbmedia/laravel-ffmpeg: ^7.0|^8.0
README
此包为您的 Laravel 项目添加音频和视频文件的验证器。
安装
要使用此包,您应该安装 ffmpeg 多媒体框架
- 在 Debian/Ubuntu 上,运行
sudo apt install ffmpeg
- 在 macOS 上使用 Homebrew:
brew install ffmpeg
之后,通过 composer 安装此包
composer require minuteoflaravel/laravel-audio-video-validator
验证器
包添加以下验证器
- audio
- video
- codec
- duration
- duration_max
- duration_min
- video_width
- video_height
- video_max_width
- video_max_height
- video_min_width
- video_min_height
自定义错误消息
如果您需要添加自定义可翻译的错误消息,只需像往常一样将它们添加到 resources/lang/en/validation.php 文件中即可
'audio' => 'The :attribute must be a audio.', 'video' => 'The :attribute must be a video.', 'codec' => 'The :attribute codec must be one of these: :codec', 'duration' => 'The :attribute must be :duration seconds duration.', 'duration_max' => 'The :attribute duration must be less than :duration_max seconds.', 'duration_min' => 'The :attribute duration must be greater than :duration_min seconds.', 'video_width' => 'The :attribute width must be :video_width.', 'video_height' => 'The :attribute height must be :video_height.', 'video_max_width' => 'The :attribute width must be less than :video_max_width.', 'video_min_width' => 'The :attribute width must be greater than :video_min_width.', 'video_min_height' => 'The :attribute height must be greater than :video_min_height.',
一些示例
检查文件是否为音频文件且音频时长为 60 秒
$request->validate([ 'audio' => 'audio|duration:60', ]);
检查文件是否为音频文件且音频时长在 30 到 300 秒之间
$request->validate([ 'audio' => 'audio|duration_min:30|duration_max:300', ]);
检查文件是否为视频文件且视频时长在 30 到 300 秒之间
$request->validate([ 'video' => 'video|duration_min:30|duration_max:300', ]);
检查文件是否为视频文件且视频尺寸为 1000x640
$request->validate([ 'video' => 'video|video_width:1000|video_height:640', ]);
检查文件是否为视频文件且视频尺寸大于 1000x640
$request->validate([ 'video' => 'video|video_min_width:1000|video_min_height:640', ]);
检查文件是否为音频文件且编解码器为 mp3 或 pcm_s16le(wav)
$request->validate([ 'audio' => 'audio|codec:mp3,pcm_s16le', ]);
检查文件是否为视频文件且编解码器为 h264(mp4)
$request->validate([ 'video' => 'video|codec:h264', ]);
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 获取更多信息。