* [PATCH 1/2] av_ff_common: attempt to fix encodings for ffprobe/avprobe
@ 2023-09-04 6:21 Eric Wong
2023-09-04 6:21 ` [PATCH 2/2] av_ff_common: use mcache Eric Wong
0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2023-09-04 6:21 UTC (permalink / raw)
To: dtas-all
As with sox, these will be dealing with legacy encodings
and badly-encoding software until the end of days, so do
our best to fix them up.
---
lib/dtas/source/av_ff_common.rb | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/dtas/source/av_ff_common.rb b/lib/dtas/source/av_ff_common.rb
index 5299fdb..332a0bb 100644
--- a/lib/dtas/source/av_ff_common.rb
+++ b/lib/dtas/source/av_ff_common.rb
@@ -104,13 +104,14 @@ def av_ff_ok?
prev_cmd = cmd
end while incomplete.compact[0]
+ enc = Encoding.default_external # typically Encoding::UTF_8
# old avprobe
s.scan(%r{^\[FORMAT\]\n(.*?)\n\[/FORMAT\]\n}m) do |_|
f = $1.dup
f =~ /^duration=([\d\.]+)\s*$/nm and @duration = $1.to_f
# TODO: multi-line/multi-value/repeated tags
f.gsub!(/^TAG:([^=]+)=(.*)$/ni) { |_|
- @comments[$1.upcase] = -($2)
+ @comments[-DTAS.try_enc($1.upcase, enc)] = $2
}
end
@@ -118,13 +119,17 @@ def av_ff_ok?
s.scan(%r{^\[format\.tags\]\n(.*?)\n\n}m) do |_|
f = $1.dup
f.gsub!(/^([^=]+)=(.*)$/ni) { |_|
- @comments[$1.upcase] = -$2
+ @comments[-DTAS.try_enc($1.upcase, enc)] = $2
}
end
s.scan(%r{^\[format\]\n(.*?)\n\n}m) do |_|
f = $1.dup
f =~ /^duration=([\d\.]+)\s*$/nm and @duration = $1.to_f
end
+ comments.each do |k,v|
+ v.chomp!
+ comments[k] = -DTAS.try_enc(v, enc)
+ end
! @astreams.compact.empty?
end
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] av_ff_common: use mcache
2023-09-04 6:21 [PATCH 1/2] av_ff_common: attempt to fix encodings for ffprobe/avprobe Eric Wong
@ 2023-09-04 6:21 ` Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2023-09-04 6:21 UTC (permalink / raw)
To: dtas-all
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).
---
lib/dtas/source/av.rb | 1 +
lib/dtas/source/av_ff_common.rb | 19 ++++++++++++++++---
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 39cad6c..823b29f 100644
--- a/lib/dtas/source/av.rb
+++ b/lib/dtas/source/av.rb
@@ -20,6 +20,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 332a0bb..0c84b2f 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 687cd18..491e580 100644
--- a/lib/dtas/source/ff.rb
+++ b/lib/dtas/source/ff.rb
@@ -21,6 +21,7 @@ class DTAS::Source::Ff # :nodoc:
def initialize
command_init(FF_DEFAULTS)
+ @mcache = nil
@av_ff_probe = "ffprobe"
end
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-04 6:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-04 6:21 [PATCH 1/2] av_ff_common: attempt to fix encodings for ffprobe/avprobe Eric Wong
2023-09-04 6:21 ` [PATCH 2/2] av_ff_common: use mcache Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/dtas.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).