diff options
author | Eric Wong <e@80x24.org> | 2023-09-04 06:21:52 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2024-01-27 22:18:19 +0000 |
commit | b8f99198b49c162920f2c28e0aa0da4eff8f14a7 (patch) | |
tree | 19650bc42bc3580b2077c3ef7b3d9fcf335d3cd6 | |
parent | 467b6941c7e9b5ecc299f92c7fa2f32d9326ba11 (diff) | |
download | dtas-b8f99198b49c162920f2c28e0aa0da4eff8f14a7.tar.gz |
As with soxi(1), waiting for ffprobe(1) or avprobe(1) is still an expensive operation despite Process.spawn being optimized to use vfork(2).
-rw-r--r-- | lib/dtas/source/av.rb | 1 | ||||
-rw-r--r-- | lib/dtas/source/av_ff_common.rb | 19 | ||||
-rw-r--r-- | lib/dtas/source/ff.rb | 1 |
3 files changed, 18 insertions, 3 deletions
diff --git a/lib/dtas/source/av.rb b/lib/dtas/source/av.rb index e05c695..dcebcfd 100644 --- a/lib/dtas/source/av.rb +++ b/lib/dtas/source/av.rb @@ -18,6 +18,7 @@ class DTAS::Source::Av # :nodoc: def initialize command_init(AV_DEFAULTS) + @mcache = nil @av_ff_probe = "avprobe" end diff --git a/lib/dtas/source/av_ff_common.rb b/lib/dtas/source/av_ff_common.rb index f67ab83..c600c48 100644 --- a/lib/dtas/source/av_ff_common.rb +++ b/lib/dtas/source/av_ff_common.rb @@ -21,10 +21,23 @@ module DTAS::Source::AvFfCommon # :nodoc: attr_reader :format attr_reader :duration + CACHE_KEYS = [ :@duration, :@probe_harder, :@comments, :@astreams, + :@format ].freeze + + def mcache_lookup(infile) + (@mcache ||= DTAS::Mcache.new).lookup(infile) do |input, dst| + tmp = source_file_dup(infile, nil, nil) + tmp.av_ff_ok? or return nil + CACHE_KEYS.each { |k| dst[k] = tmp.instance_variable_get(k) } + dst + end + end + def try(infile, offset = nil, trim = nil) - rv = source_file_dup(infile, offset, trim) - rv.av_ff_ok? or return - rv + ent = mcache_lookup(infile) or return + ret = source_file_dup(infile, offset, trim) + CACHE_KEYS.each { |k| ret.instance_variable_set(k, ent[k]) } + ret end def __parse_astream(cmd, stream) diff --git a/lib/dtas/source/ff.rb b/lib/dtas/source/ff.rb index 3d84d99..c337b42 100644 --- a/lib/dtas/source/ff.rb +++ b/lib/dtas/source/ff.rb @@ -18,6 +18,7 @@ class DTAS::Source::Ff # :nodoc: def initialize command_init(FF_DEFAULTS) + @mcache = nil @av_ff_probe = "ffprobe" end |