From 7d4df5917e267fe076c36077c20ac31a5b0db983 Mon Sep 17 00:00:00 2001 From: Nowaker Date: Sat, 23 Sep 2023 04:46:49 -0500 Subject: [PATCH 1/2] Dimensions: support for rotation inside side_data_list --- lib/ffmpeg/movie.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ffmpeg/movie.rb b/lib/ffmpeg/movie.rb index 0e148bb3..954f81d2 100644 --- a/lib/ffmpeg/movie.rb +++ b/lib/ffmpeg/movie.rb @@ -95,6 +95,9 @@ def initialize(path) @rotation = if video_stream.key?(:tags) and video_stream[:tags].key?(:rotate) video_stream[:tags][:rotate].to_i + elsif video_stream.key?(:side_data_list) + rotation_data = video_stream[:side_data_list].find { |data| data.key?(:rotation) } + rotation_data ? rotation_data[:rotation].to_i : nil else nil end From 8f540c2e6539b20230ad5c35296b0512ca6ca31f Mon Sep 17 00:00:00 2001 From: Nowaker Date: Thu, 7 Dec 2023 10:39:16 -0600 Subject: [PATCH 2/2] Dimensions: interpret rotation correctly for width and height --- lib/ffmpeg/movie.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ffmpeg/movie.rb b/lib/ffmpeg/movie.rb index 954f81d2..89006093 100644 --- a/lib/ffmpeg/movie.rb +++ b/lib/ffmpeg/movie.rb @@ -159,11 +159,17 @@ def local? end def width - rotation.nil? || rotation == 180 ? @width : @height; + return @width if rotation.nil? + + normalized_rotation = rotation % 360 + normalized_rotation == 180 || normalized_rotation == 0 ? @width : @height end def height - rotation.nil? || rotation == 180 ? @height : @width; + return @height if rotation.nil? + + normalized_rotation = rotation % 360 + normalized_rotation == 180 || normalized_rotation == 0 ? @height : @width end def resolution