ffmprb 0.6.7 → 0.6.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89d245761d8d4cc634a01b2df4b24285d8d12442
4
- data.tar.gz: 9f837994c17a2b7537b1047b2cf3228b26786bc8
3
+ metadata.gz: 3c63aad2be1497ee10ff566dafaa5a76f7e8cc87
4
+ data.tar.gz: 0b6b1f15cd314f7b51fc7dbddb3b9c37f47dcdfe
5
5
  SHA512:
6
- metadata.gz: 925d6aaea191371123fe2bfa6df96ec30a2c33469f3804881c794400e8ab3681b08c9fecce3c2008702a3c9e183aa5c79fd4500569acf85a8aa7fb099fdd6659
7
- data.tar.gz: 75ccb1c89e17601d9f3c5bf767dfb9b0a88810fd8f6e74316984391ebbf3dfa5c15acda73868135e8ec0eea1e53b7a38aea1dff09589f396bee96b58d0681823
6
+ metadata.gz: 183ba570ca74223f6f5974a969ff9f2bd74fe5a8a099e34b429901773d76d7757d8c58fb8666d9444abedc5539d978b98ef22fa1c534bb9b7ba43a14665a9701
7
+ data.tar.gz: a9be63b31513b789f454931b0514c3b7601e01ac38ba71ee4a596cd82cab7b99b3547439303aace34595235e69b719550d3361830431d8091bb5df922a3c6e2b
data/lib/ffmprb/file.rb CHANGED
@@ -131,10 +131,10 @@ module Ffmprb
131
131
  raise Error, "Incorrect audio extname (must be .mp3)" unless !audio || audio.extname =~ /mp3$/
132
132
  raise Error, "Can sample either video OR audio UNLESS a block is given" unless block_given? || (!!audio != !!video)
133
133
 
134
- cmd = " -i #{path}"
135
- cmd << " -deinterlace -an -ss #{at} -r 1 -vcodec mjpeg -f mjpeg #{video.path}" if video
136
- cmd << " -vn -ss #{at} -t 1 -f mp3 #{audio.path}" if audio
137
- Util.ffmpeg cmd
134
+ cmd = ['-i', path]
135
+ cmd += ['-deinterlace', '-an', '-ss', at, '-r', 1, '-vcodec', 'mjpeg', '-f', 'mjpeg', video.path] if video
136
+ cmd += ['-vn', '-ss', at, '-t', 1, '-f', 'mp3', audio.path] if audio
137
+ Util.ffmpeg *cmd
138
138
 
139
139
  return video || audio unless block_given?
140
140
 
@@ -172,9 +172,9 @@ module Ffmprb
172
172
 
173
173
  def probe(force=false)
174
174
  return @probe unless !@probe || force
175
- cmd = " -v quiet -i #{path} -print_format json -show_format -show_streams"
176
- cmd << " -show_frames" if force
177
- @probe = JSON.parse(Util::ffprobe cmd).tap do |probe|
175
+ cmd = ['-v', 'quiet', '-i', path, '-print_format', 'json', '-show_format', '-show_streams']
176
+ cmd << '-show_frames' if force
177
+ @probe = JSON.parse(Util::ffprobe *cmd).tap do |probe|
178
178
  raise Error, "This doesn't look like a ffprobable file" unless probe['streams']
179
179
  end
180
180
  end
data/lib/ffmprb/filter.rb CHANGED
@@ -210,12 +210,8 @@ module Ffmprb
210
210
  inout filter, nil, output
211
211
  end
212
212
 
213
- def complex_options(filters)
214
- if filters.empty?
215
- ''
216
- else
217
- " -filter_complex \"#{filters.join '; '}\""
218
- end
213
+ def complex_options(*filters)
214
+ ['-filter_complex', filters.join('; ')] unless filters.empty?
219
215
  end
220
216
 
221
217
  private
@@ -114,7 +114,7 @@ module Ffmprb
114
114
  end
115
115
 
116
116
  def options
117
- " -i #{@io.path}"
117
+ ['-i', @io.path]
118
118
  end
119
119
 
120
120
  def filters_for(lbl, process:, video: true, audio: true)
@@ -238,9 +238,9 @@ module Ffmprb
238
238
  end
239
239
  io_channel_lbls.each do |io, channel_lbls|
240
240
  channel_lbls.each do |channel_lbl|
241
- options << " -map \"[#{channel_lbl}]\""
241
+ options << '-map' << "[#{channel_lbl}]"
242
242
  end
243
- options << " #{io.path}"
243
+ options << io.path
244
244
  end
245
245
 
246
246
  end
