uencode 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ This project is released under The MIT License
2
+
3
+ Copyright © 2011, uEncode, Cássio Marques
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # UEncode
2
2
 
3
- A Ruby gem to interact with the [uEncode](http://www.uencode.com) API. This extends the work of [Cassio Marques](https://github.com/cassiomarques/).
3
+ A Ruby gem to interact with the [uEncode](http://www.uencode.com) API. This extends the work of [Cássio Marques](https://github.com/cassiomarques/).
4
4
 
5
5
  ## Creating a job
6
6
 
@@ -14,8 +14,7 @@ end
14
14
 
15
15
 
16
16
  #create job and set source video
17
- job = UEncode::Job.new :userdata => "AnyDataUsefulToYou", :callback => "Your Email Address or Callack Url"
18
- job.source_video = UEncode::Source.new :url => "http://your.source.url/foo.flv", :timeout => 600
17
+ job = UEncode::Job.new :userdata => "AnyDataUsefulToYou", :callback => "Your Email Address or Callack Url", :source_video => {:url => "http://your.source.url/foo.flv", :timeout => 600}
19
18
 
20
19
  #create configuration for a video output
21
20
  configuration = {:video => {:bitrate => 1000, :codec => 'h264', :profile => 'baseline', :size => {:width => 640, :height => 480}, :fix_rotation => true, :force_sqare_pixels => true}}
@@ -45,6 +44,18 @@ puts response.code
45
44
  puts response.data
46
45
  ```
47
46
 
47
+ ## Advanced output options
48
+ ``` ruby
49
+ #add an overlay to a video or capture output
50
+ out = UEncode::VideoOutput.new :container => 'mpeg4', :overlay => {:quadrant=>'Lower-Right', :source_image=>{:url=>'http://your.source.url/logo.png'}}
51
+
52
+ #encode only a portion of input video (values are seconds)
53
+ out = UEncode::VideoOutput.new :container => 'mpeg4', :clip => {:start => 30, :duration => 60}
54
+
55
+ #add metadata to a video
56
+ out = UEncode::VideoOutput.new :container => 'mpeg4', :metadata => {:title => 'Video Title', :author => 'Video Author'}
57
+ ```
58
+
48
59
  ## Checking job status
49
60
  ``` ruby
50
61
  require 'uencode'
@@ -81,7 +92,7 @@ The gem does not validate input. Consult the [uEncode API documentation](http://
81
92
 
82
93
  This project is released under The MIT License
83
94
 
84
- Copyright © 2011, uEncode, Cassio Marques
95
+ Copyright © 2011, uEncode, Cássio Marques
85
96
 
86
97
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
87
98
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2011, uEncode, Cassio Marques
1
+ # Copyright (c) 2011, uEncode, Cássio Marques
2
2
 
3
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -18,8 +18,17 @@ module UEncode
18
18
 
19
19
  module AttrSetting
20
20
  def set_attributes(options)
21
- self.class.const_get("ATTRIBUTES").each { |attr| instance_variable_set(:"@#{attr}", options[attr.to_sym] || options[attr.to_s]) }
22
- end
21
+ # self.class.const_get("ATTRIBUTES").each { |attr| instance_variable_set(:"@#{attr}", options[attr.to_sym] || options[attr.to_s]) }
22
+ # options.each do |key, value|
23
+ options.each_pair { |key, value|
24
+ if self.class.const_get("ATTRIBUTES").include?(key)
25
+ instance_variable_set(:"@#{key}", value)
26
+ else
27
+ self.send("#{key}=", value)
28
+ end
29
+ }
30
+
31
+ end
23
32
 
24
33
  def initialize(options)
25
34
  set_attributes options
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2011, uEncode, Cassio Marques
1
+ # Copyright (c) 2011, uEncode, Cássio Marques
2
2
 
3
3
  module UEncode
4
4
 
@@ -76,6 +76,62 @@ module UEncode
76
76
  private
77
77
  def root_name; "source"; end
78
78
  end
79
+
80
+ class OverlayUrl
81
+ include Transfer
82
+
83
+ private
84
+ def root_name; "url"; end
85
+ end
86
+
87
+ class Position
88
+ ATTRIBUTES = [:x, :y]
89
+
90
+ include AttrSetting
91
+
92
+ def to_xml
93
+ %Q{
94
+ <position>
95
+ <#{x.nil? ? '<x>' + x.to_s + '</x>' : ""}
96
+ <#{y.nil? ? '<y>' + y.to_s + '</y>' : ""}
97
+ </position>
98
+ }
99
+ end
100
+ end
101
+
102
+ class Overlay
103
+ ATTRIBUTES = [:quadrant]
104
+
105
+ include AttrSetting
106
+
107
+ def position=(_position)
108
+ _position = Position.new(_position) unless _position.instance_of?(Position) || _position.nil?
109
+ instance_variable_set :@position, _position
110
+ end
111
+
112
+ def position
113
+ @position
114
+ end
115
+
116
+ def source_image=(_source)
117
+ _source = OverlayUrl.new(_source) unless _source.instance_of?(OverlayUrl) || _source.nil?
118
+ instance_variable_set :@source_image, _source
119
+ end
120
+
121
+ def source_image
122
+ @source_image
123
+ end
124
+
125
+ def to_xml
126
+ %Q{
127
+ <overlay>
128
+ #{!source_image.nil? ? source_image.to_xml : ""}
129
+ #{!@position.nil? ? @position.to_xml : ""}
130
+ #{!quadrant.nil? ? '<quadrant>' + quadrant.to_s + '</quadrant>' : ""}
131
+ </overlay>
132
+ }
133
+ end
134
+ end
79
135
 
80
136
  class CaptureOutput
81
137
  ATTRIBUTES = [:rate, :stretch, :crop, :zip, :prefix]
@@ -107,6 +163,14 @@ module UEncode
107
163
  @max_size
108
164
  end
109
165
 
166
+ def overlay=(_overlay)
167
+ _overlay = Overlay.new(_overlay) unless _overlay.instance_of?(Overlay) || _overlay.nil?
168
+ instance_variable_set :@overlay, _overlay
169
+ end
170
+
171
+ def overlay
172
+ @overlay
173
+ end
110
174
 
111
175
  def to_xml
112
176
  %Q{
@@ -119,19 +183,93 @@ module UEncode
119
183
  </destinations>
120
184
  #{@size ? @size.to_xml : ""}
121
185
  #{@max_size ? @max_size.to_xml : ""}
186
+ #{@overlay ? @overlay.to_xml : ""}
122
187
  </capture>
123
188
  }
124
189
  end
125
190
  end
126
191
 
192
+ class Metadata
193
+ ATTRIBUTES = [:title, :author, :composer, :album, :year, :track, :comment, :genre, :copyright, :description, :synopsis, :show, :episode_id, :network]
194
+
195
+ include AttrSetting
196
+
197
+ def to_xml
198
+ %Q{
199
+ <meta>
200
+ #{!title.nil? ? '<title>' + title.to_s + '</title>' : ""}
201
+ #{!author.nil? ? '<author>' + author.to_s + '</author>' : ""}
202
+ #{!composer.nil? ? '<composer>' + composer.to_s + '</composer>' : ""}
203
+ #{!album.nil? ? '<album>' + album.to_s + '</album>' : ""}
204
+ #{!year.nil? ? '<year>' + year.to_s + '</year>' : ""}
205
+ #{!track.nil? ? '<track>' + track.to_s + '</track>' : ""}
206
+ #{!comment.nil? ? '<comment>' + comment.to_s + '</comment>' : ""}
207
+ #{!genre.nil? ? '<genre>' + genre.to_s + '</genre>' : ""}
208
+ #{!copyright.nil? ? '<copyright>' + copyright.to_s + '</copyright>' : ""}
209
+ #{!description.nil? ? '<description>' + description.to_s + '</description>' : ""}
210
+ #{!synopsis.nil? ? '<synopsis>' + synopsis.to_s + '</synopsis>' : ""}
211
+ #{!show.nil? ? '<show>' + show.to_s + '</show>' : ""}
212
+ #{!episode_id.nil? ? '<episode_id>' + episode_id.to_s + '</episode_id>' : ""}
213
+ #{!network.nil? ? '<network>' + network.to_s + '</network>' : ""}
214
+ </meta>
215
+ }
216
+ end
217
+ end
218
+
219
+ class Clip
220
+ ATTRIBUTES = [:start, :duration]
221
+
222
+ include AttrSetting
223
+
224
+ def to_xml
225
+ %Q{
226
+ <clip>
227
+ #{!start.nil? ? '<start>' + start.to_s + '</start>' : ""}
228
+ #{!duration.nil? ? '<duration>' + duration.to_s + '</duration>' : ""}
229
+ </clip>
230
+ }
231
+ end
232
+ end
233
+
127
234
  class VideoOutput
128
235
  ATTRIBUTES = [:destination, :container]
129
236
 
237
+ include AttrSetting
238
+
130
239
  include Enumerable
131
240
 
132
241
  attr_writer :container
133
242
  attr_accessor :streams
134
243
 
244
+
245
+ def overlay=(_overlay)
246
+ _overlay = Overlay.new(_overlay) unless _overlay.instance_of?(Overlay) || _overlay.nil?
247
+ instance_variable_set :@overlay, _overlay
248
+ end
249
+
250
+ def overlay
251
+ @overlay
252
+ end
253
+
254
+ def clip=(_clip)
255
+ _clip = Clip.new(_clip) unless _clip.instance_of?(Clip) || _clip.nil?
256
+ instance_variable_set :@clip, _clip
257
+ end
258
+
259
+ def clip
260
+ @clip
261
+ end
262
+
263
+ def metadata=(_metadata)
264
+ _metadata = Metadata.new(_metadata) unless _metadata.instance_of?(Metadata) || _metadata.nil?
265
+ instance_variable_set :@metadata, _metadata
266
+ end
267
+
268
+ def metadata
269
+ @metadata
270
+ end
271
+
272
+
135
273
  def initialize(options)
136
274
  @streams = VideoStreams.new
137
275
  @destinations = []
@@ -150,8 +288,11 @@ module UEncode
150
288
  %Q{
151
289
  <video>
152
290
  <destinations>
153
- #{@destinations.inject("") { |s, dest| s << dest.to_xml}}
291
+ #{@destinations.inject("") { |s, dest| s << dest.to_xml}}
154
292
  </destinations>
293
+ #{metadata.nil? ? "" : metadata.to_xml}
294
+ #{clip.nil? ? "" : clip.to_xml}
295
+ #{overlay.nil? ? "" : overlay.to_xml}
155
296
  <container>#{container}</container>
156
297
  #{@streams.to_xml}
157
298
  </video>
@@ -163,6 +304,7 @@ module UEncode
163
304
  class VideoStreams
164
305
  attr_reader :video_config, :audio_config
165
306
 
307
+
166
308
  def initialize
167
309
  @video_config = VideoConfig.new
168
310
  @audio_config = AudioConfig.new
@@ -180,17 +322,17 @@ module UEncode
180
322
  # codec, bitrate, channels, samplerate.
181
323
  #
182
324
  def configure(hash)
183
- video = hash[:video]
184
- audio = hash[:audio]
185
- if !video.nil?
325
+ vid = hash[:video]
326
+ aud = hash[:audio]
327
+ if !vid.nil?
186
328
  configure_video do |c|
187
- video.each_pair { |key, value| c.send("#{key}=", value) }
329
+ vid.each_pair { |key, value| c.send("#{key}=", value)}
188
330
  end
189
331
  end
190
332
 
191
- if !audio.nil?
333
+ if !aud.nil?
192
334
  configure_audio do |c|
193
- audio.each_pair { |key, value| c.send("#{key}=", value) }
335
+ aud.each_pair { |key, value| c.send("#{key}=", value) }
194
336
  end
195
337
  end
196
338
  end
@@ -241,12 +383,6 @@ module UEncode
241
383
  class VideoConfig
242
384
  attr_accessor :bitrate, :codec, :profile, :quality, :framerate, :passes, :deinterlace, :fix_rotation, :force_square_pixels
243
385
 
244
- def initialize
245
- @deinterlace = false
246
- @profile = "main"
247
- @passes = 1
248
- end
249
-
250
386
  def size=(_size)
251
387
  _size = Size.new(_size) unless _size.instance_of?(Size) || _size.nil?
252
388
  instance_variable_set :@size, _size
@@ -269,6 +405,7 @@ module UEncode
269
405
  # The audio configs for each VideoStream
270
406
  class AudioConfig
271
407
  attr_accessor :codec, :bitrate, :channels, :samplerate, :quality
408
+
272
409
  end
273
410
 
274
411
  class JobStatus
@@ -290,7 +427,7 @@ module UEncode
290
427
  def source_video
291
428
  @source_video
292
429
  end
293
-
430
+
294
431
  def initialize(options)
295
432
  @video_outputs = []
296
433
  @captures = []
@@ -311,7 +448,7 @@ module UEncode
311
448
  <job>
312
449
  #{source_video.nil? ? "" : source_video.to_xml}
313
450
  #{userdata.nil? ? "" : '<userdata>' + userdata + '</userdata>'}
314
- #{callback.nil? ? "" : '<callback>' + callback + '</callback>'}
451
+ #{callback.nil? ? "" : '<callback>' + callback + '</callback>'}
315
452
  <outputs>
316
453
  #{@video_outputs.inject("") { |s, vid| s << vid.to_xml}}
317
454
  #{@captures.inject("") { |s, cap| s << cap.to_xml }}
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2011, uEncode, Cassio Marques
1
+ # Copyright (c) 2011, uEncode, Cássio Marques
2
2
 
3
3
  module UEncode
4
4
  class Request
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2011, uEncode, Cassio Marques
1
+ # Copyright (c) 2011, uEncode, Cássio Marques
2
2
 
3
3
  module UEncode
4
4
  class Response
@@ -1,5 +1,5 @@
1
- # Copyright (c) 2011, uEncode, Cassio Marques
1
+ # Copyright (c) 2011, uEncode, Cássio Marques
2
2
 
3
3
  module UEncode
4
- VERSION = "3.0.0"
4
+ VERSION = "3.1.0"
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: uencode
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.0.0
5
+ version: 3.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - uencode
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-03-16 00:00:00 -04:00
14
+ date: 2012-03-29 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -71,7 +71,7 @@ files:
71
71
  - .autotest
72
72
  - .gitignore
73
73
  - Gemfile
74
- - Guardfile
74
+ - LICENSE.txt
75
75
  - README.md
76
76
  - Rakefile
77
77
  - lib/uencode.rb
data/Guardfile DELETED
@@ -1,8 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec', :notification => true do
5
- watch(%r{^spec/.+_spec\.rb})
6
- watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
- end