dragonfly-ffmpeg 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,6 +28,11 @@ module EnMasse
28
28
  e.output_directory = opts[:output_directory] if opts.has_key?(:output_directory)
29
29
  e.encoder_profiles = opts[:encoder_profiles] if opts.has_key?(:encoder_profiles)
30
30
  end
31
+
32
+ c.job :html5 do |format, options|
33
+ options = options || {}
34
+ encode(format, :html5, options)
35
+ end
31
36
  end
32
37
  end
33
38
 
@@ -29,7 +29,7 @@ module EnMasse
29
29
 
30
30
  configurable_attr :encoder_profiles, {
31
31
  :mp4 => [
32
- Profile.new(:default,
32
+ Profile.new(:html5,
33
33
  :video_codec => "libx264",
34
34
  :resolution => "1280x720",
35
35
  :frame_rate => 29.97,
@@ -41,7 +41,7 @@ module EnMasse
41
41
  )
42
42
  ],
43
43
  :ogv => [
44
- Profile.new(:default,
44
+ Profile.new(:html5,
45
45
  :video_codec => "libtheora",
46
46
  :resolution => "1280x720",
47
47
  :frame_rate => 29.97,
@@ -52,7 +52,7 @@ module EnMasse
52
52
  )
53
53
  ],
54
54
  :webm => [
55
- Profile.new(:default,
55
+ Profile.new(:html5,
56
56
  :video_codec => "libvpx",
57
57
  :resolution => "1280x720",
58
58
  :frame_rate => 29.97,
@@ -67,25 +67,31 @@ module EnMasse
67
67
 
68
68
  configurable_attr :output_directory, '/tmp'
69
69
 
70
- def encode(temp_object, format, profile_id = :default, options = {})
71
- if profile_id.is_a?(Profile)
72
- profile = profile_id
73
- else
74
- raise UnknownEncoderProfile unless profile_defined?(format, profile_id.to_sym)
75
- profile = get_profile(format, profile_id.to_sym)
70
+ def encode(temp_object, format, profile = :html5, options = {})
71
+ format = format.to_sym
72
+ raise UnsupportedFormat, "Format not supported - #{format}" unless supported_format?(format)
73
+ unless profile.is_a?(Profile)
74
+ raise UnknownEncoderProfile unless profile_defined?(format, profile.to_sym)
75
+ profile = get_profile(format, profile.to_sym)
76
76
  end
77
77
 
78
78
  options.merge!(profile.encoding_options)
79
79
 
80
80
  origin = ::FFMPEG::Movie.new(temp_object.path)
81
- new_filename = ::Pathname.new(temp_object.path).sub_ext(".#{format}").basename
82
- new_filepath = File.join(output_directory, new_filename)
83
- transcoded = origin.transcode(new_filepath, options)
84
- ::Dragonfly::TempObject.new(File.read(transcoded.path))
81
+ tempfile = new_tempfile(format)
82
+ transcoded = origin.transcode(tempfile.path, options)
83
+ ::Dragonfly::TempObject.new(File.new(transcoded.path))
85
84
  end
86
-
85
+
87
86
  private
88
87
 
88
+ def new_tempfile(ext = nil)
89
+ tempfile = ext ? Tempfile.new(["dragonfy-video", ".#{ext}"]) : Tempfile.new("dragonfly-video")
90
+ tempfile.binmode
91
+ tempfile.close
92
+ tempfile
93
+ end
94
+
89
95
  def profiles(format)
90
96
  encoder_profiles[format]
91
97
  end
@@ -95,6 +101,10 @@ module EnMasse
95
101
  result.first
96
102
  end
97
103
 
104
+ def supported_format?(format)
105
+ encoder_profiles.has_key?(format)
106
+ end
107
+
98
108
  def profile_defined?(format, profile_name)
99
109
  return false if profiles(format).nil?
100
110
 
@@ -25,6 +25,9 @@ module EnMasse
25
25
  class EncoderError < DragonflyFFMPEGError
26
26
  end
27
27
 
28
+ class UnsupportedFormat < EncoderError
29
+ end
30
+
28
31
  class UnknownEncoderProfile < EncoderError
29
32
  end
30
33
  end
@@ -19,7 +19,7 @@
19
19
  module EnMasse
20
20
  module Dragonfly
21
21
  module FFMPEG
22
- VERSION = "0.0.3"
22
+ VERSION = "0.0.4"
23
23
  end
24
24
  end
25
25
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dragonfly-ffmpeg
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamie Winsor
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-01 00:00:00 -07:00
13
+ date: 2011-07-14 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency