vcs_ruby 0.8.2 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/vcs.rb CHANGED
@@ -137,7 +137,7 @@ begin
137
137
  sheet.initialize_filename(options[:output][index]) if options[:output][index]
138
138
  sheet.build
139
139
  end
140
- rescue Exception => e
141
- STDERR.puts "ERROR: #{e.message}"
140
+ #rescue Exception => e
141
+ # STDERR.puts "ERROR: #{e.message}"
142
142
  end
143
143
 
data/lib/command.rb CHANGED
@@ -4,23 +4,33 @@
4
4
 
5
5
  module VCSRuby
6
6
  class Command
7
- attr_reader :name, :available
7
+ attr_reader :name
8
8
  def initialize name, command
9
9
  @name = name
10
10
  @command = which(command)
11
11
  @available = !!@command
12
12
  end
13
13
 
14
- def execute parameter, streams = "2> /dev/null"
15
- raise "Command '#{name}' not available" unless available
14
+ def available?
15
+ @available
16
+ end
16
17
 
18
+ def execute parameter, streams = 0
19
+ raise "Command '#{name}' not available" unless available?
20
+ result = nil
17
21
  if Tools::windows?
18
- `cmd /C #{@command} #{parameter}`
22
+ streams = '2> nul' if streams === 0
23
+
24
+ result = `cmd /C #{@command} #{parameter} #{streams}`
19
25
  else
20
- `#{@command} #{parameter} #{streams}`
26
+ streams = "2> /dev/null" if streams === 0
27
+
28
+ result =`#{@command} #{parameter} #{streams}`
21
29
  end
22
- end
23
30
 
31
+ raise "#{@command} failed with return value '#{$?}'"unless $? == 0
32
+ return result
33
+ end
24
34
  private
25
35
  # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
26
36
  def which cmd
data/lib/ffmpeg.rb CHANGED
@@ -2,24 +2,151 @@
2
2
  # FFmpeg Abstraction
3
3
  #
4
4
 
5
- require 'command'
6
5
  require 'capturer'
6
+ require 'command'
7
+ require 'time_index'
7
8
 
8
9
  module VCSRuby
9
10
  class FFmpeg < Capturer
11
+
12
+ CODEC = 3
13
+ DIMENSION = 5
14
+ FPS = 7
15
+
10
16
  def initialize video
11
17
  @video = video
12
- @command = Command.new :ffmpeg, 'ffmpeg'
18
+ @ffmpeg = Command.new :ffmpeg, 'ffmpeg'
19
+ @ffprobe = Command.new :ffmpeg, 'ffprobe'
20
+ detect_version
13
21
  end
14
22
 
15
23
  def name
16
24
  :ffmpeg
17
25
  end
18
26
 
27
+ def available?
28
+ @ffmpeg.available? && !libav?
29
+ end
30
+
31
+ def libav?
32
+ @libav
33
+ end
34
+
35
+ def detect_version
36
+ info = @ffmpeg.execute('-version')
37
+ match = /avconv ([\d|.|-|:]*)/.match(info)
38
+ @libav = true if match
39
+ match = /ffmpeg version ([\d|.]*)/.match(info)
40
+ if match
41
+ @version = match[1]
42
+ end
43
+ end
44
+
19
45
  def length
20
- info = @command.execute("-i #{@video} -dframes 0 -vframes 0 /dev/null", "2>&1")
21
- match = /Duration: ([\d|:|.]*)/.match(info)
46
+ load_probe
47
+ match = /Duration: ([\d|:|.]*)/.match(@cache)
22
48
  return TimeIndex.new match[1]
23
49
  end
50
+
51
+ def width
52
+ load_probe
53
+ @width
54
+ end
55
+
56
+ def height
57
+ load_probe
58
+ @height
59
+ end
60
+
61
+ def par
62
+ load_probe
63
+ @par
64
+ end
65
+
66
+ def dar
67
+ load_probe
68
+ @dar
69
+ end
70
+
71
+ def fps
72
+ load_probe
73
+ @fps
74
+ end
75
+
76
+ def video_codec
77
+ load_probe
78
+
79
+ @video_codec
80
+ end
81
+
82
+ def audio_codec
83
+ load_probe
84
+
85
+ @audio_codec
86
+ end
87
+
88
+ def grab time, image_path
89
+ @ffmpeg.execute "-y -ss #{time.total_seconds} -i \"#{@video}\" -an -dframes 1 -vframes 1 -vcodec png -f rawvideo \"#{image_path}\""
90
+ end
91
+
92
+ def to_s
93
+ "FFmpeg #{@version}"
94
+ end
95
+
96
+ private
97
+ def load_probe
98
+ return if @cache
99
+
100
+ @cache = @ffprobe.execute("\"#{@video}\"", "2>&1")
101
+ puts @cache if Tools.verbose?
102
+
103
+ parse_video_streams
104
+ parse_audio_streams
105
+ end
106
+
107
+ def parse_video_streams
108
+ video_stream = split_stream_line(is_stream?(@cache, /Video/).first)
109
+
110
+ dimensions = /(\d*)x(\d*) \[PAR (\d*:\d*) DAR (\d*:\d*)\]/.match(video_stream[DIMENSION])
111
+
112
+ if dimensions
113
+ @par = dimensions[3]
114
+ @dar = dimensions[4]
115
+ else
116
+ dimensions = /(\d*)x(\d*)/.match(video_stream[DIMENSION])
117
+ end
118
+
119
+ if dimensions
120
+ @width = dimensions[1].to_i
121
+ @height = dimensions[2].to_i
122
+ end
123
+
124
+ fps = /([\d|.]+) fps/.match(video_stream[FPS])
125
+ @fps = fps ? fps[1].to_f : 0.0
126
+
127
+ @video_codec = video_stream[CODEC]
128
+ end
129
+
130
+ def parse_audio_streams
131
+ audio_stream = split_stream_line(is_stream?(@cache, /Audio/).first)
132
+
133
+ @audio_codec = audio_stream[CODEC]
134
+ end
135
+
136
+ def is_stream? probe, regex
137
+ streams(probe).select{ |s| s =~ regex }
138
+ end
139
+
140
+ def streams probe
141
+ @cache.split(/\r?\n/).map(&:strip).select{|l| l.start_with? 'Stream' }
142
+ end
143
+
144
+ def split_stream_line line
145
+ parts = line.split(',')
146
+ stream = parts.shift
147
+ result = stream.split(':')
148
+ result += parts
149
+ return result.map(&:strip)
150
+ end
24
151
  end
