From 619b08c9d4e43d94bac39cd395c1def6fa796f06 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 10 May 2015 09:06:35 +0000 Subject: splitfx: support -O/--outdir switch to control output dir It is useful to force output to a writable directory if the YAML file is on a read-only mount point or to force the output to a large tmpfs mount point to avoid SSD/HDD wear. --- Documentation/dtas-splitfx.txt | 12 +++++++++--- bin/dtas-splitfx | 1 + lib/dtas/splitfx.rb | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Documentation/dtas-splitfx.txt b/Documentation/dtas-splitfx.txt index 8e37523..a6a1f7d 100644 --- a/Documentation/dtas-splitfx.txt +++ b/Documentation/dtas-splitfx.txt @@ -35,6 +35,12 @@ to use ecasound(1), too. : Disable automatic setting of the DITHERFX env. This also passes the option to sox(1) via SOX_OPTS. +-O, \--outdir OUTDIR +: Set output directory instead of current directory. + User-created targets must allow a placeholder for the + (by default, an empty string) $OUTDIR environment variable + in the output command. + # FILE FORMAT * infile - string, the pathname of the original audio file @@ -106,7 +112,7 @@ use in targets: * TRIMFX - essential, this supplys the necessary sox(1) trim effect to each track. In other words, this is: "trim ${TBEG}s ${TLEN}s" * COMMENTS - expands to --comment-file=PATH for sox(1) -* OUTFMT - sox(1) arguments for the output format (e.g. "-ts32 -c2 * -r44100") +* OUTDIR - placeholder for --outdir, defaults to an empty string * SUFFIX - the suffix of the output format without "." (e.g. "flac", "ogg") * TRACKNUMBER - the track number, useful for comments and filenames * RATEFX - rate effect and arguments for sox(1) resampling @@ -147,7 +153,7 @@ imbalance in a live concert recording from the audience: "|sox $INFILE -c1 -p $TRIMFX remix 1v1 vol +9.5dB" "|sox $INFILE -c1 -p $TRIMFX remix 2v1 vol +8.5dB" $COMMENTS $OUTFMT - bandYYYY-MM-DD.FOO.t0"$TRACKNUMBER.$SUFFIX" + ${OUTDIR}bandYYYY-MM-DD.FOO.t0"$TRACKNUMBER.$SUFFIX" $RATEFX $DITHERFX stats format: type: flac @@ -163,7 +169,7 @@ For reference, the "opusenc" default target is implemented as follows: --raw-bits $BITS_PER_SAMPLE $OPUSENC_BITRATE --raw-rate $RATE --raw-chan $CHANNELS --raw-endianness $ENDIAN_OPUSENC - $OPUSENC_COMMENTS - $TRACKNUMBER.opus + $OPUSENC_COMMENTS - $OUTDIR$TRACKNUMBER.opus format: bits: 16 rate: 48000 diff --git a/bin/dtas-splitfx b/bin/dtas-splitfx index be12910..b8fc6c8 100755 --- a/bin/dtas-splitfx +++ b/bin/dtas-splitfx @@ -14,6 +14,7 @@ OptionParser.new('', 24, ' ') do |op| op.on('-j', '--jobs [JOBS]', Integer) { |val| opts[:jobs] = val } op.on('-s', '--quiet', '--silent') { |val| opts[:silent] = true } op.on('-D', '--no-dither') { |val| opts[:no_dither] = true } + op.on('-O', '--outdir OUTDIR') { |val| opts[:outdir] = val } op.parse!(ARGV) end diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb index 208ff67..3f673ee 100644 --- a/lib/dtas/splitfx.rb +++ b/lib/dtas/splitfx.rb @@ -10,7 +10,7 @@ require 'tempfile' # Unlike the stuff for dtas-player, dtas-splitfx is fairly tied to sox # (but we may still pipe to ecasound or anything else) class DTAS::SplitFX # :nodoc: - CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$TRACKNUMBER.$SUFFIX" '\ + CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$OUTDIR$TRACKNUMBER.$SUFFIX" '\ '$TRIMFX $FX $RATEFX $DITHERFX' include DTAS::Process include DTAS::XS @@ -55,6 +55,7 @@ class DTAS::SplitFX # :nodoc: @track_zpad = true @t2s = method(:t2s) @infile = nil + @outdir = nil @targets = { "flac-cdda" => { "command" => CMD, @@ -72,7 +73,7 @@ class DTAS::SplitFX # :nodoc: '$OPUSENC_BITRATE --raw-rate $RATE --raw-chan $CHANNELS ' \ '--raw-endianness $ENDIAN_OPUSENC ' \ '$OPUSENC_COMMENTS ' \ - '- $TRACKNUMBER.opus', + '- $OUTDIR$TRACKNUMBER.opus', "format" => { "bits" => 16, "rate" => 48000, @@ -197,6 +198,7 @@ class DTAS::SplitFX # :nodoc: infile_env(env, @infile) env["OUTFMT"] = xs(outfmt.to_sox_arg) env["SUFFIX"] = outfmt.type + env["OUTDIR"] = @outdir ? "#@outdir/".squeeze('/') : '' env.merge!(t.env) command = target["command"] @@ -323,6 +325,11 @@ class DTAS::SplitFX # :nodoc: end def run(target, opts = {}) + if @outdir = opts[:outdir] + require 'fileutils' + FileUtils.mkpath(@outdir) + end + fails = [] tracks = @tracks.dup pids = {} -- cgit v1.2.3-24-ge0c7