aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib/active_storage/analyzer/video_analyzer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage/lib/active_storage/analyzer/video_analyzer.rb')
-rw-r--r--activestorage/lib/active_storage/analyzer/video_analyzer.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/activestorage/lib/active_storage/analyzer/video_analyzer.rb b/activestorage/lib/active_storage/analyzer/video_analyzer.rb
index 408b5e58e9..1c144baa37 100644
--- a/activestorage/lib/active_storage/analyzer/video_analyzer.rb
+++ b/activestorage/lib/active_storage/analyzer/video_analyzer.rb
@@ -19,6 +19,8 @@ module ActiveStorage
# This analyzer requires the {ffmpeg}[https://www.ffmpeg.org] system library, which is not provided by Rails. You must
# install ffmpeg yourself to use this analyzer.
class Analyzer::VideoAnalyzer < Analyzer
+ class_attribute :ffprobe_path, default: "ffprobe"
+
def self.accept?(blob)
blob.video?
end
@@ -29,10 +31,18 @@ module ActiveStorage
private
def width
- Integer(video_stream["width"]) if video_stream["width"]
+ rotated? ? raw_height : raw_width
end
def height
+ rotated? ? raw_width : raw_height
+ end
+
+ def raw_width
+ Integer(video_stream["width"]) if video_stream["width"]
+ end
+
+ def raw_height
Integer(video_stream["height"]) if video_stream["height"]
end
@@ -50,6 +60,10 @@ module ActiveStorage
end
end
+ def rotated?
+ angle == 90 || angle == 270
+ end
+
def tags
@tags ||= video_stream["tags"] || {}
@@ -68,7 +82,7 @@ module ActiveStorage
end
def probe_from(file)
- IO.popen([ "ffprobe", "-print_format", "json", "-show_streams", "-v", "error", file.path ]) do |output|
+ IO.popen([ ffprobe_path, "-print_format", "json", "-show_streams", "-v", "error", file.path ]) do |output|
JSON.parse(output.read)
end
rescue Errno::ENOENT