Skip to content

Commit

Permalink
Merge pull request #7 from instructure/fix/rotation
Browse files Browse the repository at this point in the history
fix: rotation is not calculated for media with multiple side data elements
  • Loading branch information
bajankristof authored Nov 8, 2024
2 parents 424e251 + 87113bb commit a3404b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ Style/ArgumentsForwarding:

Style/FloatDivision:
Enabled: false

Style/SafeNavigationChainLength:
Enabled: false
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
18 changes: 12 additions & 6 deletions lib/ffmpeg/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/ffmpeg/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module FFMPEG
VERSION = '6.1.1'
VERSION = '6.1.2'
end

0 comments on commit a3404b8

Please sign in to comment.