@@ -70,7 +70,7 @@ module Ffmprb
70
70
  end
71
71
 
72
72
  def run
73
- Util.ffmpeg command
73
+ Util.ffmpeg *command
74
74
  @threaded.to_a.each &:join
75
75
  end
76
76
 
@@ -93,7 +93,7 @@ module Ffmprb
93
93
  end
94
94
 
95
95
  def input_options
96
- @inputs.map(&:options).join
96
+ @inputs.map(&:options).flatten(1)
97
97
  end
98
98
 
99
99
  def output_options
data/lib/ffmprb/util.rb CHANGED
@@ -10,28 +10,32 @@ module Ffmprb
10
10
 
11
11
  class << self
12
12
 
13
- def ffprobe(args)
14
- sh "ffprobe#{args}"
13
+ attr_accessor :ffmpeg_cmd, :ffprobe_cmd
14
+
15
+ def ffprobe(*args)
16
+ sh ffprobe_cmd, *args
15
17
  end
16
18
 
17
- def ffmpeg(args)
18
- args = " -loglevel debug#{args}" if Ffmprb.debug
19
- sh "ffmpeg -y#{args}", output: :stderr
19
+ def ffmpeg(*args)
20
+ args = ['-loglevel', 'debug'] + args if Ffmprb.debug
21
+ sh ffmpeg_cmd, '-y', *args, output: :stderr
20
22
  end
21
23
 
22
- def sh(cmd, output: :stdout, log: :stderr)
23
- Ffmprb.logger.info cmd
24
- Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
24
+ def sh(*cmd, output: :stdout, log: :stderr)
25
+ cmd = cmd.to_a.map(&:to_s)
26
+ cmd_str = cmd.join(' ')
27
+ Ffmprb.logger.info cmd_str
28
+ Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
25
29
  stdin.close
26
30
 
27
31
  # XXX process timeouting/cleanup here will be appreciated
28
32
 
29
33
  begin
30
- log_cmd = "#{cmd.split(' ').first.upcase}: " if log
34
+ log_cmd = "#{(cmd.respond_to?(:first)? cmd : cmd.split(' ')).first.upcase}: " if log
31
35
  stdout_r = Reader.new(stdout, output == :stdout, log == :stdout && log_cmd)
32
36
  stderr_r = Reader.new(stderr, true, log == :stderr && log_cmd)
33
37
 
34
- raise Error, "#{cmd}:\n#{stderr_r.read}" unless
38
+ raise Error, "#{cmd_str}:\n#{stderr_r.read}" unless
35
39
  wait_thr.value.exitstatus == 0 # NOTE blocks
36
40
 
37
41
  # NOTE only one of them will return non-nil, see above
@@ -45,7 +49,7 @@ module Ffmprb
45
49
  Ffmprb.logger.error "Thread joining error: #{$!.message}"
46
50
  stderr_r.join if stdout_r
47
51
  end
48
- Ffmprb.logger.debug "FINISHED: #{cmd}"
52
+ Ffmprb.logger.debug "FINISHED: #{cmd_str}"
49
53
  end
50
54
  end
51
55
  end
@@ -1,3 +1,3 @@
1
1
  module Ffmprb
2
- VERSION = "0.6.7"
2
+ VERSION = "0.6.9"
3
3
  end
data/lib/ffmprb.rb CHANGED
@@ -19,6 +19,9 @@ module Ffmprb
19
19
  class Error < StandardError
20
20
  end
21
21
 
22
+ Util.ffmpeg_cmd = 'ffmpeg'
23
+ Util.ffprobe_cmd = 'ffprobe'
24
+
22
25
  Process.duck_audio_hi = 0.9
23
26
  Process.duck_audio_lo = 0.1
24
27
  Process.duck_audio_transition_sec = 1
@@ -59,9 +62,9 @@ module Ffmprb
59
62
  def find_silence(input_file, output_file)
60
63
  logger.debug "Finding silence (#{input_file.path}->#{output_file.path})"
61
64
  filters = Filter.silencedetect
62
- options = " -i #{input_file.path}#{Filter.complex_options filters} #{output_file.path}"
65
+ options = ['-i', input_file.path, *Filter.complex_options(filters), output_file.path]
63
66
  silence = []
64
- Util.ffmpeg(options).split("\n").each do |line|
67
+ Util.ffmpeg(*options).split("\n").each do |line|
65
68
  next unless line =~ /^\[silencedetect\s.*\]\s*silence_(\w+):\s*(\d+\.?d*)/
66
69
  case $1
67
70
  when 'start'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffmprb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - showbox.com
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-07-22 00:00:00.000000000 Z
12
+ date: 2015-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mkfifo