From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 208.118.235.0/24 X-Spam-Status: No, score=-2.3 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: dtas-all@80x24.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id D7D8F1FAC8 for ; Sun, 10 May 2015 11:23:06 +0000 (UTC) Received: from localhost ([::1]:33212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YrPK5-0005QA-VA for dtas-all@80x24.org; Sun, 10 May 2015 07:23:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YrPK3-0005Q4-7L for dtas-all@nongnu.org; Sun, 10 May 2015 07:23:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YrPJz-0004qf-Tp for dtas-all@nongnu.org; Sun, 10 May 2015 07:23:03 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:57425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YrPJz-0004qa-Na for dtas-all@nongnu.org; Sun, 10 May 2015 07:22:59 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6623F1FA7B; Sun, 10 May 2015 11:22:58 +0000 (UTC) From: Eric Wong To: Subject: [PATCH] splitfx: support -O/--outdir switch to control output dir Date: Sun, 10 May 2015 11:22:56 +0000 Message-Id: <1431256976-18583-1-git-send-email-e@80x24.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 Cc: Eric Wong X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Sender: dtas-all-bounces+dtas-all=80x24.org@nongnu.org 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 = {} -- EW