mediakit 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -10
- data/lib/mediakit/drivers.rb +1 -1
- data/lib/mediakit/ffmpeg.rb +7 -2
- data/lib/mediakit/ffmpeg/options.rb +4 -3
- data/lib/mediakit/initializers/ffmpeg.rb +4 -4
- data/lib/mediakit/process/runner.rb +8 -12
- data/lib/mediakit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8c1d2feb0c883e753a129e9604a25a51d30f200
|
4
|
+
data.tar.gz: ee908ed8e9b9d53feb99d7f421521f8a98552b44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a74f24782c40f1a5aff0765c4ec36866daac73222b9ab39cb4d1fa94add35bd4dde103c55c62c655b3569b97e1a1e91ad657d052a64d711a5f88a2aaaf576bd
|
7
|
+
data.tar.gz: a9d135f3fc6c6e0ed555da249d0a82a32eacc245cc7624b78ad2e9fcfa8bc62fc1f1c459797ce7e951c396c017edb4a4bb3c031ef8132390389036b2eaffb120
|
data/README.md
CHANGED
@@ -61,15 +61,10 @@ but can pass certain it.
|
|
61
61
|
driver = Mediakit::Drivers::FFmpeg.new()
|
62
62
|
ffmpeg = Mediakit::FFmpeg.new(driver)
|
63
63
|
|
64
|
-
options = Mediakit::FFmpeg::Options.new
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
),
|
69
|
-
Mediakit::FFmpeg::Options::InputFileOption.new(
|
70
|
-
options: nil,
|
71
|
-
path: input,
|
72
|
-
),
|
64
|
+
options = Mediakit::FFmpeg::Options.new
|
65
|
+
options.add_option(Mediakit::FFmpeg::Options::GlobalOption.new('t' => 100))
|
66
|
+
options.add_option(Mediakit::FFmpeg::Options::InputFileOption.new(options: nil, path: input))
|
67
|
+
options.add_option(
|
73
68
|
Mediakit::FFmpeg::Options::OutputFileOption.new(
|
74
69
|
options: {
|
75
70
|
'vf' => 'crop=320:320:0:0',
|
@@ -77,7 +72,7 @@ options = Mediakit::FFmpeg::Options.new(
|
|
77
72
|
'ab' => '128k',
|
78
73
|
},
|
79
74
|
path: output,
|
80
|
-
)
|
75
|
+
)
|
81
76
|
)
|
82
77
|
puts "$ #{ffmpeg.command(options)}"
|
83
78
|
puts ffmpeg.run(options, timeout: 30, nice: 0)
|
data/lib/mediakit/drivers.rb
CHANGED
@@ -35,7 +35,7 @@ module Mediakit
|
|
35
35
|
options, rest_args = parse_options(args.dup)
|
36
36
|
runner = Mediakit::Process::Runner.new(options)
|
37
37
|
begin
|
38
|
-
stdout, stderr
|
38
|
+
exit_status, stdout, stderr = runner.run(bin, *rest_args)
|
39
39
|
raise(FailError, stderr) unless exit_status
|
40
40
|
stdout
|
41
41
|
rescue Mediakit::Process::Runner::CommandNotFoundError => e
|
data/lib/mediakit/ffmpeg.rb
CHANGED
@@ -7,6 +7,11 @@ module Mediakit
|
|
7
7
|
class FFmpegError < StandardError;
|
8
8
|
end
|
9
9
|
|
10
|
+
class << self
|
11
|
+
attr_accessor(:default_global_option)
|
12
|
+
end
|
13
|
+
self.default_global_option = Options::GlobalOption.new('y' => true)
|
14
|
+
|
10
15
|
attr_reader(:codecs, :formats, :decoders, :encoders)
|
11
16
|
|
12
17
|
def self.create(driver = Mediakit::Drivers::FFmpeg.new)
|
@@ -26,12 +31,12 @@ module Mediakit
|
|
26
31
|
#
|
27
32
|
# @param [Mediakit::Runners::FFmpeg::Options] options options to create CLI argument
|
28
33
|
def run(options, driver_options = {})
|
29
|
-
args = options.compose
|
34
|
+
args = options.compose(self.class.default_global_option)
|
30
35
|
@driver.run(args, driver_options)
|
31
36
|
end
|
32
37
|
|
33
38
|
def command(options, driver_options = {})
|
34
|
-
args = options.compose
|
39
|
+
args = options.compose(self.class.default_global_option)
|
35
40
|
@driver.command(args, driver_options)
|
36
41
|
end
|
37
42
|
|
@@ -36,9 +36,10 @@ module Mediakit
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def compose
|
39
|
+
def compose(default_global = GlobalOption.new)
|
40
|
+
merged_global = global ? default_global.merge(global) : default_global
|
40
41
|
composed_string = ''
|
41
|
-
composed_string << "#{
|
42
|
+
composed_string << "#{merged_global}"
|
42
43
|
composed_string << " #{inputs.map(&:compose).join(' ')}" if inputs && !inputs.empty?
|
43
44
|
composed_string << " #{output}" if output
|
44
45
|
composed_string
|
@@ -155,7 +156,7 @@ module Mediakit
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def to_s
|
158
|
-
"
|
159
|
+
"'#{@string}'"
|
159
160
|
end
|
160
161
|
end
|
161
162
|
|
@@ -59,7 +59,7 @@ module Mediakit
|
|
59
59
|
|
60
60
|
def raw_items
|
61
61
|
options = Mediakit::FFmpeg::Options.new(Mediakit::FFmpeg::Options::GlobalOption.new('formats' => true))
|
62
|
-
output
|
62
|
+
output = @command.run(options, logger: nil)
|
63
63
|
return [] if output.nil? || output.empty?
|
64
64
|
output.split(DELIMITER_FOR_FORMATS)[1].each_line.to_a
|
65
65
|
end
|
@@ -101,7 +101,7 @@ module Mediakit
|
|
101
101
|
|
102
102
|
def raw_items
|
103
103
|
options = Mediakit::FFmpeg::Options.new(Mediakit::FFmpeg::Options::GlobalOption.new('decoders' => true))
|
104
|
-
output
|
104
|
+
output = @command.run(options, logger: nil)
|
105
105
|
return [] if output.nil? || output.empty?
|
106
106
|
output.split(DELIMITER_FOR_CODER)[1].each_line.to_a
|
107
107
|
end
|
@@ -159,7 +159,7 @@ module Mediakit
|
|
159
159
|
|
160
160
|
def raw_items
|
161
161
|
options = Mediakit::FFmpeg::Options.new(Mediakit::FFmpeg::Options::GlobalOption.new('encoders' => true))
|
162
|
-
output
|
162
|
+
output = @command.run(options, logger: nil)
|
163
163
|
return [] if output.nil? || output.empty?
|
164
164
|
output.split(DELIMITER_FOR_CODER)[1].each_line.to_a
|
165
165
|
end
|
@@ -209,7 +209,7 @@ module Mediakit
|
|
209
209
|
|
210
210
|
def raw_items
|
211
211
|
options = Mediakit::FFmpeg::Options.new(Mediakit::FFmpeg::Options::GlobalOption.new('codecs' => true))
|
212
|
-
output
|
212
|
+
output = @command.run(options, logger: nil)
|
213
213
|
return [] if output.nil? || output.empty?
|
214
214
|
output.split(DELIMITER_FOR_CODECS)[1].each_line.to_a
|
215
215
|
end
|
@@ -29,28 +29,28 @@ module Mediakit
|
|
29
29
|
# @overload run(command, args)
|
30
30
|
# @param command [String] command name
|
31
31
|
# @param args [Array] args as string
|
32
|
-
# @return out [String] stdout of command
|
33
|
-
# @return err [String] stderr of command
|
32
|
+
# @return out [String] stdout and stderr of command
|
34
33
|
# @return exit_status [Boolean] is succeeded
|
35
34
|
def run(bin, *args)
|
36
35
|
command = build_command(bin, *args)
|
37
36
|
begin
|
38
37
|
stdin, stdout, stderr, wait_thread = Open3.popen3(command)
|
39
38
|
stdin.close
|
40
|
-
output, error_output
|
39
|
+
exit_status, output, error_output = wait(stdout, stderr, wait_thread)
|
41
40
|
rescue Errno::ENOENT => e
|
42
41
|
raise(CommandNotFoundError, "Can't find command - #{command}, #{e.meessage}")
|
43
42
|
end
|
44
43
|
|
45
|
-
[output, error_output
|
44
|
+
[exit_status, output, error_output]
|
46
45
|
end
|
47
46
|
|
48
47
|
def wait(stdout, stderr, wait_thread)
|
49
48
|
begin
|
50
|
-
setup_watchers(
|
49
|
+
setup_watchers(stderr)
|
51
50
|
loop_thread = Thread.new { run_loop }
|
52
51
|
wait_thread.join
|
53
52
|
exit_status = (wait_thread.value.exitstatus == 0)
|
53
|
+
output = stdout.read
|
54
54
|
rescue Timeout::Error => error
|
55
55
|
force_kill_process(wait_thread.pid)
|
56
56
|
raise(error)
|
@@ -59,7 +59,7 @@ module Mediakit
|
|
59
59
|
loop_thread.join if loop_thread
|
60
60
|
end
|
61
61
|
|
62
|
-
[
|
62
|
+
[exit_status, output, @out_watcher.data]
|
63
63
|
end
|
64
64
|
|
65
65
|
def build_command(bin, *args)
|
@@ -76,13 +76,11 @@ module Mediakit
|
|
76
76
|
"#{bin} #{escaped_args}"
|
77
77
|
end
|
78
78
|
|
79
|
-
def setup_watchers(
|
79
|
+
def setup_watchers(stderr)
|
80
80
|
@timer = @timeout ? TimeoutTimer.new(@timeout, Thread.current) : nil
|
81
|
-
@out_watcher = IOWatcher.new(
|
82
|
-
@err_watcher = IOWatcher.new(stderr) { |data| @timer.update if @timer; logger.error(data) }
|
81
|
+
@out_watcher = IOWatcher.new(stderr) { |data| @timer.update if @timer; logger.info(data); }
|
83
82
|
@loop = Coolio::Loop.new
|
84
83
|
@out_watcher.attach(@loop)
|
85
|
-
@err_watcher.attach(@loop)
|
86
84
|
@timer.attach(@loop) if @timer
|
87
85
|
end
|
88
86
|
|
@@ -90,7 +88,6 @@ module Mediakit
|
|
90
88
|
@loop.run
|
91
89
|
rescue => e
|
92
90
|
# workaround for ambiguous RuntimeError
|
93
|
-
# TODO: replace logger method
|
94
91
|
logger.warn(e.message)
|
95
92
|
logger.warn(e.backtrace.join("\n"))
|
96
93
|
end
|
@@ -98,7 +95,6 @@ module Mediakit
|
|
98
95
|
def teardown_watchers
|
99
96
|
@loop.watchers.each { |w| w.detach if w.attached? }
|
100
97
|
@out_watcher.close if @out_watcher && !@out_watcher.closed?
|
101
|
-
@err_watcher.close if @err_watcher && !@err_watcher.closed?
|
102
98
|
@loop.stop if @loop.has_active_watchers?
|
103
99
|
rescue RuntimeError => e
|
104
100
|
logger.warn(e.message)
|
data/lib/mediakit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediakit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ainame
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|