streamio-ffmpeg 0.1.0
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/CHANGELOG +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/ffmpeg/movie.rb +42 -0
- data/lib/streamio-ffmpeg.rb +7 -0
- data/spec/ffmpeg/movie_spec.rb +61 -0
- data/spec/fixtures/movies/awesome.mov +0 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +13 -0
- data/streamio-ffmpeg.gemspec +58 -0
- metadata +79 -0
data/.document
ADDED
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Backeus
|
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,29 @@
|
|
1
|
+
= Streamio FFMPEG
|
2
|
+
|
3
|
+
Simplest possible wrapper around FFMPEG to get metadata from movie files and do transcoding. IN DEVELOPMENT - Current version only handles basic metadata parsing.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
sudo gem install streamio-ffmpeg
|
8
|
+
|
9
|
+
(should add instructions for ffmpeg installation here as well)
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
movie = FFMPEG::Movie.new("path/to/movie.mov")
|
14
|
+
movie.duration # Duration of the movie in seconds
|
15
|
+
movie.width # Width of the movie in pixels
|
16
|
+
movie.height # Height of the movie in pixels
|
17
|
+
|
18
|
+
== Note on Patches/Pull Requests
|
19
|
+
|
20
|
+
* Fork the project.
|
21
|
+
* Make your feature addition or bug fix.
|
22
|
+
* Add specs for it. This is important so I don't break it in a future version unintentionally.
|
23
|
+
* Commit, do not mess with rakefile, version, or history.
|
24
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
25
|
+
* Send me a pull request. Bonus points for topic branches.
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2010 David Backeus. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "streamio-ffmpeg"
|
8
|
+
gem.summary = %Q{Simple wrapper around ffmpeg to get metadata from movies and do transcoding}
|
9
|
+
gem.description = %Q{Simple wrapper around ffmpeg to get metadata from movies and do transcoding}
|
10
|
+
gem.email = "duztdruid@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/dbackeus/streamio-ffmpeg"
|
12
|
+
gem.authors = ["David Backeus"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
22
|
+
spec.libs << 'lib' << 'spec'
|
23
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
spec.rcov = true
|
30
|
+
end
|
31
|
+
|
32
|
+
task :spec => :check_dependencies
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rake/rdoctask'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "streamio-ffmpeg #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/ffmpeg/movie.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module FFMPEG
|
4
|
+
class Movie
|
5
|
+
attr_reader :duration, :video_stream, :audio_stream, :video_codec, :colorspace, :resolution
|
6
|
+
|
7
|
+
def initialize(path)
|
8
|
+
raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exists?(path)
|
9
|
+
|
10
|
+
stdin, stdout, stderr = Open3.popen3("ffmpeg -i #{path}") # Output will land in stderr
|
11
|
+
output = stderr.read
|
12
|
+
|
13
|
+
@valid = output[/Unknown format/].nil?
|
14
|
+
|
15
|
+
output[/Duration: (\d{2}):(\d{2}):(\d{2}\.\d{1})/]
|
16
|
+
@duration = ($1.to_i*60*60) + ($2.to_i*60) + $3.to_f
|
17
|
+
|
18
|
+
output[/Video: (.*)/]
|
19
|
+
@video_stream = $1
|
20
|
+
|
21
|
+
output[/Audio: (.*)/]
|
22
|
+
@audio_stream = $1
|
23
|
+
|
24
|
+
if video_stream
|
25
|
+
@video_codec, @colorspace, resolution = video_stream.split(/\s?,\s?/)
|
26
|
+
@resolution = resolution.split(" ").first # get rid of [PAR 1:1 DAR 16:9]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid?
|
31
|
+
@valid
|
32
|
+
end
|
33
|
+
|
34
|
+
def width
|
35
|
+
resolution.split("x")[0].to_i rescue nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def height
|
39
|
+
resolution.split("x")[1].to_i rescue nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require 'spec_helper.rb'
|
3
|
+
|
4
|
+
module FFMPEG
|
5
|
+
describe Movie do
|
6
|
+
describe "given a non existing file" do
|
7
|
+
it "should throw ArgumentError" do
|
8
|
+
lambda { Movie.new("i_dont_exist") }.should raise_error(Errno::ENOENT, /does not exist/)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "given a non movie file" do
|
13
|
+
before(:all) do
|
14
|
+
@movie = Movie.new(__FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not be valid" do
|
18
|
+
@movie.should_not be_valid
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "given awesome.mov file" do
|
23
|
+
before(:all) do
|
24
|
+
@movie = Movie.new("#{fixture_path}/movies/awesome.mov")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should parse duration to number of seconds" do
|
28
|
+
@movie.duration.should == 7.5
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should parse video stream information" do
|
32
|
+
@movie.video_stream.should == "h264, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 371 kb/s, 16.75 fps, 15 tbr, 600 tbn, 1200 tbc"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should parse audio stream information" do
|
36
|
+
@movie.audio_stream.should == "aac, 44100 Hz, stereo, s16, 75 kb/s"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should know the video codec" do
|
40
|
+
@movie.video_codec.should == "h264"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should know the colorspace" do
|
44
|
+
@movie.colorspace.should == "yuv420p"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should know the resolution" do
|
48
|
+
@movie.resolution.should == "640x480"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should know the width and height" do
|
52
|
+
@movie.width.should == 640
|
53
|
+
@movie.height.should == 480
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should should be valid" do
|
57
|
+
@movie.should be_valid
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
Binary file
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'streamio-ffmpeg'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def fixture_path
|
12
|
+
@fixture_path ||= File.join(File.dirname(__FILE__), 'fixtures')
|
13
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{streamio-ffmpeg}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David Backeus"]
|
12
|
+
s.date = %q{2010-02-05}
|
13
|
+
s.description = %q{Simple wrapper around ffmpeg to get metadata from movies and do transcoding}
|
14
|
+
s.email = %q{duztdruid@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"CHANGELOG",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/ffmpeg/movie.rb",
|
28
|
+
"lib/streamio-ffmpeg.rb",
|
29
|
+
"spec/ffmpeg/movie_spec.rb",
|
30
|
+
"spec/fixtures/movies/awesome.mov",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"streamio-ffmpeg.gemspec"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/dbackeus/streamio-ffmpeg}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Simple wrapper around ffmpeg to get metadata from movies and do transcoding}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/ffmpeg/movie_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: streamio-ffmpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Backeus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-05 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: Simple wrapper around ffmpeg to get metadata from movies and do transcoding
|
26
|
+
email: duztdruid@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- CHANGELOG
|
38
|
+
- LICENSE
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- VERSION
|
42
|
+
- lib/ffmpeg/movie.rb
|
43
|
+
- lib/streamio-ffmpeg.rb
|
44
|
+
- spec/ffmpeg/movie_spec.rb
|
45
|
+
- spec/fixtures/movies/awesome.mov
|
46
|
+
- spec/spec.opts
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
- streamio-ffmpeg.gemspec
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/dbackeus/streamio-ffmpeg
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Simple wrapper around ffmpeg to get metadata from movies and do transcoding
|
77
|
+
test_files:
|
78
|
+
- spec/ffmpeg/movie_spec.rb
|
79
|
+
- spec/spec_helper.rb
|