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.
- data/lib/paperclip-ffmpeg.rb +24 -23
- data/paperclip-ffmpeg.gemspec +1 -1
- metadata +2 -2
data/lib/paperclip-ffmpeg.rb
CHANGED
@@ -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
|
-
:
|
15
|
-
:
|
16
|
-
:ar => 44100,
|
17
|
-
:b => '1200k',
|
18
|
-
:deinterlace => nil,
|
19
|
-
:r => 25,
|
20
|
-
:y => nil,
|
14
|
+
:input => {},
|
15
|
+
:output => { :y => nil }
|
21
16
|
}
|
22
|
-
|
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[:
|
105
|
-
@convert_options[:
|
106
|
-
@convert_options[:
|
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[:
|
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
|
-
|
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}
|
123
|
+
raise PaperclipError, "error while processing video for #{@basename}: #{e}" if @whiny
|
123
124
|
end
|
124
125
|
|
125
126
|
dst
|
data/paperclip-ffmpeg.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: paperclip-ffmpeg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
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-
|
13
|
+
date: 2011-07-17 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|