puremotion 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/puremotion/codecs.rb +59 -0
- data/lib/puremotion/events/event.rb +69 -0
- data/lib/puremotion/events/generator.rb +50 -0
- data/lib/puremotion/media/stream/audio.rb +0 -0
- data/lib/puremotion/media/stream/base.rb +7 -0
- data/lib/puremotion/media/stream/collection.rb +5 -0
- data/lib/puremotion/media/stream/video.rb +61 -0
- data/lib/puremotion/media/stream.rb +4 -0
- data/lib/puremotion/media.rb +490 -0
- data/lib/puremotion/recipes/ipod.yml +12 -0
- data/lib/puremotion/thread.rb +153 -0
- data/lib/puremotion/tools/ffmpeg.rb +141 -0
- data/lib/puremotion/transcode/recipe.rb +250 -0
- data/lib/puremotion/transcode/transcode.rb +153 -0
- data/lib/puremotion.rb +22 -0
- data/puremotion.gemspec +68 -0
- data/test/helper.rb +10 -0
- data/test/test_puremotion.rb +7 -0
- metadata +89 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ominiom
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= puremotion
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Ominiom. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "puremotion"
|
8
|
+
gem.summary = %Q{PureMotion}
|
9
|
+
gem.description = %Q{A Ruby wrapper for analysis and conversion of media using FFmpeg}
|
10
|
+
gem.email = "iain.iw.wilson@googlemail.com"
|
11
|
+
gem.homepage = "http://github.com/ominiom/puremotion"
|
12
|
+
gem.authors = ["Ominiom"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "puremotion #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module PureMotion::Codecs
|
2
|
+
|
3
|
+
@@Codec = Struct.new(:audio, :video, :ffmpeg_name)
|
4
|
+
|
5
|
+
@@codecs = {
|
6
|
+
'aac' => {
|
7
|
+
:ffmpeg_name => 'libfaac',
|
8
|
+
:audio => true
|
9
|
+
},
|
10
|
+
'mp3' => {
|
11
|
+
:ffmpeg_name => 'libmp3lame',
|
12
|
+
:audio => true
|
13
|
+
},
|
14
|
+
'vorbis' => {
|
15
|
+
:ffmpeg_name => 'libvorbis',
|
16
|
+
:audio => true
|
17
|
+
},
|
18
|
+
'theora' => {
|
19
|
+
:ffmpeg_name => 'libtheora',
|
20
|
+
:video => true
|
21
|
+
},
|
22
|
+
'divx' => {
|
23
|
+
:ffmpeg_name => 'libxvid',
|
24
|
+
:video => true
|
25
|
+
},
|
26
|
+
'h264' => {
|
27
|
+
:ffmpeg_name => 'libx264',
|
28
|
+
:video => true
|
29
|
+
},
|
30
|
+
'flv' => {
|
31
|
+
:ffmpeg_name => 'flv',
|
32
|
+
:video => true
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
def self.find name, type = nil
|
37
|
+
codec = @@codecs[name]
|
38
|
+
if not type.nil? and not codec.nil? then
|
39
|
+
if not codec[type] then return false end
|
40
|
+
end
|
41
|
+
return build(codec) unless codec.nil?
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.valid? name, type = nil
|
46
|
+
codec = find name, type
|
47
|
+
return false if codec.nil?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.build codec
|
52
|
+
c = @@Codec.new
|
53
|
+
codec.each_pair do |key, value|
|
54
|
+
c[key] = value
|
55
|
+
end
|
56
|
+
c
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# ruby-event - event.rb
|
2
|
+
# Author :: Stefan Nuxoll
|
3
|
+
# License :: BSD License
|
4
|
+
# Copyright :: Copyright (C) 2009 Stefan Nuxoll
|
5
|
+
|
6
|
+
require 'thread'
|
7
|
+
|
8
|
+
module PureMotion::Events
|
9
|
+
|
10
|
+
class Event
|
11
|
+
|
12
|
+
# Creates a new instance of event, optionally passing in an already created
|
13
|
+
# array of handlers for the event
|
14
|
+
def initialize(handlers = [], named_handlers = {})
|
15
|
+
@handlers = handlers
|
16
|
+
@named_handlers = named_handlers
|
17
|
+
|
18
|
+
@handlers_lock = Mutex.new
|
19
|
+
@named_handlers_lock = Mutex.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns a new Event object with a new handler added,
|
23
|
+
def +(handler)
|
24
|
+
@handlers_lock.synchronize do
|
25
|
+
@handlers << handler
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creates a new named handler (you can unregister these later without
|
30
|
+
# affecting other handlers)
|
31
|
+
def subscribe(name, &block)
|
32
|
+
@named_handlers_lock.synchronize do
|
33
|
+
@named_handlers[name] = block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Removes a named handler from the event
|
38
|
+
def unsubscribe(name)
|
39
|
+
@named_handlers_lock.synchronize do
|
40
|
+
@named_handlers.delete(name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Calls all of the handlers for the events, with the given sender and set
|
45
|
+
# of arguments.
|
46
|
+
def call(sender, args)
|
47
|
+
# Make sure we don't get surprised with new friends while we're calling
|
48
|
+
# the handlers
|
49
|
+
named_handlers = @named_handlers
|
50
|
+
handlers = @handlers
|
51
|
+
|
52
|
+
named_handlers.each do |name, handler|
|
53
|
+
handler.call(sender, *args)
|
54
|
+
end
|
55
|
+
handlers.each do |handler|
|
56
|
+
handler.call(sender, *args)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Clears the list of anonymous handlers
|
61
|
+
def clear!
|
62
|
+
@handlers_lock.synchronize do
|
63
|
+
@handlers = []
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# ruby-event - generator.rb
|
2
|
+
# Author :: Stefan Nuxoll
|
3
|
+
# License :: BSD License
|
4
|
+
# Copyright :: Copyright (C) 2009 Stefan Nuxoll
|
5
|
+
|
6
|
+
module PureMotion::Events
|
7
|
+
module Generator
|
8
|
+
|
9
|
+
# Constructs the methods and objects for an event automatically
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
# event :data_received
|
13
|
+
def event(event_name)
|
14
|
+
self.class_eval <<-EOT
|
15
|
+
|
16
|
+
def #{event_name}(*args, &block)
|
17
|
+
_ensure_events
|
18
|
+
if not @_events["#{event_name}"]
|
19
|
+
@_events["#{event_name}"] = PureMotion::Events::Event.new
|
20
|
+
end
|
21
|
+
if args != []
|
22
|
+
@_events["#{event_name}"].call(self, args)
|
23
|
+
else
|
24
|
+
if block
|
25
|
+
#{event_name} + block
|
26
|
+
else
|
27
|
+
@_events["#{event_name}"]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def #{event_name}=(event)
|
33
|
+
_ensure_events
|
34
|
+
if PureMotion::Events::Event === event
|
35
|
+
@_events["#{event_name}"] = event
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def _ensure_events
|
40
|
+
if not @_events
|
41
|
+
@_events = {}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private :_ensure_events
|
46
|
+
EOT
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
File without changes
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class PureMotion::Stream::Video
|
2
|
+
|
3
|
+
@raw = ''
|
4
|
+
@media = nil
|
5
|
+
|
6
|
+
def initialize raw
|
7
|
+
@raw = raw
|
8
|
+
|
9
|
+
@matches = {
|
10
|
+
:stream => /Stream\s*(.*?)[,|:|\(|\[].*?\s*Video:\s*(.*?),\s*(.*?),\s*(\d*)x(\d*)/,
|
11
|
+
:bitrate => /Stream\s*.*?[,|:|\(|\[].*?\s*Video:\s*.*?,\s*.*?,\s*\d*x\d*[^,]*,\s*([0-9\.]+)\s*(.*\/.),/,
|
12
|
+
:frame_rate => /Stream\s*.*?[,|:|\(|\[].*?\s*Video:\s\S*,\s\S*,\s\d+x\d+[^,]+,\s\S*\s\S*,\s([^,\s]*)/,
|
13
|
+
:raw_duration => /Duration:\s*([0-9\:\.]+),/
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
return (@raw =~ match(:stream))
|
19
|
+
end
|
20
|
+
|
21
|
+
def fps
|
22
|
+
fps = test(:frame_rate, 1)
|
23
|
+
|
24
|
+
return fps.to_f unless fps.to_f == 0.0
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def resolution
|
29
|
+
res = {
|
30
|
+
:width => test(:stream, 4).to_i,
|
31
|
+
:height => test(:stream, 5).to_i
|
32
|
+
}
|
33
|
+
|
34
|
+
res.each_pair { |k, v| if v == 0 then res[k] = nil end }
|
35
|
+
|
36
|
+
Struct.new("Resolution", :width, :height)
|
37
|
+
Struct::Resolution.new(
|
38
|
+
res[:width],
|
39
|
+
res[:height]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
#def detail
|
44
|
+
#
|
45
|
+
#end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def match name
|
50
|
+
return @matches[name]
|
51
|
+
end
|
52
|
+
|
53
|
+
def test(name = nil, n = -1)
|
54
|
+
match = @matches[name]
|
55
|
+
return nil if match.nil?
|
56
|
+
|
57
|
+
return match.match(@raw) unless n >= 0
|
58
|
+
return match.match(@raw)[n]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|