paperclip-ffmpeg 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,15 +11,17 @@ module Paperclip
11
11
  # set, the options will be appended to the convert command upon video transcoding
12
12
  def initialize file, options = {}, attachment = nil
13
13
  @convert_options = {
14
- :ab => '64k',
15
- :ac => 2,
16
- :ar => 44100,
17
- :b => '1200k',
18
- :deinterlace => nil,
19
- :r => 25,
20
- :y => nil,
14
+ :input => {},
15
+ :output => { :y => nil }
21
16
  }
22
- @convert_options.reverse_merge! options[:convert_options] unless options[:convert_options].nil? || options[:convert_options].class != Hash
17
+ unless options[:convert_options].nil? || options[:convert_options].class != Hash
18
+ unless options[:convert_options][:input].nil? || options[:convert_options][:input].class != Hash
19
+ @convert_options[:input].reverse_merge! options[:convert_options][:input]
20
+ end
21
+ unless options[:convert_options][:output].nil? || options[:convert_options][:output].class != Hash
22
+ @convert_options[:output].reverse_merge! options[:convert_options][:output]
23
+ end
24
+ end
23
25
 
24
26
  @geometry = options[:geometry]
25
27
  @file = file
@@ -62,7 +64,7 @@ module Paperclip
62
64
  # Keep aspect ratio
63
65
  width = target_width.to_i
64
66
  height = (width.to_f / (@meta[:aspect].to_f)).to_i
65
- @convert_options[:s] = "#{width.to_i}x#{height.to_i}"
67
+ @convert_options[:output][:s] = "#{width.to_i}x#{height.to_i}"
66
68
  else
67
69
  return nil
68
70
  end
@@ -71,7 +73,7 @@ module Paperclip
71
73
  # Keep aspect ratio
72
74
  width = target_width.to_i
73
75
  height = (width.to_f / (@meta[:aspect].to_f)).to_i
74
- @convert_options[:s] = "#{width.to_i}x#{height.to_i}"
76
+ @convert_options[:output][:s] = "#{width.to_i}x#{height.to_i}"
75
77
  else
76
78
  return nil
77
79
  end
@@ -82,44 +84,43 @@ module Paperclip
82
84
  # We should add half the delta as a padding offset Y
83
85
  pad_y = (target_height.to_f - height.to_f) / 2
84
86
  if pad_y > 0
85
- @convert_options[:vf] = "scale=#{width}:-1,pad=#{width.to_i}:#{target_height.to_i}:0:#{pad_y}:black"
87
+ @convert_options[:output][:vf] = "scale=#{width}:-1,pad=#{width.to_i}:#{target_height.to_i}:0:#{pad_y}:black"
86
88
  else
87
- @convert_options[:vf] = "scale=#{width}:-1,crop=#{width.to_i}:#{height.to_i}"
89
+ @convert_options[:output][:vf] = "scale=#{width}:-1,crop=#{width.to_i}:#{height.to_i}"
88
90
  end
89
91
  else
90
92
  # Keep aspect ratio
91
93
  width = target_width.to_i
92
94
  height = (width.to_f / (@meta[:aspect].to_f)).to_i
93
- @convert_options[:s] = "#{width.to_i}x#{height.to_i}"
95
+ @convert_options[:output][:s] = "#{width.to_i}x#{height.to_i}"
94
96
  end
95
97
  else
96
98
  # Do not keep aspect ratio
97
- @convert_options[:s] = "#{target_width.to_i}x#{target_height.to_i}"
99
+ @convert_options[:output][:s] = "#{target_width.to_i}x#{target_height.to_i}"
98
100
  end
99
101
  end
100
102
  end
101
103
  # Add format
102
104
  case @format
103
105
  when 'jpg', 'jpeg', 'png', 'gif' # Images
104
- @convert_options[:f] = 'image2'
105
- @convert_options[:ss] = @time
106
- @convert_options[:vframes] = 1
106
+ @convert_options[:input][:ss] = @time
107
+ @convert_options[:input][:vframes] = 1
108
+ @convert_options[:output][:f] = 'image2'
107
109
  end
108
110
 
109
111
  # Add source
110
- @convert_options[:i] = ':source'
111
-
112
- parameters << @convert_options.map { |k,v| "-#{k.to_s} #{v} "}
112
+ parameters << @convert_options[:input].map { |k,v| "-#{k.to_s} #{v} "}
113
+ parameters << "-i :source"
114
+ parameters << @convert_options[:output].map { |k,v| "-#{k.to_s} #{v} "}
113
115
  parameters << ":dest"
114
116
 
115
117
  parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
116
118
 
117
- puts "ffmpeg #{parameters}"
119
+ Paperclip.log("[paperclip][ffmpeg] #{parameters}")
118
120
  begin
119
121
  success = Paperclip.run("ffmpeg", parameters, :source => "#{File.expand_path(src.path)}", :dest => File.expand_path(dst.path))
120
-
121
122
  rescue Cocaine::ExitStatusError => e
122
- raise PaperclipError, "error while processing video for #{@basename}." if @whiny
123
+ raise PaperclipError, "error while processing video for #{@basename}: #{e}" if @whiny
123
124
  end
124
125
 
125
126
  dst
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "paperclip-ffmpeg"
6
- s.version = '0.6.7'
6
+ s.version = '0.7.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Omar Abdel-Wahab"]
9
9
  s.email = ["owahab@gmail.com"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: paperclip-ffmpeg
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.7
5
+ version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Omar Abdel-Wahab
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-10 00:00:00 +02:00
13
+ date: 2011-07-17 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency