dragonfly-ffmpeg 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dragonfly-ffmpeg/analyser.rb +20 -16
- data/lib/dragonfly-ffmpeg/encoder.rb +8 -0
- data/lib/dragonfly-ffmpeg/version.rb +1 -1
- data/spec/dragonfly-ffmpeg/analyser_spec.rb +6 -2
- data/spec/dragonfly-ffmpeg/encoder_spec.rb +111 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/support/video_matchers.rb +62 -5
- metadata +13 -13
@@ -30,69 +30,73 @@ module EnMasse
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def frame_rate(temp_object)
|
33
|
-
|
33
|
+
inspect_movie(:frame_rate, temp_object)
|
34
34
|
end
|
35
35
|
alias_method :fps, :frame_rate
|
36
36
|
|
37
37
|
def duration(temp_object)
|
38
|
-
|
38
|
+
inspect_movie(:duration, temp_object)
|
39
39
|
end
|
40
40
|
|
41
41
|
def bitrate(temp_object)
|
42
|
-
|
42
|
+
inspect_movie(:bitrate, temp_object)
|
43
43
|
end
|
44
44
|
|
45
45
|
def size(temp_object)
|
46
|
-
|
46
|
+
inspect_movie(:size, temp_object)
|
47
47
|
end
|
48
48
|
|
49
49
|
def video_stream(temp_object)
|
50
|
-
|
50
|
+
inspect_movie(:video_stream, temp_object)
|
51
51
|
end
|
52
52
|
|
53
53
|
def video_codec(temp_object)
|
54
|
-
|
54
|
+
inspect_movie(:video_codec, temp_object)
|
55
55
|
end
|
56
56
|
|
57
57
|
def colorspace(temp_object)
|
58
|
-
|
58
|
+
inspect_movie(:colorspace, temp_object)
|
59
59
|
end
|
60
60
|
|
61
61
|
def resolution(temp_object)
|
62
|
-
|
62
|
+
inspect_movie(:resolution, temp_object)
|
63
63
|
end
|
64
64
|
|
65
65
|
def v_width(temp_object)
|
66
|
-
|
66
|
+
inspect_movie(:width, temp_object)
|
67
67
|
end
|
68
68
|
|
69
69
|
def v_height(temp_object)
|
70
|
-
|
70
|
+
inspect_movie(:height, temp_object)
|
71
71
|
end
|
72
72
|
|
73
73
|
def audio_stream(temp_object)
|
74
|
-
|
74
|
+
inspect_movie(:audio_stream, temp_object)
|
75
75
|
end
|
76
76
|
|
77
77
|
def audio_codec(temp_object)
|
78
|
-
|
78
|
+
inspect_movie(:audio_codec, temp_object)
|
79
79
|
end
|
80
80
|
|
81
81
|
def audio_sample_rate(temp_object)
|
82
|
-
|
82
|
+
inspect_movie(:audio_sample_rate, temp_object)
|
83
|
+
end
|
84
|
+
|
85
|
+
def audio_bitrate(temp_object)
|
86
|
+
inspect_movie(:audio_bitrate, temp_object)
|
83
87
|
end
|
84
88
|
|
85
89
|
def audio_channels(temp_object)
|
86
|
-
|
90
|
+
inspect_movie(:audio_channels, temp_object)
|
87
91
|
end
|
88
92
|
|
89
93
|
def valid?(temp_object)
|
90
|
-
|
94
|
+
inspect_movie(:valid?, temp_object)
|
91
95
|
end
|
92
96
|
|
93
97
|
private
|
94
98
|
|
95
|
-
def
|
99
|
+
def inspect_movie(method, temp_object)
|
96
100
|
::FFMPEG::Movie.new(temp_object.path).send(method)
|
97
101
|
end
|
98
102
|
|
@@ -34,6 +34,7 @@ module EnMasse
|
|
34
34
|
:frame_rate => 29.97,
|
35
35
|
:video_bitrate => 3072,
|
36
36
|
:audio_codec => "libfaac",
|
37
|
+
:audio_bitrate => 128,
|
37
38
|
:audio_channels => 2,
|
38
39
|
:audio_sample_rate => 48000,
|
39
40
|
:video_preset => "hq"
|
@@ -46,6 +47,7 @@ module EnMasse
|
|
46
47
|
:frame_rate => 29.97,
|
47
48
|
:video_bitrate => 3072,
|
48
49
|
:audio_codec => "libvorbis",
|
50
|
+
:audio_bitrate => 128,
|
49
51
|
:audio_channels => 2,
|
50
52
|
:audio_sample_rate => 48000
|
51
53
|
)
|
@@ -57,6 +59,7 @@ module EnMasse
|
|
57
59
|
:frame_rate => 29.97,
|
58
60
|
:video_bitrate => 3072,
|
59
61
|
:audio_codec => "libvorbis",
|
62
|
+
:audio_bitrate => 128,
|
60
63
|
:audio_channels => 2,
|
61
64
|
:audio_sample_rate => 48000,
|
62
65
|
:custom => "-f webm"
|
@@ -89,6 +92,11 @@ module EnMasse
|
|
89
92
|
tempfile = new_tempfile(format, original_basename)
|
90
93
|
transcoded_file = origin.transcode(tempfile.path, options)
|
91
94
|
|
95
|
+
if(format.to_s == 'mp4' && `qt-faststart`)
|
96
|
+
`qt-faststart #{transcoded_file.path} #{transcoded_file.path}.tmp.mp4`
|
97
|
+
`mv #{transcoded_file.path}.tmp.mp4 #{transcoded_file.path}`
|
98
|
+
end
|
99
|
+
|
92
100
|
content = ::Dragonfly::TempObject.new(File.new(transcoded_file.path))
|
93
101
|
meta = {
|
94
102
|
:name => (original_basename + ".#{format}"),
|
@@ -31,7 +31,7 @@ describe EnMasse::Dragonfly::FFMPEG::Analyser do
|
|
31
31
|
@analyser.ext(@video).should == '.mov'
|
32
32
|
end
|
33
33
|
|
34
|
-
it "should return the width" do
|
34
|
+
it "should return the width" do
|
35
35
|
@analyser.v_width(@video).should == 1280
|
36
36
|
end
|
37
37
|
|
@@ -44,7 +44,7 @@ describe EnMasse::Dragonfly::FFMPEG::Analyser do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should return the duration" do
|
47
|
-
@analyser.duration(@video).should ==
|
47
|
+
(@analyser.duration(@video)*10).to_i.should == 6
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should return the bit rate" do
|
@@ -71,6 +71,10 @@ describe EnMasse::Dragonfly::FFMPEG::Analyser do
|
|
71
71
|
@analyser.resolution(@video).should == "1280x720"
|
72
72
|
end
|
73
73
|
|
74
|
+
it "should return the bit rate" do
|
75
|
+
@analyser.audio_bitrate(@video).should == 89
|
76
|
+
end
|
77
|
+
|
74
78
|
it "should return the audio stream" do
|
75
79
|
@analyser.audio_stream(@video).should == "aac, 48000 Hz, stereo, s16, 89 kb/s"
|
76
80
|
end
|
@@ -64,13 +64,14 @@ describe EnMasse::Dragonfly::FFMPEG::Encoder do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe "encode with an inline defined encoding profile" do
|
67
|
+
describe "encode with an inline defined encoding profile (:webm)" do
|
68
68
|
let(:profile) do
|
69
69
|
EnMasse::Dragonfly::FFMPEG::Encoder::Profile.new(:webm_720p,
|
70
70
|
:video_codec => "libvpx",
|
71
71
|
:resolution => "1280x720",
|
72
72
|
:frame_rate => 29.97,
|
73
73
|
:video_bitrate => 3072,
|
74
|
+
:audio_bitrate => 128,
|
74
75
|
:audio_codec => "libvorbis",
|
75
76
|
:audio_channels => 2,
|
76
77
|
:audio_sample_rate => 48000,
|
@@ -96,8 +97,114 @@ describe EnMasse::Dragonfly::FFMPEG::Encoder do
|
|
96
97
|
video.should have_bitrate(profile.encoding_options[:video_bitrate])
|
97
98
|
end
|
98
99
|
|
100
|
+
it "should have the specified audio bitrate" do
|
101
|
+
video.should have_audio_bitrate(profile.encoding_options[:audio_bitrate])
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have the specified audio codec" do
|
105
|
+
video.should have_audio_codec("vorbis")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have the specified number of audio channels" do
|
109
|
+
video.should have_audio_channels(profile.encoding_options[:audio_channels])
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should have the specified audio sample rate" do
|
113
|
+
video.should have_audio_sample_rate(profile.encoding_options[:audio_sample_rate])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
describe "encode with an inline defined encoding profile (ogv)" do
|
119
|
+
let(:profile) do
|
120
|
+
EnMasse::Dragonfly::FFMPEG::Encoder::Profile.new(:ogv,
|
121
|
+
:video_codec => "libtheora",
|
122
|
+
:resolution => "1280x720",
|
123
|
+
:frame_rate => 29.97,
|
124
|
+
:video_bitrate => 3072,
|
125
|
+
:audio_bitrate => 128,
|
126
|
+
:audio_codec => "libvorbis",
|
127
|
+
:audio_channels => 2,
|
128
|
+
:audio_sample_rate => 48000
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
let(:video) { subject.encode(raw_video, :ogv, profile).first }
|
133
|
+
|
134
|
+
it "should have the specified video codec" do
|
135
|
+
video.should have_video_codec("theora")
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should have the specified resolution" do
|
139
|
+
video.should have_resolution(profile.encoding_options[:resolution])
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should have the specified frame rate" do
|
143
|
+
video.should have_frame_rate(profile.encoding_options[:frame_rate])
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should have the specified bitrate" do
|
147
|
+
bitrate = EnMasse::Dragonfly::FFMPEG::Analyser.new.bitrate(video)
|
148
|
+
bitrate.should be_within(17).of(profile.encoding_options[:video_bitrate])
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should have the specified audio bitrate" do
|
152
|
+
video.should have_audio_bitrate(profile.encoding_options[:audio_bitrate])
|
153
|
+
end
|
154
|
+
|
99
155
|
it "should have the specified audio codec" do
|
100
|
-
video.should have_audio_codec(
|
156
|
+
video.should have_audio_codec("vorbis")
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should have the specified number of audio channels" do
|
160
|
+
video.should have_audio_channels(profile.encoding_options[:audio_channels])
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should have the specified audio sample rate" do
|
164
|
+
video.should have_audio_sample_rate(profile.encoding_options[:audio_sample_rate])
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "encode with an inline defined encoding profile (mp4)" do
|
169
|
+
let(:profile) do
|
170
|
+
EnMasse::Dragonfly::FFMPEG::Encoder::Profile.new(:mp4,
|
171
|
+
:video_codec => "libx264",
|
172
|
+
:resolution => "1280x720",
|
173
|
+
:frame_rate => 29.97,
|
174
|
+
:video_bitrate => 3072,
|
175
|
+
:audio_bitrate => 128,
|
176
|
+
:audio_codec => "libfaac",
|
177
|
+
:audio_channels => 2,
|
178
|
+
:audio_sample_rate => 48000,
|
179
|
+
:video_preset => "hq"
|
180
|
+
)
|
181
|
+
end
|
182
|
+
|
183
|
+
let(:video) { subject.encode(raw_video, :mp4, profile).first }
|
184
|
+
|
185
|
+
it "should have the specified video codec" do
|
186
|
+
video.should have_video_codec("h264")
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should have the specified resolution" do
|
190
|
+
video.should have_resolution(profile.encoding_options[:resolution])
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should have the specified frame rate" do
|
194
|
+
video.should have_frame_rate(profile.encoding_options[:frame_rate])
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should have the specified bitrate" do
|
198
|
+
bitrate = EnMasse::Dragonfly::FFMPEG::Analyser.new.bitrate(video)
|
199
|
+
bitrate.should be_within(17).of(profile.encoding_options[:video_bitrate])
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should have the specified audio bitrate" do
|
203
|
+
video.should have_audio_bitrate(profile.encoding_options[:audio_bitrate])
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should have the specified audio codec" do
|
207
|
+
video.should have_audio_codec("aac")
|
101
208
|
end
|
102
209
|
|
103
210
|
it "should have the specified number of audio channels" do
|
@@ -120,5 +227,7 @@ describe EnMasse::Dragonfly::FFMPEG::Encoder do
|
|
120
227
|
subject.encode(raw_video, :webm, :a_fake_profile)
|
121
228
|
}.should raise_error(EnMasse::Dragonfly::FFMPEG::UnknownEncoderProfile)
|
122
229
|
end
|
230
|
+
|
231
|
+
|
123
232
|
|
124
233
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,6 +21,16 @@ RSpec::Matchers.define :have_video_codec do |v_codec|
|
|
21
21
|
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
22
22
|
analyser.video_codec(given) == v_codec.to_s
|
23
23
|
end
|
24
|
+
|
25
|
+
failure_message_for_should do |given|
|
26
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
27
|
+
"Expected codec #{v_codec}, but got #{analyser.video_codec(given)}"
|
28
|
+
end
|
29
|
+
|
30
|
+
failure_message_for_should_not do |given|
|
31
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
32
|
+
"Expected codec to not be #{v_codec}, but got #{analyser.video_codec(given)}"
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
RSpec::Matchers.define :have_resolution do |resolution|
|
@@ -33,35 +43,82 @@ end
|
|
33
43
|
RSpec::Matchers.define :have_frame_rate do |frame_rate|
|
34
44
|
match do |given|
|
35
45
|
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
36
|
-
analyser.frame_rate(given) == frame_rate
|
46
|
+
analyser.frame_rate(given) == frame_rate
|
47
|
+
end
|
48
|
+
|
49
|
+
failure_message_for_should do |given|
|
50
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
51
|
+
"Expected frame_rate #{frame_rate}, but got #{analyser.frame_rate(given)}"
|
52
|
+
end
|
53
|
+
|
54
|
+
failure_message_for_should_not do |given|
|
55
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
56
|
+
"Expected frame_rate to not be #{frame_rate}, but got #{analyser.frame_rate(given)}"
|
37
57
|
end
|
38
58
|
end
|
39
59
|
|
40
60
|
RSpec::Matchers.define :have_bitrate do |bitrate|
|
41
61
|
match do |given|
|
42
62
|
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
43
|
-
analyser.bitrate(given) == bitrate
|
63
|
+
analyser.bitrate(given) == bitrate
|
64
|
+
end
|
65
|
+
|
66
|
+
failure_message_for_should do |given|
|
67
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
68
|
+
"Expected bitrate #{bitrate}, but got #{analyser.bitrate(given)}"
|
69
|
+
end
|
70
|
+
|
71
|
+
failure_message_for_should_not do |given|
|
72
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
73
|
+
"Expected bitrate to not be #{bitrate}, but got #{analyser.bitrate(given)}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
RSpec::Matchers.define :have_audio_bitrate do |bitrate|
|
78
|
+
match do |given|
|
79
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
80
|
+
analyser.audio_bitrate(given) == bitrate
|
81
|
+
end
|
82
|
+
|
83
|
+
failure_message_for_should do |given|
|
84
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
85
|
+
"Expected audio bitrate #{bitrate}, but got #{analyser.audio_bitrate(given)}"
|
86
|
+
end
|
87
|
+
|
88
|
+
failure_message_for_should_not do |given|
|
89
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
90
|
+
"Expected audio bitrate to not be #{bitrate}, but got #{analyser.audio_bitrate(given)}"
|
44
91
|
end
|
45
92
|
end
|
46
93
|
|
47
94
|
RSpec::Matchers.define :have_audio_codec do |audio_codec|
|
48
95
|
match do |given|
|
49
96
|
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
50
|
-
analyser.audio_codec(given) == audio_codec
|
97
|
+
analyser.audio_codec(given) == audio_codec
|
98
|
+
end
|
99
|
+
|
100
|
+
failure_message_for_should do |given|
|
101
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
102
|
+
"Expected audio_codec #{audio_codec}, but got #{analyser.audio_codec(given)}"
|
103
|
+
end
|
104
|
+
|
105
|
+
failure_message_for_should_not do |given|
|
106
|
+
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
107
|
+
"Expected audio_codec to not be #{audio_codec}, but got #{analyser.audio_codec(given)}"
|
51
108
|
end
|
52
109
|
end
|
53
110
|
|
54
111
|
RSpec::Matchers.define :have_audio_channels do |audio_channels|
|
55
112
|
match do |given|
|
56
113
|
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
57
|
-
analyser.audio_channels(given) == audio_channels
|
114
|
+
analyser.audio_channels(given) == audio_channels
|
58
115
|
end
|
59
116
|
end
|
60
117
|
|
61
118
|
RSpec::Matchers.define :have_audio_sample_rate do |audio_sample_rate|
|
62
119
|
match do |given|
|
63
120
|
analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
|
64
|
-
analyser.audio_sample_rate(given) == audio_sample_rate
|
121
|
+
analyser.audio_sample_rate(given) == audio_sample_rate
|
65
122
|
end
|
66
123
|
end
|
67
124
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly-ffmpeg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-20 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dragonfly
|
16
|
-
requirement: &
|
16
|
+
requirement: &70205427880460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.9'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70205427880460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: streamio-ffmpeg
|
27
|
-
requirement: &
|
27
|
+
requirement: &70205427879180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70205427879180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70205427878600 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.9.2
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70205427878600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70205427878020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.6.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70205427878020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70205427877040 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.4.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70205427877040
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: fuubar
|
71
|
-
requirement: &
|
71
|
+
requirement: &70205427876360 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70205427876360
|
80
80
|
description: FFMPEG libraries for processesing, encoding, analysing and generating
|
81
81
|
videos with Dragonfly
|
82
82
|
email:
|