diff --git a/.rubocop.yml b/.rubocop.yml index 39b073f..c593b11 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,3 +37,6 @@ Style/ArgumentsForwarding: Style/FloatDivision: Enabled: false + +Style/SafeNavigationChainLength: + Enabled: false diff --git a/CHANGELOG b/CHANGELOG index 524f211..444befc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +== 6.1.2 2024-11-07 +Fixes: +* Calculate rotation correctly for media files with multiple side data elements + == 6.1.1 2024-11-04 Fixes: diff --git a/lib/ffmpeg/stream.rb b/lib/ffmpeg/stream.rb index 96424f1..49965d9 100644 --- a/lib/ffmpeg/stream.rb +++ b/lib/ffmpeg/stream.rb @@ -44,12 +44,18 @@ def initialize(metadata, stderr = '') @coded_height = metadata[:coded_height] @sample_aspect_ratio = metadata[:sample_aspect_ratio] @display_aspect_ratio = metadata[:display_aspect_ratio] - @rotation = if metadata[:tags]&.key?(:rotate) - metadata[:tags][:rotate].to_i - elsif metadata[:side_data_list]&.first&.key?(:rotation) - rotation = metadata[:side_data_list].first[:rotation].to_i - rotation.positive? ? 360 - rotation : rotation.abs - end + + @rotation = + if metadata.dig(:tags, :rotate) + metadata.dig(:tags, :rotate).to_i + else + metadata[:side_data_list] + &.find { |data| data[:side_data_type] =~ /display matrix/i } + &.dig(:rotation) + &.to_i + &.tap { |value| break value + 180 if value % 180 != 0 } + &.abs + end @color_range = metadata[:color_range] @color_space = metadata[:pix_fmt] || metadata[:color_space] diff --git a/lib/ffmpeg/version.rb b/lib/ffmpeg/version.rb index 1d2d847..a91a498 100644 --- a/lib/ffmpeg/version.rb +++ b/lib/ffmpeg/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module FFMPEG - VERSION = '6.1.1' + VERSION = '6.1.2' end