25
152
  end
data/lib/font.rb CHANGED
@@ -15,8 +15,13 @@ module VCSRuby
15
15
  end
16
16
 
17
17
  def find_path
18
- font = `fc-list | grep #{name}`
19
- font.split(':').first.strip
18
+ if Tools::windows?
19
+ Dir.entries File.join(ENV['windir'], 'fonts')
20
+ ''
21
+ else
22
+ font = `fc-list | grep #{name}`
23
+ font.split(':').first.strip
24
+ end
20
25
  end
21
26
 
22
27
  def line_height
data/lib/libav.rb CHANGED
@@ -25,13 +25,13 @@ module VCSRuby
25
25
  end
26
26
 
27
27
  def available?
28
- @avconv.available && @avprobe.available
28
+ @avconv.available? && @avprobe.available?
29
29
  end
30
30
 
31
31
  def detect_version
32
- info = @avconv.execute("-version")
32
+ info = @avconv.execute('-version')
33
33
  match = /avconv ([\d|.|-|:]*)/.match(info)
34
- @version = match[1]
34
+ @version = match[1] if match
35
35
  end
36
36
 
37
37
  def length
@@ -78,7 +78,7 @@ module VCSRuby
78
78
  end
79
79
 
80
80
  def grab time, image_path
81
- @avconv.execute "-y -ss #{time.total_seconds} -i '#{@video}' -an -dframes 1 -vframes 1 -vcodec png -f rawvideo '#{image_path}'"
81
+ @avconv.execute "-y -ss #{time.total_seconds} -i \"#{@video}\" -an -dframes 1 -vframes 1 -vcodec png -f rawvideo \"#{image_path}\""
82
82
  end
83
83
 
84
84
  def to_s
@@ -89,7 +89,7 @@ private
89
89
  def load_probe
90
90
  return if @cache
91
91
 
92
- @cache = @avprobe.execute("'#{@video}'", "2>&1")
92
+ @cache = @avprobe.execute("\"#{@video}\"", "2>&1")
93
93
  puts @cache if Tools.verbose?
94
94
 
95
95
  parse_video_streams
data/lib/mplayer.rb CHANGED
@@ -9,11 +9,15 @@ module VCSRuby
9
9
  class MPlayer < Capturer
10
10
  def initialize video
11
11
  @video = video
12
- @command = Command.new :mplayer, 'mplayer'
12
+ @mplayer = Command.new :mplayer, 'mplayer'
13
13
  end
14
14
 
15
15
  def name
16
16
  :mplayer
17
17
  end
18
+
19
+ def available?
20
+ @mplayer.available? && false
21
+ end
18
22
  end
19
23
  end
data/lib/thumbnail.rb CHANGED
@@ -14,8 +14,7 @@ module VCSRuby
14
14
  @capper = capper
15
15
  @video = video
16
16
  @configuration = configuration
17
-
18
- @filters = [method(:resize_filter), method(:timestamp_filter), method(:softshadow_filter)]
17
+ @filters = [ method(:resize_filter), method(:timestamp_filter), method(:softshadow_filter) ]
19
18
  end
20
19
 
21
20
  def capture
@@ -93,10 +92,29 @@ private
93
92
  convert.repage.+
94
93
  end
95
94
 
96
- def polaroid_filter
95
+ def polaroid_filter convert
96
+ border = 8
97
+ convert.stack do |a|
98
+ a.fill 'White'
99
+ a.background 'White'
100
+ a.bordercolor 'White'
101
+ a.mattecolor 'White'
102
+ a.frame "#{border}x#{border}"
103
+ a.stack do |b|
104
+ b.flip
105
+ b.splice "0x#{border*5}"
106
+ end
107
+ a.flip
108
+ a.bordercolor 'Grey60'
109
+ a.border 1
110
+ a.repage.+
111
+ end
97
112
  end
98
113
 
99
- def random_rotation_filter
114
+ def random_rotation_filter convert
115
+ angle = Random::rand(-18..18)
116
+ convert.background 'None'
117
+ convert.rotate angle
100
118
  end
101
119
 
102
120
  def film_filter
data/lib/tools.rb CHANGED
@@ -5,7 +5,11 @@
5
5
  module VCSRuby
6
6
  class Tools
7
7
  def self.windows?
8
- false
8
+ return ((RUBY_PLATFORM =~ /win32/ or RUBY_PLATFORM =~ /mingw32/) or (RbConfig::CONFIG['host_os'] =~ /mswin|windows/i))
9
+ end
10
+
11
+ def self.linux?
12
+ return ((RUBY_PLATFORM =~ /linux/) or (RbConfig::CONFIG['host_os'] =~ /linux/i))
9
13
  end
10
14
 
11
15
  def self.verbose= verbose
data/lib/version.info CHANGED
@@ -1 +1 @@
1
- 0.8.3
1
+ 0.8.5
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcs_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-19 00:00:00.000000000 Z
12
+ date: 2016-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mini_magick