[ubuntu-studio-devel] File Manager - Was a long time ago: Documentation: Tutorial Videos

Ralf Mardorf ralf.mardorf at alice-dsl.net
Wed Apr 27 10:19:26 UTC 2016


On Tue, 2015-12-15 at 21:40 +0100, Ralf Mardorf wrote:
> [snip] I searched websites explaining how to split stereo WAV to mono
> WAV [snip]

Half a year later I wrote a script [2]. Since there seem to be issues
with the file managers of the bloated DEs, I again want to introduce
spacefm. Spacefm allows to add "Tools" [3], mark a file and from a menu
or by a shortcut run a tool, e.g. export a selected stereo.wav mixed to
a mono.wav and/or split it to left.wav and right.wav.

The script needs to be executable
  sudo chmod a+x s2m
and it needs a few links [1]
  sudo ln -s s2m s2l; sudo ln -s s2m s2r; sudo ln -s s2m s2d; sudo ln -s s2m s2a

Regards,
Ralf


[1]
$ ls -hAl /usr/local/bin/s2*
lrwxrwxrwx 1 root root    3 Apr 27 09:49 /usr/local/bin/s2a -> s2m
lrwxrwxrwx 1 root root    3 Apr 27 09:49 /usr/local/bin/s2d -> s2m
lrwxrwxrwx 1 root root    3 Apr 27 09:49 /usr/local/bin/s2l -> s2m
-rwxr-xr-x 1 root root 1.8K Apr 27 10:57 /usr/local/bin/s2m
lrwxrwxrwx 1 root root    3 Apr 27 09:49 /usr/local/bin/s2r -> s2m


[2]
$ cat /usr/local/bin/s2m 
#!/bin/dash

version="2016-04-27"

usage()
{
  cat<<EOF

  s2m version $version rocketmouse

  stereo.wav > mono.wav:
    s2m input_file.wav
  stereo.wav > left.wav:      
    s2l input_file.wav
  stereo.wav > right.wav:
    s2r input_file.wav
  stereo.wav > dual {left,right}.wav:
    s2d input_file.wav
  stereo.wav > all {mono,left,right}.wav:
    s2a input_file.wav

EOF
  exit $1
}

outfile()
{
  outfile="$(echo "$infile" | sed 's/\(.*\).wav/\1.'$1.$suffix/I)"
  if [ -f "$outfile" ]; then
    echo "$outfile already exists"
    usage 1
  fi
}

ex2file()
{
  outfile $1
  echo "Export to $outfile"
  case $1 in
    mono)
      ffmpeg -i "$infile" -ac 1 "$outfile"
    ;;
    left)
      ffmpeg -i "$infile" -map_channel 0.0.0 "$outfile"
    ;;
    right)
      ffmpeg -i "$infile" -map_channel 0.0.1 "$outfile"
    ;;
  esac
}

case $1 in
  -h|--help)
    usage 0
  ;;
esac

infile="$1"
if [ ! -f "$infile" ]; then
  echo "No file $infile"
  usage 1
fi

num_ch=$(exiftool "$infile" | grep "Num Channels" | cut -d: -f2 | sed s/\ //)
plural=""
if [ "$num_ch" = "" ]; then
  num_ch="No"
else 
  if [ "$num_ch" -ge "2" ]; then
    plural="s"
  fi
fi
if [ "$num_ch" != "2" ]; then
  echo "$num_ch channel$plural, not a stereo file"
  usage 1
fi

suffix=$(echo "$infile" | rev | cut -d. -f1 | rev)
if [ "$(echo "$suffix" | tr [:upper:] [:lower:])" != "wav" ]; then
  echo "Suffix is \"$suffix\", must be \"wav\", case sensitivity is not required"
  usage 1
fi

case $(basename $0) in
  s2m)
    ex2file mono
  ;;
  s2l)
    ex2file left
  ;;
  s2r)
    ex2file right
  ;;
  s2d)
    outfile right
    ex2file left
    ex2file right
  ;;
  s2a)
    outfile left
    outfile right
    ex2file mono
    ex2file left
    ex2file right
  ;;
esac

exit


[3]
$ tail -n56 ~/.config/spacefm/session
cstm_5c7b8757-y=
cstm_5c7b8757-key=109
cstm_5c7b8757-keymod=8
cstm_5c7b8757-label=stereo.wav > mono.wav
cstm_5c7b8757-icon=audio-speakers-symbolic
cstm_5c7b8757-next=cstm_29b7af98
cstm_5c7b8757-prev=cstm_44d18ee4
cstm_5c7b8757-line=s2m %f
cstm_5c7b8757-task=1
cstm_5c7b8757-task_err=1
cstm_5c7b8757-task_out=1
cstm_5c7b8757-keep=1
cstm_29b7af98-y=
cstm_29b7af98-key=108
cstm_29b7af98-keymod=8
cstm_29b7af98-label=stereo.wav > left.wav
cstm_29b7af98-next=cstm_660bd947
cstm_29b7af98-prev=cstm_5c7b8757
cstm_29b7af98-line=s2l %f
cstm_29b7af98-task=1
cstm_29b7af98-task_err=1
cstm_29b7af98-task_out=1
cstm_29b7af98-keep=1
cstm_660bd947-y=
cstm_660bd947-key=114
cstm_660bd947-keymod=8
cstm_660bd947-label=stereo.wav > right.wav
cstm_660bd947-next=cstm_0c82cc40
cstm_660bd947-prev=cstm_29b7af98
cstm_660bd947-line=s2r %f
cstm_660bd947-task=1
cstm_660bd947-task_err=1
cstm_660bd947-task_out=1
cstm_660bd947-keep=1
cstm_0c82cc40-y=
cstm_0c82cc40-key=100
cstm_0c82cc40-keymod=8
cstm_0c82cc40-label=stereo.wav > dual {left,right}.wav
cstm_0c82cc40-next=cstm_2682da6a
cstm_0c82cc40-prev=cstm_660bd947
cstm_0c82cc40-line=s2d %f
cstm_0c82cc40-task=1
cstm_0c82cc40-task_err=1
cstm_0c82cc40-task_out=1
cstm_0c82cc40-keep=1
cstm_2682da6a-y=
cstm_2682da6a-key=97
cstm_2682da6a-keymod=8
cstm_2682da6a-label=stereo.wav > all {mono,left,right}.wav
cstm_2682da6a-prev=cstm_0c82cc40
cstm_2682da6a-line=s2a %f
cstm_2682da6a-task=1
cstm_2682da6a-task_err=1
cstm_2682da6a-task_out=1
cstm_2682da6a-keep=1



More information about the ubuntu-studio-devel mailing list