vidibus-fileinfo 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -51,7 +51,7 @@ For images, a hash with following data will be returned:
51
51
  :height # height of image
52
52
  :size # file size in bytes
53
53
  :bit # depth in bit
54
- :content_type # content type of image, e.g. "jpeg"
54
+ :content_type # content type of image, e.g. "image/jpeg"
55
55
  :orientation # visual position e.g. 6 (right top). See "Exif orientation" for more
56
56
  :quality # quality of image
57
57
  ```
@@ -67,10 +67,12 @@ jpg, jpeg, png, gif
67
67
  For videos, a different hash will be returned:
68
68
 
69
69
  ``` ruby
70
- :width # width of video
70
+ :width # width of video (without anamorphosis)
71
71
  :height # height of video
72
+ :aspect_ratio # aspect ratio of video on display (DAR)
72
73
  :size # file size in bytes
73
74
  :duration # duration of video in seconds
75
+ :content_type # content type of video, e.g. "video/mp4"
74
76
  :fps # frames per second
75
77
  :bitrate # overall bit rate (video + audio)
76
78
  :video_codec # codec of video stream, e.g. "h264"
@@ -81,9 +83,9 @@ For videos, a different hash will be returned:
81
83
  These video formats are currently supported:
82
84
 
83
85
  ```
84
- avi, flv, h261, h263, h264, ipod, m4v, mov, mp4, mpeg, mxf, ogg
86
+ 3g2, 3gp, asf, avi, dv, f4p, f4v, flv, ivf, m21, mj2, mjpg, mkv, mov, mp4, mpeg, mpg, mxf, ogg, ogv, rm, ts, webm, wmv
85
87
  ```
86
88
 
87
89
  ## Copyright
88
90
 
89
- Copyright (c) 2011 Andre Pankratz. See LICENSE for details.
91
+ Copyright (c) 2011-2012 Andre Pankratz. See LICENSE for details.
@@ -2,8 +2,14 @@ module Vidibus
2
2
  module Fileinfo
3
3
  module Processor
4
4
  module Video
5
- FORMATS = %w[3g2 3gp asf avi dv f4p f4v flv ivf m21 mj2 mjpg mkv mov mp4 mpeg mpg mxf ogg ogv rm ts webm wmv]
6
- METADATA = %w[audio_codec audio_sample_rate content_type bitrate duration fps height size video_codec width]
5
+ FORMATS = %w[
6
+ 3g2 3gp asf avi dv f4p f4v flv ivf m21 mj2 mjpg mkv mov mp4 mpeg mpg
7
+ mxf ogg ogv rm ts webm wmv
8
+ ]
9
+ METADATA = %w[
10
+ aspect_ratio audio_codec audio_sample_rate content_type bit_rate bitrate
11
+ duration fps frame_rate height size video_codec width
12
+ ]
7
13
 
8
14
  # FFmpeg command
9
15
  def cmd
@@ -30,16 +36,51 @@ module Vidibus
30
36
  end
31
37
  end
32
38
 
33
- def bitrate
39
+ # Return the bit rate defined as "bitrate". Calculate it from
40
+ # file size and duration otherwise.
41
+ def bit_rate
34
42
  if match = @raw_metadata[/bitrate:\s(\d+)\skb\/s/, 1]
35
43
  match.to_i
44
+ elsif duration && duration > 0
45
+ (size.to_f/125/duration).round # /125 = /1000 (kB) *8 (bit)
36
46
  end
37
47
  end
48
+ alias :bitrate :bit_rate
38
49
 
39
50
  def content_type
40
51
  super('video')
41
52
  end
42
53
 
54
+ # Return display aspect ratio defined as DAR.
55
+ # If no value is defined, calculate it from dimensions.
56
+ # If no dimensions are given, nothing is returned.
57
+ def aspect_ratio
58
+ if matches = @raw_metadata.match(/DAR\s+([0-9]+):([0-9]+)/)
59
+ w = $1.to_f
60
+ h = $2.to_f
61
+ elsif dimension
62
+ w = dimension[0].to_f
63
+ h = dimension[1].to_f
64
+ end
65
+ if w && h && w > 0 && h > 0
66
+ w/h
67
+ end
68
+ end
69
+
70
+ # Return pixel aspect ratio defined as PAR.
71
+ # If no value is defined, 1.0 will be returned.
72
+ def pixel_aspect_ratio
73
+ ar = 1.0
74
+ if matches = @raw_metadata.match(/PAR\s+([0-9]+):([0-9]+)/)
75
+ w = $1.to_f
76
+ h = $2.to_f
77
+ if w > 0 && h > 0
78
+ ar = w/h
79
+ end
80
+ end
81
+ ar
82
+ end
83
+
43
84
  def duration
44
85
  if match = @raw_metadata[/Duration:\s+([0-9\:\.]+),/, 1]
45
86
  units = match.split(":").map(&:to_f)
@@ -48,25 +89,34 @@ module Vidibus
48
89
  end
49
90
  end
50
91
 
51
- def fps
92
+ def frame_rate
52
93
  match = @raw_metadata[/([\d\.]+)\s+fps,/, 1]
53
94
  match ||= @raw_metadata[/([\d\.]+)\s+tbr,/, 1]
54
95
  if match
55
96
  match.to_f
56
97
  end
57
98
  end
99
+ alias :fps :frame_rate
58
100
 
59
101
  def height
60
102
  dimension[1] if dimension
61
103
  end
62
104
 
105
+ # Return height from dimensions and apply
106
+ # pixel aspect ratio.
63
107
  def width
64
- dimension[0] if dimension
108
+ if dimension
109
+ w = dimension[0]
110
+ if pixel_aspect_ratio != 1
111
+ return (w * pixel_aspect_ratio).round
112
+ end
113
+ w
114
+ end
65
115
  end
66
116
 
67
117
  def dimension
68
118
  if match = @raw_metadata[/^.*Video:.*?,.*?(\d+x\d+)/, 1]
69
- match.strip.split("x").map(&:to_i)
119
+ match.strip.split('x').map(&:to_i)
70
120
  end
71
121
  end
72
122
 
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Fileinfo
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
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: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-22 00:00:00 +01:00
18
+ date: 2012-04-12 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency