Active Storage 视频分析器¶ ↑
从视频 blob 中提取以下信息
-
宽度(像素)
-
高度(像素)
-
时长(秒)
-
角度(度)
-
显示宽高比
-
音频(如果文件包含音频通道,则为 true,否则为 false)
-
视频(如果文件包含视频通道,则为 true,否则为 false)
示例
ActiveStorage::Analyzer::VideoAnalyzer.new(blob).metadata # => { width: 640.0, height: 480.0, duration: 5.0, angle: 0, display_aspect_ratio: [4, 3], audio: true, video: true }
当视频的角度为 90、-90、270 或 -270 度时,其宽度和高度会自动交换,以方便使用。
此分析器需要 FFmpeg 系统库,该库不随 Rails 提供。
方法
类公共方法
accept?(blob) 链接
来源: 显示 | 在 GitHub 上
# File activestorage/lib/active_storage/analyzer/video_analyzer.rb, line 25 def self.accept?(blob) blob.video? end
实例公共方法
metadata() 链接
来源: 显示 | 在 GitHub 上
# File activestorage/lib/active_storage/analyzer/video_analyzer.rb, line 29 def metadata { width: width, height: height, duration: duration, angle: angle, display_aspect_ratio: display_aspect_ratio, audio: audio?, video: video? }.compact end