dragonfly-ffmpeg 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,5 +5,4 @@ Gemfile.lock
5
5
  pkg/*
6
6
  .rvmrc
7
7
  spec/spec.log
8
- .rspec
9
8
  spec/tmp/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --drb
2
+ --color
3
+ --format Fuubar
data/Gemfile CHANGED
@@ -1,4 +1,33 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in dragonfly-ffmpeg.gemspec
4
3
  gemspec
4
+
5
+ group :development, :test do
6
+ platforms :ruby do
7
+ gem 'spork', '>= 0.9.0.rc9'
8
+ gem 'guard-spork'
9
+
10
+ unless ENV['TRAVIS']
11
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
12
+ gem 'rb-fsevent', '>= 0.3.9'
13
+ gem 'growl', '~> 1.0.3'
14
+ end
15
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
16
+ gem 'rb-inotify', '>= 0.5.1'
17
+ gem 'libnotify', '~> 0.1.3'
18
+ end
19
+ end
20
+ end
21
+
22
+ platforms :jruby do
23
+ unless ENV['TRAVIS']
24
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
25
+ gem 'growl', '~> 1.0.3'
26
+ end
27
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
28
+ gem 'rb-inotify', '>= 0.5.1'
29
+ gem 'libnotify', '~> 0.1.3'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ guard 'rspec', :version => 2, :cli => "--format Fuubar --color --drb --drb-port 9089" do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
7
+
8
+ guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' }, :rspec_port => 9089 do
9
+ watch('config/application.rb')
10
+ watch('config/environment.rb')
11
+ watch(%r{^config/environments/.+\.rb$})
12
+ watch(%r{^config/initializers/.+\.rb$})
13
+ watch('spec/spec_helper.rb')
14
+ end
@@ -19,8 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'dragonfly', '>= 0.9'
23
- s.add_dependency 'streamio-ffmpeg', '>= 0.8.0'
24
- s.add_development_dependency 'rspec', '>= 2.6.0'
25
- s.add_development_dependency 'ruby-debug19'
22
+ s.add_dependency 'dragonfly', '~> 0.9'
23
+ s.add_dependency 'streamio-ffmpeg', '~> 0.8.0'
24
+
25
+ s.add_development_dependency 'rspec', '~> 2.6.0'
26
+ s.add_development_dependency 'guard-rspec', '~> 0.4.2'
27
+ s.add_development_dependency 'fuubar'
26
28
  end
@@ -16,17 +16,18 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'dragonfly'
20
+ require 'dragonfly-ffmpeg/errors'
21
+ require 'streamio-ffmpeg'
22
+
19
23
  module EnMasse
20
24
  module Dragonfly
21
- module FFMPEG
25
+ module FFMPEG
26
+ autoload :Config, 'dragonfly-ffmpeg/config'
27
+ autoload :Analyser, 'dragonfly-ffmpeg/analyser'
28
+ autoload :Encoder, 'dragonfly-ffmpeg/encoder'
22
29
  end
23
30
  end
24
31
  end
25
32
 
26
- require 'dragonfly'
27
- require 'dragonfly-ffmpeg/errors'
28
- require 'dragonfly-ffmpeg/config'
29
- require 'dragonfly-ffmpeg/analyser'
30
- require 'dragonfly-ffmpeg/encoder'
31
-
32
33
  Dragonfly::App.register_configuration(:ffmpeg) { EnMasse::Dragonfly::FFMPEG::Config }
@@ -24,6 +24,10 @@ module EnMasse
24
24
  class Analyser
25
25
 
26
26
  include ::Dragonfly::Loggable
27
+
28
+ def ext(temp_object)
29
+ File.extname(temp_object.path)
30
+ end
27
31
 
28
32
  def frame_rate(temp_object)
29
33
  inspect(:frame_rate, temp_object)
@@ -16,14 +16,13 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'streamio-ffmpeg'
20
19
  require 'pathname'
21
- require 'dragonfly-ffmpeg/encoder/profile'
22
20
 
23
21
  module EnMasse
24
22
  module Dragonfly
25
23
  module FFMPEG
26
24
  class Encoder
25
+ autoload :Profile, 'dragonfly-ffmpeg/encoder/profile'
27
26
 
28
27
  include ::Dragonfly::Configurable
29
28
 
@@ -69,6 +68,7 @@ module EnMasse
69
68
 
70
69
  def encode(temp_object, format, profile = :html5, options = {})
71
70
  format = format.to_sym
71
+
72
72
  raise UnsupportedFormat, "Format not supported - #{format}" unless supported_format?(format)
73
73
  unless profile.is_a?(Profile)
74
74
  raise UnknownEncoderProfile unless profile_defined?(format, profile.to_sym)
@@ -78,15 +78,21 @@ module EnMasse
78
78
  options.merge!(profile.encoding_options)
79
79
 
80
80
  origin = ::FFMPEG::Movie.new(temp_object.path)
81
- tempfile = new_tempfile(format)
82
- transcoded = origin.transcode(tempfile.path, options)
83
- ::Dragonfly::TempObject.new(File.new(transcoded.path))
81
+ tempfile = new_tempfile(format, File.basename(temp_object.path, '.*'))
82
+ transcoded_file = origin.transcode(tempfile.path, options)
83
+
84
+ [
85
+ ::Dragonfly::TempObject.new(File.new(transcoded_file.path)),
86
+ :name => File.basename(transcoded_file.path),
87
+ :format => format,
88
+ :ext => File.extname(transcoded_file.path)
89
+ ]
84
90
  end
85
91
 
86
92
  private
87
93
 
88
- def new_tempfile(ext = nil)
89
- tempfile = ext ? Tempfile.new(["dragonfy-video", ".#{ext}"]) : Tempfile.new("dragonfly-video")
94
+ def new_tempfile(ext = nil, name = 'dragonfly-video')
95
+ tempfile = ext ? Tempfile.new(["#{name}-", ".#{ext}"]) : Tempfile.new("#{name}-")
90
96
  tempfile.binmode
91
97
  tempfile.close
92
98
  tempfile
@@ -19,7 +19,7 @@
19
19
  module EnMasse
20
20
  module Dragonfly
21
21
  module FFMPEG
22
- VERSION = "0.0.4"
22
+ VERSION = "0.1.0"
23
23
  end
24
24
  end
25
25
  end
@@ -27,6 +27,10 @@ describe EnMasse::Dragonfly::FFMPEG::Analyser do
27
27
  @analyser.log = Logger.new(LOG_FILE)
28
28
  end
29
29
 
30
+ it "should return the extension of the file" do
31
+ @analyser.ext(@video).should == '.mov'
32
+ end
33
+
30
34
  it "should return the width" do
31
35
  @analyser.v_width(@video).should == 1280
32
36
  end
@@ -20,46 +20,104 @@ require 'spec_helper'
20
20
 
21
21
  describe EnMasse::Dragonfly::FFMPEG::Encoder do
22
22
 
23
- before(:all) do
24
- video_path = SAMPLES_DIR + '/test-movie.mov'
25
- @video = Dragonfly::TempObject.new(File.new(video_path))
26
- @encoder = EnMasse::Dragonfly::FFMPEG::Encoder.new
27
- @encoder.output_directory = TMP_DIR
23
+ subject do
24
+ encoder = EnMasse::Dragonfly::FFMPEG::Encoder.new
25
+ encoder.output_directory = TMP_DIR
26
+ encoder
28
27
  end
29
28
 
30
- it "should encode the video using the default mp4 encoding profile" do
31
- video = @encoder.encode(@video, :mp4)
32
- video.should have_video_codec(:h264)
29
+ let(:raw_video) { Dragonfly::TempObject.new(File.new(SAMPLES_DIR + '/test-movie.mov')) }
30
+
31
+ describe "encode with default mp4 profile" do
32
+ let(:video) { subject.encode(raw_video, :mp4).first }
33
+
34
+ it "should have the h264 video codec" do
35
+ video.should have_video_codec(:h264)
36
+ end
37
+
38
+ it "should have a mp4 file extension" do
39
+ video.should have_file_extension('.mp4')
40
+ end
33
41
  end
34
42
 
35
- it "should encode the video using the default ogv encoding profile" do
36
- video = @encoder.encode(@video, :ogv)
37
- video.should have_video_codec(:theora)
43
+ describe "encode with default mp4 profile" do
44
+ let(:video) { subject.encode(raw_video, :ogv).first }
45
+
46
+ it "should have the theora video codec" do
47
+ video.should have_video_codec(:theora)
48
+ end
49
+
50
+ it "should have the ogv file extension" do
51
+ video.should have_file_extension('.ogv')
52
+ end
38
53
  end
39
54
 
40
- it "should encode the video using the default webm encoding profile" do
41
- video = @encoder.encode(@video, :webm)
42
- video.should have_video_codec(:libvpx)
55
+ describe "encode with default webm profile" do
56
+ let(:video) { subject.encode(raw_video, :webm).first }
57
+
58
+ it "should have the libvpx video codec" do
59
+ video.should have_video_codec(:libvpx)
60
+ end
61
+
62
+ it "should have the webm file extension" do
63
+ video.should have_file_extension('.webm')
64
+ end
43
65
  end
44
66
 
45
- it "should encode the video using an encoding profile that is defined inline" do
46
- profile = EnMasse::Dragonfly::FFMPEG::Encoder::Profile.new(:webm_720p,
47
- :video_codec => "libvpx",
48
- :resolution => "1280x720",
49
- :frame_rate => 29.97,
50
- :video_bitrate => 3072,
51
- :audio_codec => "libvorbis",
52
- :audio_channels => 2,
53
- :audio_sample_rate => 48000,
54
- :custom => "-f webm"
55
- )
56
- video = @encoder.encode(@video, :webm, profile)
57
- video.should have_video_codec(:libvpx)
67
+ describe "encode with an inline defined encoding profile" do
68
+ let(:profile) do
69
+ EnMasse::Dragonfly::FFMPEG::Encoder::Profile.new(:webm_720p,
70
+ :video_codec => "libvpx",
71
+ :resolution => "1280x720",
72
+ :frame_rate => 29.97,
73
+ :video_bitrate => 3072,
74
+ :audio_codec => "libvorbis",
75
+ :audio_channels => 2,
76
+ :audio_sample_rate => 48000,
77
+ :custom => "-f webm"
78
+ )
79
+ end
80
+
81
+ let(:video) { subject.encode(raw_video, :webm, profile).first }
82
+
83
+ it "should have the specified video codec" do
84
+ video.should have_video_codec(profile.encoding_options[:video_codec])
85
+ end
86
+
87
+ it "should have the specified resolution" do
88
+ video.should have_resolution(profile.encoding_options[:resolution])
89
+ end
90
+
91
+ it "should have the specified frame rate" do
92
+ video.should have_frame_rate(profile.encoding_options[:frame_rate])
93
+ end
94
+
95
+ it "should have the specified bitrate" do
96
+ video.should have_bitrate(profile.encoding_options[:video_bitrate])
97
+ end
98
+
99
+ it "should have the specified audio codec" do
100
+ video.should have_audio_codec(profile.encoding_options[:audio_codec])
101
+ end
102
+
103
+ it "should have the specified number of audio channels" do
104
+ video.should have_audio_channels(profile.encoding_options[:audio_channels])
105
+ end
106
+
107
+ it "should have the specified audio sample rate" do
108
+ video.should have_audio_sample_rate(profile.encoding_options[:audio_sample_rate])
109
+ end
110
+ end
111
+
112
+ it "should throw UnsupportedFormat if the format specified is not defined" do
113
+ lambda {
114
+ subject.encode(raw_video, :lol264, :html5)
115
+ }.should raise_error(EnMasse::Dragonfly::FFMPEG::UnsupportedFormat)
58
116
  end
59
117
 
60
118
  it "should throw UnknownEncoderProfile if the encoding profile is not defined" do
61
119
  lambda {
62
- @encoder.encode(@video, :lol264, :h264_720p)
120
+ subject.encode(raw_video, :webm, :a_fake_profile)
63
121
  }.should raise_error(EnMasse::Dragonfly::FFMPEG::UnknownEncoderProfile)
64
122
  end
65
123
 
@@ -19,26 +19,33 @@
19
19
  require 'rubygems'
20
20
  require 'bundler'
21
21
  Bundler.setup(:default, :test)
22
+ require 'spork'
22
23
 
23
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
24
- $LOAD_PATH.unshift(File.dirname(__FILE__))
25
- require 'rspec'
26
- require 'dragonfly-ffmpeg'
27
- require 'support/video_matchers'
24
+ Spork.prefork do
25
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
26
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
27
+ require 'rspec'
28
+ require 'dragonfly-ffmpeg'
29
+ require 'support/video_matchers'
28
30
 
29
- SAMPLES_DIR = File.expand_path(File.dirname(__FILE__) + '/../samples') unless defined?(SAMPLES_DIR)
31
+ SAMPLES_DIR = File.expand_path(File.dirname(__FILE__) + '/../samples') unless defined?(SAMPLES_DIR)
30
32
 
31
- require 'logger'
32
- LOG_FILE = File.dirname(__FILE__) + '/spec.log' unless defined?(LOG_FILE)
33
- TMP_DIR = File.dirname(__FILE__) + '/tmp' unless defined?(TMP_DIR)
34
- FileUtils.mkdir_p(TMP_DIR)
35
- FileUtils.rm_rf Dir.glob(TMP_DIR + '/*')
36
- FileUtils.rm_rf(LOG_FILE)
33
+ require 'logger'
34
+ LOG_FILE = File.dirname(__FILE__) + '/spec.log' unless defined?(LOG_FILE)
35
+ TMP_DIR = File.dirname(__FILE__) + '/tmp' unless defined?(TMP_DIR)
36
+ FileUtils.mkdir_p(TMP_DIR)
37
+ FileUtils.rm_rf Dir.glob(TMP_DIR + '/*')
38
+ FileUtils.rm_rf(LOG_FILE)
37
39
 
38
- logger = Logger.new(LOG_FILE)
39
- logger.level = Logger::INFO
40
- FFMPEG.logger = logger
40
+ logger = Logger.new(LOG_FILE)
41
+ logger.level = Logger::INFO
42
+ FFMPEG.logger = logger
43
+
44
+ def test_app
45
+ Dragonfly::App.send(:new)
46
+ end
47
+ end
41
48
 
42
- def test_app
43
- Dragonfly::App.send(:new)
49
+ Spork.each_run do
50
+ # code for each spork run
44
51
  end
@@ -22,3 +22,52 @@ RSpec::Matchers.define :have_video_codec do |v_codec|
22
22
  analyser.video_codec(given) == v_codec.to_s
23
23
  end
24
24
  end
25
+
26
+ RSpec::Matchers.define :have_resolution do |resolution|
27
+ match do |given|
28
+ analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
29
+ analyser.resolution(given) == resolution.to_s
30
+ end
31
+ end
32
+
33
+ RSpec::Matchers.define :have_frame_rate do |frame_rate|
34
+ match do |given|
35
+ analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
36
+ analyser.frame_rate(given) == frame_rate.to_s
37
+ end
38
+ end
39
+
40
+ RSpec::Matchers.define :have_bitrate do |bitrate|
41
+ match do |given|
42
+ analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
43
+ analyser.bitrate(given) == bitrate.to_s
44
+ end
45
+ end
46
+
47
+ RSpec::Matchers.define :have_audio_codec do |audio_codec|
48
+ match do |given|
49
+ analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
50
+ analyser.audio_codec(given) == audio_codec.to_s
51
+ end
52
+ end
53
+
54
+ RSpec::Matchers.define :have_audio_channels do |audio_channels|
55
+ match do |given|
56
+ analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
57
+ analyser.audio_channels(given) == audio_channels.to_s
58
+ end
59
+ end
60
+
61
+ RSpec::Matchers.define :have_audio_sample_rate do |audio_sample_rate|
62
+ match do |given|
63
+ analyser = EnMasse::Dragonfly::FFMPEG::Analyser.new
64
+ analyser.audio_sample_rate(given) == audio_sample_rate.to_s
65
+ end
66
+ end
67
+
68
+ RSpec::Matchers.define :have_file_extension do |file_extension|
69
+ match do |given|
70
+ File.extname(given.path) == file_extension
71
+ end
72
+ end
73
+
metadata CHANGED
@@ -1,74 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dragonfly-ffmpeg
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
4
5
  prerelease:
5
- version: 0.0.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Jamie Winsor
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-14 00:00:00 -07:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: dragonfly
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70265767650100 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0.9"
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: streamio-ffmpeg
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70265767650100
25
+ - !ruby/object:Gem::Dependency
26
+ name: streamio-ffmpeg
27
+ requirement: &70265767649420 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
35
32
  version: 0.8.0
36
33
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: rspec
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70265767649420
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70265767648120 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
46
43
  version: 2.6.0
47
44
  type: :development
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: ruby-debug19
51
45
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70265767648120
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-rspec
49
+ requirement: &70265767647660 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.2
58
55
  type: :development
59
- version_requirements: *id004
60
- description: FFMPEG libraries for processesing, encoding, analysing and generating videos with Dragonfly
61
- email:
56
+ prerelease: false
57
+ version_requirements: *70265767647660
58
+ - !ruby/object:Gem::Dependency
59
+ name: fuubar
60
+ requirement: &70265767647280 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70265767647280
69
+ description: FFMPEG libraries for processesing, encoding, analysing and generating
70
+ videos with Dragonfly
71
+ email:
62
72
  - jamie@enmasse.com
63
73
  executables: []
64
-
65
74
  extensions: []
66
-
67
75
  extra_rdoc_files: []
68
-
69
- files:
76
+ files:
70
77
  - .gitignore
78
+ - .rspec
71
79
  - Gemfile
80
+ - Guardfile
72
81
  - LICENSE
73
82
  - README.md
74
83
  - Rakefile
@@ -85,35 +94,31 @@ files:
85
94
  - spec/dragonfly-ffmpeg/encoder_spec.rb
86
95
  - spec/spec_helper.rb
87
96
  - spec/support/video_matchers.rb
88
- has_rdoc: true
89
97
  homepage: https://github.com/enmasse-entertainment/dragonfly-ffmpeg
90
98
  licenses: []
91
-
92
99
  post_install_message:
93
100
  rdoc_options: []
94
-
95
- require_paths:
101
+ require_paths:
96
102
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
103
+ required_ruby_version: !ruby/object:Gem::Requirement
98
104
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: "0"
103
- required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
110
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: "0"
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
109
115
  requirements: []
110
-
111
116
  rubyforge_project: dragonfly-ffmpeg
112
- rubygems_version: 1.6.2
117
+ rubygems_version: 1.8.10
113
118
  signing_key:
114
119
  specification_version: 3
115
120
  summary: A video manipulation plugin for Dragonfly
116
- test_files:
121
+ test_files:
117
122
  - spec/dragonfly-ffmpeg/analyser_spec.rb
118
123
  - spec/dragonfly-ffmpeg/encoder_spec.rb
119
124
  - spec/spec_helper.rb