From 1a281580243cc51500de6b5fd45c77e5efa172d4 Mon Sep 17 00:00:00 2001 From: jebw Date: Fri, 29 May 2015 19:02:23 +0100 Subject: [PATCH] Added setting rotation metadata --- lib/av/commands/avconv.rb | 2 ++ lib/av/commands/base.rb | 21 +++++++++++++++++++++ lib/av/commands/ffmpeg.rb | 2 ++ spec/av/base_spec.rb | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/lib/av/commands/avconv.rb b/lib/av/commands/avconv.rb index 6620c9c..0bbe4d4 100644 --- a/lib/av/commands/avconv.rb +++ b/lib/av/commands/avconv.rb @@ -30,6 +30,8 @@ def filter_rotate degrees when 270 add_output_param vf: 'cclock' end + + self end end diff --git a/lib/av/commands/base.rb b/lib/av/commands/base.rb index a8c24ea..352cf92 100644 --- a/lib/av/commands/base.rb +++ b/lib/av/commands/base.rb @@ -180,6 +180,27 @@ def parse_param param end list end + + def metadata_rotate degrees + add_output_param :'metadata:s:v:0', "rotate=#{degrees}" + + self + end + + def filter_metadata_rotate degrees + filter_rotate degrees + + if @source + current_rotate = identify(@source)[:rotate] || 0 + else + ::Av.log "Source has not been set - assuming current rotation metadata is 0" + current_rotate = 0 + end + + metadata_rotate (current_rotate - degrees) % 360 + + self + end end end end diff --git a/lib/av/commands/ffmpeg.rb b/lib/av/commands/ffmpeg.rb index a32edeb..0e81917 100644 --- a/lib/av/commands/ffmpeg.rb +++ b/lib/av/commands/ffmpeg.rb @@ -29,6 +29,7 @@ def filter_volume vol def filter_rotate degrees raise ::Av::InvalidFilterParameter unless degrees % 90 == 0 + case degrees when 90 add_output_param vf: 'transpose=1' @@ -37,6 +38,7 @@ def filter_rotate degrees when 270 add_output_param vf: 'transpose=2' end + self end end diff --git a/spec/av/base_spec.rb b/spec/av/base_spec.rb index a5c8805..a137a97 100644 --- a/spec/av/base_spec.rb +++ b/spec/av/base_spec.rb @@ -67,5 +67,23 @@ it { expect { subject.run }.not_to raise_exception } end + + describe '.metadata_rotate' do + before do + subject.metadata_rotate(90) + end + + it { expect(subject.output_params.to_s).to eq '-metadata:s:v:0 rotate=90' } + end + + describe '.filter_metadata_rotate' do + before do + subject.add_source(source) + subject.filter_metadata_rotate(90) + end + + it { expect(subject.output_params.to_s).to match /-metadata:s:v:0 rotate=270/ } + it { expect(subject.output_params.to_s).to match /-vf (clock|transpose=1)/ } + end end