carrierwave-video 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,6 +37,9 @@ Pass in options to process:
37
37
  Resolution passed to ffmpeg:
38
38
  resolution: "640x360"
39
39
 
40
+ If you want to keep the same resolution:
41
+ resolution: :same
42
+
40
43
  Watermark:
41
44
  watermark: {
42
45
  path: File.join(Rails.root, "directory", "file.png"),
@@ -59,6 +62,9 @@ They will be called with the parameters sent to process.
59
62
  Logging:
60
63
  logger: :method #returns object that behaves like Logger
61
64
 
65
+ Custom:
66
+ streamio-ffmpeg accepts custom params. You may pass these in but keep in mind the watermarking params will be appended if there were any.
67
+
62
68
  = OGG/OGV & Theora
63
69
 
64
70
  If you want to transcode to OGV format, I recommend using ffmpeg2theora. It works better.
@@ -25,5 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'streamio-ffmpeg'
26
26
  s.add_runtime_dependency 'carrierwave'
27
27
  s.requirements << 'ruby, version 1.9 or greater'
28
- s.requirements << 'ffmpeg, version 0.10 or greater with libx256, libfaac, libtheora, libvorbid, libvpx enabled'
28
+ s.requirements << 'ffmpeg, version 0.11.1 or greater with libx256, libfaac, libtheora, libvorbid, libvpx enabled'
29
29
  end
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Video
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -49,6 +49,11 @@ module CarrierWave
49
49
 
50
50
  with_trancoding_callbacks do
51
51
  file = ::FFMPEG::Movie.new(current_path)
52
+
53
+ if opts[:resolution] == :same
54
+ @options.format_options[:resolution] = file.resolution
55
+ end
56
+
52
57
  file.transcode(tmp_path, @options.format_options, @options.encoder_options)
53
58
  File.rename tmp_path, current_path
54
59
  end
@@ -2,12 +2,13 @@ module CarrierWave
2
2
  module Video
3
3
  class FfmpegOptions
4
4
  attr_reader :watermark_path, :watermark_position, :watermark_pixels,
5
- :format, :resolution, :callbacks
5
+ :format, :resolution, :custom, :callbacks
6
6
 
7
7
  def initialize(format, options)
8
8
  @format = format.to_s
9
9
  @watermark = options[:watermark].present?
10
10
  @resolution = options[:resolution] || "640x360"
11
+ @custom = options[:custom]
11
12
  @callbacks = options[:callbacks] || {}
12
13
  @logger = options[:logger]
13
14
  @unparsed = options
@@ -32,29 +33,34 @@ module CarrierWave
32
33
  end
33
34
 
34
35
  def format_options
35
- format_options = case format
36
- when "mp4"
37
- {
38
- video_codec: 'libx264',
39
- audio_codec: 'libfaac',
40
- custom: "-qscale 0 -vpre slow -vpre baseline -g 30 #{watermark_params}"
41
- }
42
- when "webm"
43
- {
44
- video_codec: 'libvpx',
45
- audio_codec: 'libvorbis',
46
- custom: "-b 1500k -ab 160000 -f webm -g 30 #{watermark_params}"
47
- }
48
- when "ogv"
49
- {
50
- video_codec: 'libtheora',
51
- audio_codec: 'libvorbis',
52
- custom: "-b 1500k -ab 160000 -g 30 #{watermark_params}"
53
- }
54
- else
55
- {}
36
+ @format_options ||= begin
37
+ result = case format
38
+ when "mp4"
39
+ {
40
+ video_codec: 'libx264',
41
+ audio_codec: 'libfaac',
42
+ custom: "-qscale 0 -vpre slow -vpre baseline -g 30 #{watermark_params}"
43
+ }
44
+ when "webm"
45
+ {
46
+ video_codec: 'libvpx',
47
+ audio_codec: 'libvorbis',
48
+ custom: "-b 1500k -ab 160000 -f webm -g 30 #{watermark_params}"
49
+ }
50
+ when "ogv"
51
+ {
52
+ video_codec: 'libtheora',
53
+ audio_codec: 'libvorbis',
54
+ custom: "-b 1500k -ab 160000 -g 30 #{watermark_params}"
55
+ }
56
+ else
57
+ {}
58
+ end
59
+
60
+ { resolution: resolution }.merge(result).tap do |h|
61
+ h[:custom] = "#{custom} #{watermark_params}".strip if custom.present?
62
+ end
56
63
  end
57
- { resolution: resolution }.merge(format_options)
58
64
  end
59
65
 
60
66
  def watermark?
@@ -48,9 +48,10 @@ describe CarrierWave::Video do
48
48
  FFMPEG::Movie.should_receive(:new).and_return(movie)
49
49
  end
50
50
 
51
- context "no options set" do
51
+ context "with no options set" do
52
52
  before { File.should_receive(:rename) }
53
- it "is calls transcode with correct format options" do
53
+
54
+ it "calls transcode with correct format options" do
54
55
  movie.should_receive(:transcode) do |path, opts, codec_opts|
55
56
  codec_opts.should == {preserve_aspect_ratio: :width}
56
57
 
@@ -63,9 +64,17 @@ describe CarrierWave::Video do
63
64
 
64
65
  converter.encode_video(format)
65
66
  end
67
+
68
+ it "provides a default for the resolution" do
69
+ movie.should_receive(:transcode) do |path, opts, codec_opts|
70
+ opts[:resolution].should == '640x360'
71
+ end
72
+
73
+ converter.encode_video(format)
74
+ end
66
75
  end
67
76
 
68
- context "callbacks set" do
77
+ context "with callbacks set" do
69
78
  before { movie.should_receive(:transcode) }
70
79
  let(:opts) do
71
80
  { callbacks: {
@@ -108,7 +117,7 @@ describe CarrierWave::Video do
108
117
  end
109
118
  end
110
119
 
111
- context "logger set" do
120
+ context "with logger set" do
112
121
  let(:logger) { mock }
113
122
  before do
114
123
  converter.model.stub(:logger).and_return(logger)
@@ -141,7 +150,7 @@ describe CarrierWave::Video do
141
150
  end
142
151
  end
143
152
 
144
- context "watermark set" do
153
+ context "with watermark set" do
145
154
  before { File.should_receive(:rename) }
146
155
 
147
156
  it "appends watermark params to custom params for ffmpeg" do
@@ -178,6 +187,45 @@ describe CarrierWave::Video do
178
187
  })
179
188
  end
180
189
  end
190
+
191
+ context "with resolution set to :same" do
192
+ before do
193
+ File.should_receive(:rename)
194
+ movie.stub(:resolution).and_return('1280x720')
195
+ end
196
+
197
+ it "sets the output resolution to match that of the input" do
198
+ movie.should_receive(:transcode) do |path, opts, codec_opts|
199
+ opts[:resolution].should == '1280x720'
200
+ end
201
+
202
+ converter.encode_video(format, resolution: :same)
203
+ end
204
+ end
205
+
206
+ context "with custom passed in" do
207
+ before do
208
+ File.should_receive(:rename)
209
+ end
210
+
211
+ it "takes the provided custom param" do
212
+ movie.should_receive(:transcode) do |path, opts, codec_opts|
213
+ opts[:custom].should == '-preset slow' # a la changes in ffmpeg 0.11.1
214
+ end
215
+
216
+ converter.encode_video(format, custom: '-preset slow')
217
+ end
218
+
219
+ it "maintains the watermark params" do
220
+ movie.should_receive(:transcode) do |path, opts, codec_opts|
221
+ opts[:custom].should == "-preset slow -vf \"movie=path/to/file.png [logo]; [in][logo] overlay= [out]\""
222
+ end
223
+
224
+ converter.encode_video(format, custom: '-preset slow', watermark: {
225
+ path: 'path/to/file.png'
226
+ })
227
+ end
228
+ end
181
229
  end
182
230
 
183
231
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - rheaton
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-06-25 00:00:00 -04:00
17
+ date: 2012-07-30 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: "0"
120
120
  requirements:
121
121
  - ruby, version 1.9 or greater
122
- - ffmpeg, version 0.10 or greater with libx256, libfaac, libtheora, libvorbid, libvpx enabled
122
+ - ffmpeg, version 0.11.1 or greater with libx256, libfaac, libtheora, libvorbid, libvpx enabled
123
123
  rubyforge_project: carrierwave-video
124
124
  rubygems_version: 1.3.7
125
125
  signing_key: