vidibus-fileinfo 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +87 -0
- data/Rakefile +10 -4
- data/lib/vidibus/fileinfo/base.rb +37 -0
- data/lib/vidibus/fileinfo/processor/image.rb +36 -23
- data/lib/vidibus/fileinfo/processor/video.rb +53 -19
- data/lib/vidibus/fileinfo/version.rb +1 -1
- data/lib/vidibus/fileinfo.rb +3 -3
- data/lib/vidibus-fileinfo.rb +3 -4
- metadata +50 -67
- data/.gitignore +0 -6
- data/.rspec +0 -1
- data/Gemfile +0 -4
- data/README.rdoc +0 -79
- data/spec/files/Jim-Marshall.jpg +0 -0
- data/spec/files/RevAppTest.mp4 +0 -0
- data/spec/spec_helper.rb +0 -14
- data/spec/support/files.rb +0 -9
- data/spec/support/stubs.rb +0 -4
- data/spec/vidibus/fileinfo/base_spec.rb +0 -65
- data/spec/vidibus/fileinfo/processor/image_spec.rb +0 -38
- data/spec/vidibus/fileinfo/processor/video_spec.rb +0 -57
- data/spec/vidibus/fileinfo_spec.rb +0 -131
- data/vidibus-fileinfo.gemspec +0 -31
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Vidibus::Fileinfo [](http://stillmaintained.com/vidibus/vidibus-fileinfo)
|
2
|
+
|
3
|
+
Returns information like the width, height and bits about an image or video file.
|
4
|
+
|
5
|
+
This gem is part of [Vidibus](http://vidibus.org), an open source toolset for building distributed (video) applications.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add the dependency to the Gemfile of your application:
|
10
|
+
|
11
|
+
gem "vidibus-fileinfo"
|
12
|
+
|
13
|
+
Then call bundle install on your console.
|
14
|
+
|
15
|
+
## System requirements
|
16
|
+
|
17
|
+
In order to perform the file inspection, ImageMagick and FFmpeg executables are required.
|
18
|
+
|
19
|
+
Unless ruby already knows about those tools, you'll have to define the path somewhere.
|
20
|
+
In a Rails environment, a good place would be your development.rb and production.rb.
|
21
|
+
|
22
|
+
Example for development environment on OSX:
|
23
|
+
|
24
|
+
``` shell
|
25
|
+
# Set path to ImageMagick and FFmpeg executables
|
26
|
+
ENV["PATH"] = "#{ENV["PATH"]}:/opt/local/bin"
|
27
|
+
```
|
28
|
+
|
29
|
+
Example for production environment on Debian:
|
30
|
+
|
31
|
+
``` shell
|
32
|
+
# Set path to ImageMagick and FFmpeg executables
|
33
|
+
ENV["PATH"] = "#{ENV["PATH"]}:/usr/bin/"
|
34
|
+
```
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
Obtaining information from a file is easy:
|
39
|
+
|
40
|
+
``` ruby
|
41
|
+
Fileinfo("path/to/myfile.png")
|
42
|
+
# => {:width => 300, height => 200, ... }
|
43
|
+
```
|
44
|
+
|
45
|
+
### Image files
|
46
|
+
|
47
|
+
For images, a hash with following data will be returned:
|
48
|
+
|
49
|
+
``` ruby
|
50
|
+
:width # width of image
|
51
|
+
:height # height of image
|
52
|
+
:size # file size in bytes
|
53
|
+
:bit # depth in bit
|
54
|
+
:content_type # content type of image, e.g. "jpeg"
|
55
|
+
```
|
56
|
+
|
57
|
+
This gem currently support these image formats:
|
58
|
+
|
59
|
+
```
|
60
|
+
jpg, jpeg, png, gif
|
61
|
+
```
|
62
|
+
|
63
|
+
### Video files
|
64
|
+
|
65
|
+
For videos, a different hash will be returned:
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
:width # width of video
|
69
|
+
:height # height of video
|
70
|
+
:size # file size in bytes
|
71
|
+
:duration # duration of video in seconds
|
72
|
+
:fps # frames per second
|
73
|
+
:bitrate # overall bit rate (video + audio)
|
74
|
+
:video_codec # codec of video stream, e.g. "h264"
|
75
|
+
:audio_codec # codec of audio stream, e.g. "aac"
|
76
|
+
:audio_sample_rate # sample rate of audio stream, e.g. 48000
|
77
|
+
```
|
78
|
+
|
79
|
+
These video formats are currently supported:
|
80
|
+
|
81
|
+
```
|
82
|
+
avi, flv, h261, h263, h264, ipod, m4v, mov, mp4, mpeg, mxf, ogg
|
83
|
+
```
|
84
|
+
|
85
|
+
## Copyright
|
86
|
+
|
87
|
+
Copyright (c) 2011 Andre Pankratz. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,20 +1,26 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
|
1
3
|
require "bundler"
|
2
|
-
require "
|
4
|
+
require "rdoc/task"
|
3
5
|
require "rspec"
|
4
6
|
require "rspec/core/rake_task"
|
7
|
+
|
8
|
+
require "vidibus/fileinfo/version"
|
9
|
+
|
5
10
|
Bundler::GemHelper.install_tasks
|
6
11
|
|
7
|
-
|
12
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
8
13
|
t.pattern = "spec/**/*_spec.rb"
|
9
14
|
t.rcov = true
|
10
15
|
t.rcov_opts = ["--exclude", "^spec,/gems/"]
|
11
16
|
end
|
12
17
|
|
13
18
|
Rake::RDocTask.new do |rdoc|
|
14
|
-
require File.expand_path("../lib/vidibus/fileinfo/version.rb", __FILE__)
|
15
19
|
rdoc.rdoc_dir = "rdoc"
|
16
|
-
rdoc.title = "vidibus-
|
20
|
+
rdoc.title = "vidibus-permalink #{Vidibus::Fileinfo::VERSION}"
|
17
21
|
rdoc.rdoc_files.include("README*")
|
18
22
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
19
23
|
rdoc.options << "--charset=utf-8"
|
20
24
|
end
|
25
|
+
|
26
|
+
task :default => :rcov
|
@@ -17,6 +17,11 @@ module Vidibus
|
|
17
17
|
@mime_type ||= Mime::Type.lookup_by_extension(format)
|
18
18
|
end
|
19
19
|
|
20
|
+
def data
|
21
|
+
raise PathError unless @path
|
22
|
+
@data ||= parse_metadata
|
23
|
+
end
|
24
|
+
|
20
25
|
protected
|
21
26
|
|
22
27
|
def check_file
|
@@ -28,6 +33,38 @@ module Vidibus
|
|
28
33
|
@processor = Fileinfo.processor(format)
|
29
34
|
extend @processor
|
30
35
|
end
|
36
|
+
|
37
|
+
def parse_metadata
|
38
|
+
@raw_metadata = process_cmd
|
39
|
+
|
40
|
+
metadata = {}
|
41
|
+
@processor::METADATA.each do |attribute|
|
42
|
+
begin
|
43
|
+
metadata[attribute.to_sym] = send(attribute)
|
44
|
+
rescue
|
45
|
+
raise DataError, "#{attribute}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
validate(metadata)
|
50
|
+
metadata
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_cmd
|
54
|
+
pid, stdin, stdout, stderr = POSIX::Spawn::popen4(cmd)
|
55
|
+
raw_metadata = eval("#{output}.read")
|
56
|
+
Process::waitpid(pid)
|
57
|
+
raw_metadata
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate(metadata)
|
61
|
+
raise DataError unless valid?(metadata)
|
62
|
+
end
|
63
|
+
|
64
|
+
# The video/image file size in bytes.
|
65
|
+
def size
|
66
|
+
File.size(@path)
|
67
|
+
end
|
31
68
|
end
|
32
69
|
end
|
33
70
|
end
|
@@ -3,36 +3,49 @@ module Vidibus
|
|
3
3
|
module Processor
|
4
4
|
module Image
|
5
5
|
FORMATS = %w[jpg jpeg png gif]
|
6
|
+
METADATA = %w[bit content_type height orientation quality size width]
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:content_type => values[1].downcase,
|
18
|
-
:width => dimensions[0],
|
19
|
-
:height => dimensions[1],
|
20
|
-
:bit => values[4].to_i,
|
21
|
-
:size => File.size(@path)
|
22
|
-
}
|
23
|
-
end
|
8
|
+
def cmd
|
9
|
+
"identify -verbose #{@path}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def output
|
13
|
+
:stdout
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid?(metadata)
|
17
|
+
!(metadata[:width].zero? || metadata[:height].zero?)
|
24
18
|
end
|
25
19
|
|
26
20
|
protected
|
27
21
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
def bit
|
23
|
+
/^\s*Depth:\s(\w+)-bit/.match(@raw_metadata)[1].presence.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def content_type
|
27
|
+
/^\s*Format:\s(\w+)/.match(@raw_metadata)[1].presence.downcase
|
28
|
+
end
|
29
|
+
|
30
|
+
def height
|
31
|
+
dimension[1]
|
32
|
+
end
|
33
|
+
|
34
|
+
def width
|
35
|
+
dimension[0]
|
36
|
+
end
|
37
|
+
|
38
|
+
def dimension
|
39
|
+
str = /^\s*Geometry: (\w+)/.match(@raw_metadata)[1].presence
|
40
|
+
str.split("x").map(&:to_i)
|
41
|
+
end
|
42
|
+
|
43
|
+
def orientation
|
44
|
+
/^\s*exif:Orientation:\s(\d+)/.match(@raw_metadata)[1].presence.to_i
|
32
45
|
end
|
33
46
|
|
34
|
-
def
|
35
|
-
|
47
|
+
def quality
|
48
|
+
/^\s*Quality: (\d+)/.match(@raw_metadata)[1].presence.to_i
|
36
49
|
end
|
37
50
|
end
|
38
51
|
end
|
@@ -3,26 +3,60 @@ module Vidibus
|
|
3
3
|
module Processor
|
4
4
|
module Video
|
5
5
|
FORMATS = %w[avi flv h261 h263 h264 ipod m4v mov mp4 mpeg mxf ogg]
|
6
|
+
METADATA = %w[audio_codec audio_sample_rate bitrate duration fps height
|
7
|
+
size video_codec width]
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
9
|
+
def cmd
|
10
|
+
"ffmpeg -i #{@path}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def output
|
14
|
+
:stderr
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?(metadata)
|
18
|
+
!(metadata[:width].zero? || metadata[:height].zero? || metadata[:duration].zero?)
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def audio_codec
|
24
|
+
/Audio:\s+([a-z]+),/.match(@raw_metadata)[1].presence
|
25
|
+
end
|
26
|
+
|
27
|
+
def audio_sample_rate
|
28
|
+
/(\d+)\sHz/.match(@raw_metadata)[1].presence.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
def bitrate
|
32
|
+
/bitrate:\s(\d+)\skb\/s/.match(@raw_metadata)[1].presence.to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
def duration
|
36
|
+
str = /Duration:\s+([0-9\:\.]+),/.match(@raw_metadata)[1].presence
|
37
|
+
units = str.split(":").map(&:to_f)
|
38
|
+
(units[0] * 60 * 60 * 1000) + (units[1] * 60 * 1000) + (units[2] * 1000) / 1000
|
39
|
+
end
|
40
|
+
|
41
|
+
def fps
|
42
|
+
/(\d+)\s+fps,/.match(@raw_metadata)[1].presence.to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
def height
|
46
|
+
dimension[1]
|
47
|
+
end
|
48
|
+
|
49
|
+
def width
|
50
|
+
dimension[0]
|
51
|
+
end
|
52
|
+
|
53
|
+
def dimension
|
54
|
+
str = /^.*Video:.*( \d+x\d+ ).*$/.match(@raw_metadata)[1].strip.presence
|
55
|
+
str.split("x").map(&:to_i)
|
56
|
+
end
|
57
|
+
|
58
|
+
def video_codec
|
59
|
+
/Video:\s+([a-z0-9]+),/.match(@raw_metadata).presence[1]
|
26
60
|
end
|
27
61
|
end
|
28
62
|
end
|
data/lib/vidibus/fileinfo.rb
CHANGED
data/lib/vidibus-fileinfo.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
+
require "action_dispatch/http/mime_type"
|
2
|
+
require "posix/spawn"
|
1
3
|
require "vidibus-core_extensions"
|
2
|
-
require "action_dispatch/http/mime_type.rb"
|
3
|
-
require "rvideo"
|
4
4
|
|
5
|
-
|
6
|
-
require "fileinfo"
|
5
|
+
require "vidibus/fileinfo"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidibus-fileinfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Pankratz
|
@@ -15,12 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-07 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: actionpack
|
23
|
-
prerelease: false
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
@@ -32,11 +30,11 @@ dependencies:
|
|
32
30
|
- 0
|
33
31
|
- 4
|
34
32
|
version: 3.0.4
|
35
|
-
type: :runtime
|
36
33
|
version_requirements: *id001
|
37
|
-
|
38
|
-
name: vidibus-core_extensions
|
34
|
+
name: actionpack
|
39
35
|
prerelease: false
|
36
|
+
type: :runtime
|
37
|
+
- !ruby/object:Gem::Dependency
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
@@ -46,11 +44,11 @@ dependencies:
|
|
46
44
|
segments:
|
47
45
|
- 0
|
48
46
|
version: "0"
|
49
|
-
type: :runtime
|
50
47
|
version_requirements: *id002
|
51
|
-
|
52
|
-
name: open4
|
48
|
+
name: posix-spawn
|
53
49
|
prerelease: false
|
50
|
+
type: :runtime
|
51
|
+
- !ruby/object:Gem::Dependency
|
54
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
53
|
none: false
|
56
54
|
requirements:
|
@@ -60,41 +58,41 @@ dependencies:
|
|
60
58
|
segments:
|
61
59
|
- 0
|
62
60
|
version: "0"
|
63
|
-
type: :runtime
|
64
61
|
version_requirements: *id003
|
65
|
-
|
66
|
-
name: newbamboo-rvideo
|
62
|
+
name: vidibus-core_extensions
|
67
63
|
prerelease: false
|
64
|
+
type: :runtime
|
65
|
+
- !ruby/object:Gem::Dependency
|
68
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
67
|
none: false
|
70
68
|
requirements:
|
71
69
|
- - ">="
|
72
70
|
- !ruby/object:Gem::Version
|
73
|
-
hash:
|
71
|
+
hash: 23
|
74
72
|
segments:
|
73
|
+
- 1
|
75
74
|
- 0
|
76
|
-
|
77
|
-
|
75
|
+
- 0
|
76
|
+
version: 1.0.0
|
78
77
|
version_requirements: *id004
|
79
|
-
- !ruby/object:Gem::Dependency
|
80
78
|
name: bundler
|
81
79
|
prerelease: false
|
80
|
+
type: :development
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - ~>
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
hash:
|
87
|
+
hash: 7
|
88
88
|
segments:
|
89
|
-
-
|
90
|
-
|
91
|
-
- 0
|
92
|
-
version: 1.0.0
|
93
|
-
type: :development
|
89
|
+
- 2
|
90
|
+
version: "2"
|
94
91
|
version_requirements: *id005
|
95
|
-
|
96
|
-
name: rake
|
92
|
+
name: rspec
|
97
93
|
prerelease: false
|
94
|
+
type: :development
|
95
|
+
- !ruby/object:Gem::Dependency
|
98
96
|
requirement: &id006 !ruby/object:Gem::Requirement
|
99
97
|
none: false
|
100
98
|
requirements:
|
@@ -104,29 +102,25 @@ dependencies:
|
|
104
102
|
segments:
|
105
103
|
- 0
|
106
104
|
version: "0"
|
107
|
-
type: :development
|
108
105
|
version_requirements: *id006
|
109
|
-
|
110
|
-
name: rspec
|
106
|
+
name: rr
|
111
107
|
prerelease: false
|
108
|
+
type: :development
|
109
|
+
- !ruby/object:Gem::Dependency
|
112
110
|
requirement: &id007 !ruby/object:Gem::Requirement
|
113
111
|
none: false
|
114
112
|
requirements:
|
115
|
-
- -
|
113
|
+
- - ">="
|
116
114
|
- !ruby/object:Gem::Version
|
117
|
-
hash:
|
115
|
+
hash: 3
|
118
116
|
segments:
|
119
|
-
- 2
|
120
117
|
- 0
|
121
|
-
|
122
|
-
- beta
|
123
|
-
- 20
|
124
|
-
version: 2.0.0.beta.20
|
125
|
-
type: :development
|
118
|
+
version: "0"
|
126
119
|
version_requirements: *id007
|
127
|
-
|
128
|
-
name: rr
|
120
|
+
name: rake
|
129
121
|
prerelease: false
|
122
|
+
type: :development
|
123
|
+
- !ruby/object:Gem::Dependency
|
130
124
|
requirement: &id008 !ruby/object:Gem::Requirement
|
131
125
|
none: false
|
132
126
|
requirements:
|
@@ -136,11 +130,11 @@ dependencies:
|
|
136
130
|
segments:
|
137
131
|
- 0
|
138
132
|
version: "0"
|
139
|
-
type: :development
|
140
133
|
version_requirements: *id008
|
141
|
-
|
142
|
-
name: relevance-rcov
|
134
|
+
name: rcov
|
143
135
|
prerelease: false
|
136
|
+
type: :development
|
137
|
+
- !ruby/object:Gem::Dependency
|
144
138
|
requirement: &id009 !ruby/object:Gem::Requirement
|
145
139
|
none: false
|
146
140
|
requirements:
|
@@ -150,9 +144,11 @@ dependencies:
|
|
150
144
|
segments:
|
151
145
|
- 0
|
152
146
|
version: "0"
|
153
|
-
type: :development
|
154
147
|
version_requirements: *id009
|
155
|
-
|
148
|
+
name: rdoc
|
149
|
+
prerelease: false
|
150
|
+
type: :development
|
151
|
+
description: Returns information like the width, height and bits about an image or video file.
|
156
152
|
email: andre@vidibus.com
|
157
153
|
executables: []
|
158
154
|
|
@@ -161,28 +157,15 @@ extensions: []
|
|
161
157
|
extra_rdoc_files: []
|
162
158
|
|
163
159
|
files:
|
164
|
-
- .gitignore
|
165
|
-
- .rspec
|
166
|
-
- Gemfile
|
167
|
-
- LICENSE
|
168
|
-
- README.rdoc
|
169
|
-
- Rakefile
|
170
|
-
- lib/vidibus-fileinfo.rb
|
171
|
-
- lib/vidibus/fileinfo.rb
|
172
160
|
- lib/vidibus/fileinfo/base.rb
|
173
161
|
- lib/vidibus/fileinfo/processor/image.rb
|
174
162
|
- lib/vidibus/fileinfo/processor/video.rb
|
175
163
|
- lib/vidibus/fileinfo/version.rb
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
- spec/vidibus/fileinfo/base_spec.rb
|
182
|
-
- spec/vidibus/fileinfo/processor/image_spec.rb
|
183
|
-
- spec/vidibus/fileinfo/processor/video_spec.rb
|
184
|
-
- spec/vidibus/fileinfo_spec.rb
|
185
|
-
- vidibus-fileinfo.gemspec
|
164
|
+
- lib/vidibus/fileinfo.rb
|
165
|
+
- lib/vidibus-fileinfo.rb
|
166
|
+
- LICENSE
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
186
169
|
has_rdoc: true
|
187
170
|
homepage: https://github.com/vidibus/vidibus-fileinfo
|
188
171
|
licenses: []
|
@@ -214,8 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
197
|
version: 1.3.6
|
215
198
|
requirements: []
|
216
199
|
|
217
|
-
rubyforge_project:
|
218
|
-
rubygems_version: 1.
|
200
|
+
rubyforge_project:
|
201
|
+
rubygems_version: 1.6.2
|
219
202
|
signing_key:
|
220
203
|
specification_version: 3
|
221
204
|
summary: Returns information about an image or video file.
|
data/.gitignore
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--format nested
|
data/Gemfile
DELETED
data/README.rdoc
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
= Vidibus::Fileinfo
|
2
|
-
|
3
|
-
Returns various information on image and video files.
|
4
|
-
|
5
|
-
This gem is part of the open source service-oriented {video framework}[http://vidibus.org] Vidibus.
|
6
|
-
|
7
|
-
|
8
|
-
== Installation
|
9
|
-
|
10
|
-
Add the dependency to the Gemfile of your application:
|
11
|
-
|
12
|
-
gem "vidibus-fileinfo"
|
13
|
-
|
14
|
-
Then call bundle install on your console.
|
15
|
-
|
16
|
-
|
17
|
-
== System requirements
|
18
|
-
|
19
|
-
In order to perform the file inspection, ImageMagick and FFmpeg executables are required.
|
20
|
-
|
21
|
-
Unless ruby already knows about those tools, you'll have to define the path somewhere.
|
22
|
-
In a Rails environment, a good place would be your development.rb and production.rb.
|
23
|
-
|
24
|
-
Example for development environment on OSX:
|
25
|
-
|
26
|
-
# Set path to ImageMagick and FFmpeg executables
|
27
|
-
ENV["PATH"] = "#{ENV["PATH"]}:/opt/local/bin"
|
28
|
-
|
29
|
-
Example for production environment on Debian:
|
30
|
-
|
31
|
-
# Set path to ImageMagick and FFmpeg executables
|
32
|
-
ENV["PATH"] = "#{ENV["PATH"]}:/usr/bin/"
|
33
|
-
|
34
|
-
|
35
|
-
== Usage
|
36
|
-
|
37
|
-
Obtaining information from a file is easy:
|
38
|
-
|
39
|
-
Fileinfo("path/to/myfile.png")
|
40
|
-
# => {:width => 300, height => 200, ... }
|
41
|
-
|
42
|
-
|
43
|
-
=== Image files
|
44
|
-
|
45
|
-
For images, a hash with following data will be returned:
|
46
|
-
|
47
|
-
:width # width of image
|
48
|
-
:height # height of image
|
49
|
-
:size # file size in bytes
|
50
|
-
:bit # depth in bit
|
51
|
-
:content_type # content type of image, e.g. "jpeg"
|
52
|
-
|
53
|
-
This gem currently support these image formats:
|
54
|
-
|
55
|
-
jpg, jpeg, png, gif
|
56
|
-
|
57
|
-
|
58
|
-
=== Video files
|
59
|
-
|
60
|
-
For videos, a different hash will be returned:
|
61
|
-
|
62
|
-
:width # width of video
|
63
|
-
:height # height of video
|
64
|
-
:size # file size in bytes
|
65
|
-
:duration # duration of video in seconds
|
66
|
-
:fps # frames per second
|
67
|
-
:bitrate # overall bit rate (video + audio)
|
68
|
-
:video_codec # codec of video stream, e.g. "h264"
|
69
|
-
:audio_codec # codec of audio stream, e.g. "aac"
|
70
|
-
:audio_sample_rate # sample rate of audio stream, e.g. 48000
|
71
|
-
|
72
|
-
These video formats are currently supported:
|
73
|
-
|
74
|
-
avi, flv, h261, h263, h264, ipod, m4v, mov, mp4, mpeg, mxf, ogg
|
75
|
-
|
76
|
-
|
77
|
-
== Copyright
|
78
|
-
|
79
|
-
Copyright (c) 2011 Andre Pankratz. See LICENSE for details.
|
data/spec/files/Jim-Marshall.jpg
DELETED
Binary file
|
data/spec/files/RevAppTest.mp4
DELETED
Binary file
|
data/spec/spec_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "rspec"
|
6
|
-
require "rr"
|
7
|
-
require "vidibus-fileinfo"
|
8
|
-
|
9
|
-
require "support/stubs"
|
10
|
-
require "support/files"
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
config.mock_with :rr
|
14
|
-
end
|
data/spec/support/files.rb
DELETED
data/spec/support/stubs.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Vidibus::Fileinfo::Base do
|
4
|
-
let(:subject) {Vidibus::Fileinfo::Base}
|
5
|
-
let(:jpg_info) {subject.new(jpg_path)}
|
6
|
-
|
7
|
-
describe "initializing" do
|
8
|
-
it "should require one param" do
|
9
|
-
expect {subject.new}.to raise_error(ArgumentError)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise an error if file is not accessible" do
|
13
|
-
expect {
|
14
|
-
subject.new("something")
|
15
|
-
}.to raise_error(Vidibus::Fileinfo::FileAccessError)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should raise an error if file is a directory" do
|
19
|
-
expect {
|
20
|
-
subject.new(File.dirname(__FILE__))
|
21
|
-
}.to raise_error(Vidibus::Fileinfo::NoFileError)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should raise an error if file format is not supported" do
|
25
|
-
stub_file("/what.ever")
|
26
|
-
expect {
|
27
|
-
subject.new("/what.ever")
|
28
|
-
}.to raise_error(Vidibus::Fileinfo::UnsupportedFormatError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should pass if file is valid" do
|
32
|
-
subject.new(jpg_path).should be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should allow access to the processor's methods" do
|
36
|
-
jpg_info.should respond_to(:data)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#format" do
|
41
|
-
it "should return the current file's format" do
|
42
|
-
mock(Vidibus::Fileinfo).format(jpg_path) {"jpg"}
|
43
|
-
jpg_info.format
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#mime_type" do
|
48
|
-
it "should return the current file's mime type" do
|
49
|
-
mock(Mime::Type).lookup_by_extension("jpg") {"image/jpeg"}
|
50
|
-
jpg_info.mime_type
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#path" do
|
55
|
-
it "should return the current file's path" do
|
56
|
-
jpg_info.path.should eql(jpg_path)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#processor" do
|
61
|
-
it "should return the matching processor for given file" do
|
62
|
-
jpg_info.processor.should eql(Vidibus::Fileinfo::Processor::Image)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Vidibus::Fileinfo::Processor::Image do
|
4
|
-
let(:subject) {Vidibus::Fileinfo::Base.new(jpg_path)}
|
5
|
-
|
6
|
-
describe "FORMATS" do
|
7
|
-
it "should include various image formats" do
|
8
|
-
Vidibus::Fileinfo::Processor::Image::FORMATS.should eql(%w[jpg jpeg png gif])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#data" do
|
13
|
-
it "should require @path to be defined" do
|
14
|
-
subject.instance_variable_set("@path", nil)
|
15
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::PathError)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should raise an error if ImageMagick fails to extract any data" do
|
19
|
-
stub(subject).perform {""}
|
20
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should raise an error if ImageMagick fails to extract dimensions" do
|
24
|
-
stub(subject).perform {"Something"}
|
25
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return a hash of image attributes" do
|
29
|
-
subject.data.should eql({
|
30
|
-
:content_type => "jpeg",
|
31
|
-
:width => 30,
|
32
|
-
:height => 23,
|
33
|
-
:bit => 8,
|
34
|
-
:size => 14822
|
35
|
-
})
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Vidibus::Fileinfo::Processor::Video do
|
4
|
-
let(:subject) {Vidibus::Fileinfo::Base.new(mp4_path)}
|
5
|
-
|
6
|
-
describe "FORMATS" do
|
7
|
-
it "should include various image formats" do
|
8
|
-
Vidibus::Fileinfo::Processor::Video::FORMATS.should eql(%w[avi flv h261 h263 h264 ipod m4v mov mp4 mpeg mxf ogg])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#data" do
|
13
|
-
it "should require @path to be defined" do
|
14
|
-
subject.instance_variable_set("@path", nil)
|
15
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::PathError)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should call RVideo::Inspector.new" do
|
19
|
-
mock(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => "10", :height => "10", :duration => "10")}
|
20
|
-
subject.data
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should raise an error if RVideo::Inspector returns nothing" do
|
24
|
-
stub(RVideo::Inspector).new(:file => mp4_path) {}
|
25
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should raise an error if RVideo::Inspector fails to extract height" do
|
29
|
-
stub(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => "10", :height => nil, :duration => "10")}
|
30
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should raise an error if RVideo::Inspector fails to extract width" do
|
34
|
-
stub(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => nil, :height => "10", :duration => "10")}
|
35
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should raise an error if RVideo::Inspector fails to extract duration" do
|
39
|
-
stub(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => "10", :height => "10", :duration => nil)}
|
40
|
-
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return a hash of image attributes" do
|
44
|
-
subject.data.should eql({
|
45
|
-
:video_codec => "mpeg4",
|
46
|
-
:audio_codec => "aac",
|
47
|
-
:audio_sample_rate => 48000,
|
48
|
-
:height => 405,
|
49
|
-
:width => 720,
|
50
|
-
:fps => 25.0,
|
51
|
-
:duration => 1.92,
|
52
|
-
:bitrate => 602,
|
53
|
-
:size => 144631
|
54
|
-
})
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Vidibus::Fileinfo do
|
4
|
-
let(:subject) {Vidibus::Fileinfo}
|
5
|
-
|
6
|
-
describe ".processors" do
|
7
|
-
it "should return a list of available processor classes" do
|
8
|
-
subject.processors.should eql([Vidibus::Fileinfo::Processor::Image, Vidibus::Fileinfo::Processor::Video])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe ".formats" do
|
13
|
-
it "should return a list of processable file formats" do
|
14
|
-
subject.formats.should eql(%w[avi flv gif h261 h263 h264 ipod jpeg jpg m4v mov mp4 mpeg mxf ogg png])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".processor" do
|
19
|
-
it "should require a format" do
|
20
|
-
expect {subject.processor}.to raise_error(ArgumentError)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should return the image processor for an image format" do
|
24
|
-
subject.processor("jpg").should eql(Vidibus::Fileinfo::Processor::Image)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should return the video processor for a video format" do
|
28
|
-
subject.processor("mp4").should eql(Vidibus::Fileinfo::Processor::Video)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should raise an error for unsupported file formats" do
|
32
|
-
expect {
|
33
|
-
subject.processor("xxx")
|
34
|
-
}.to raise_error(Vidibus::Fileinfo::UnsupportedFormatError)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe ".format" do
|
39
|
-
it "should require a path" do
|
40
|
-
expect {subject.format}.to raise_error(ArgumentError)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return the format of a given file path" do
|
44
|
-
subject.format("/my/face.jpg").should eql("jpg")
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return the format in lower case" do
|
48
|
-
subject.format("/my/face.JPG").should eql("jpg")
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should raise an error if no format can be detected" do
|
52
|
-
expect {
|
53
|
-
subject.format("/my/face")
|
54
|
-
}.to raise_error(Vidibus::Fileinfo::NoFormatError)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe ".bytes" do
|
59
|
-
it "should require a value" do
|
60
|
-
expect {subject.bytes}.to raise_error(ArgumentError)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should return input number" do
|
64
|
-
subject.bytes(1).should eql(1)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should return a rounded input float" do
|
68
|
-
subject.bytes(1.5).should eql(2)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should parse '18942'" do
|
72
|
-
subject.bytes("18942").should eql(18942)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should parse '135 B'" do
|
76
|
-
subject.bytes("135 B").should eql(135)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should parse '1 kB'" do
|
80
|
-
subject.bytes("1 kB").should eql(1024)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should parse '2KB'" do
|
84
|
-
subject.bytes("2KB").should eql(2048)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should parse '2.4k'" do
|
88
|
-
subject.bytes("2.4k").should eql(2458)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should parse '0.23 MB'" do
|
92
|
-
subject.bytes("0.23 MB").should eql(241172)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should parse '5 M'" do
|
96
|
-
subject.bytes("5 M").should eql(5242880)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should parse '1.4gb'" do
|
100
|
-
subject.bytes("1.4482gb").should eql(1554992910)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should parse '4G'" do
|
104
|
-
subject.bytes("4G").should eql(4294967296)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should parse '0.0002 TB'" do
|
108
|
-
subject.bytes("0.0002 TB").should eql(219902326)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should parse '4t'" do
|
112
|
-
subject.bytes("4t").should eql(4398046511104)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should raise an error for unsupported values" do
|
116
|
-
expect {subject.bytes([4.5])}.to raise_error(ArgumentError)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should raise an error for unsupported units" do
|
120
|
-
expect {subject.bytes("5.2 flop/s")}.to raise_error(Vidibus::Fileinfo::UnitError)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "Fileinfo" do
|
126
|
-
it "should be a shorthand for Vidibus::Fileinfo::Base.new and return file data" do
|
127
|
-
mock(Vidibus::Fileinfo::Base).new("/my/face.jpg") {OpenStruct.new}
|
128
|
-
stub.any_instance_of(OpenStruct).data {{:some => "thing"}}
|
129
|
-
Fileinfo("/my/face.jpg").should eql({:some => "thing"})
|
130
|
-
end
|
131
|
-
end
|
data/vidibus-fileinfo.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path("../lib/vidibus/fileinfo/version", __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "vidibus-fileinfo"
|
6
|
-
s.version = Vidibus::Fileinfo::VERSION
|
7
|
-
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = "Andre Pankratz"
|
9
|
-
s.email = "andre@vidibus.com"
|
10
|
-
s.homepage = "https://github.com/vidibus/vidibus-fileinfo"
|
11
|
-
s.summary = "Returns information about an image or video file."
|
12
|
-
s.description = "Gets width, height, bits and other figures."
|
13
|
-
|
14
|
-
s.required_rubygems_version = ">= 1.3.6"
|
15
|
-
s.rubyforge_project = "vidibus-fileinfo"
|
16
|
-
|
17
|
-
s.add_dependency "actionpack", "~> 3.0.4"
|
18
|
-
s.add_dependency "vidibus-core_extensions"
|
19
|
-
s.add_dependency "open4"
|
20
|
-
s.add_dependency "newbamboo-rvideo"
|
21
|
-
|
22
|
-
s.add_development_dependency "bundler", ">= 1.0.0"
|
23
|
-
s.add_development_dependency "rake"
|
24
|
-
s.add_development_dependency "rspec", "~> 2.0.0.beta.20"
|
25
|
-
s.add_development_dependency "rr"
|
26
|
-
s.add_development_dependency "relevance-rcov"
|
27
|
-
|
28
|
-
s.files = `git ls-files`.split("\n")
|
29
|
-
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
30
|
-
s.require_path = 'lib'
|
31
|
-
end
|