Skip to content
T Yoshizawa edited this page Mar 16, 2015 · 3 revisions

wmadec

Windows版LMSに付属しているwmadec.exeの代替案

#!/bin/bash
#
# wmadec ffmpeg wrapper. (c)http://774plugin.googlecode.com 
#
# mms:// -> pcm
# .wma   -> pcm
#
#
FFMPEG_PATH="/path/to/ffmpeg"
 
set -e
 
function Die () {
  echo -e "ERROR: $1" >&2
  exit 1
}
 
[ -x "$FFMPEG_PATH" ] || Die "[ffmpeg] executable not found."
 
function usage() {
  echo 'wmadec [-dqhyw] [ -r sample_rate ] 
 [ -n num_channels ] [ -o outputfile ] [input file/url] 
-d 
	Add debugging output.  (ffmpeg -loglevel debug)
-q
	Suppresses program output. (ffmpeg -loglevel quiet)
-h
	Print help message.
-r n
	Sample rate of output. Default is 44100.
-n n
	Number of channels of output. Default is 2
-o filename
	Write output to specified filename.  Default is stdout.
-y
	Overwrite output files
-w
	Add wave headers
' >&2
  exit 1
}

 
FF_LOGLEVEL=error 
FF_SAMPLE_RATE=44100 
FF_NUM_CHANNELS=2 
FF_OUTFILE="-"
FF_OUTPUT_FMT="s16le"
FF_OPTIONS=
 
while getopts "dqhb:r:n:o:yw" OPT
do
  case $OPT in
    "d" ) FF_LOGLEVEL="debug" ;;
    "q" ) FF_LOGLEVEL="quiet" ;;
    "h" ) usage ;;
    "b" ) FF_BIT_PER_SAMPLE="$OPTARG" ;;
    "r" ) FF_SAMPLE_RATE="$OPTARG" ;;
    "n" ) FF_NUM_CHANNELS="$OPTARG" ;;
    "o" ) FF_OUTFILE="$OPTARG" ;;
    "y" ) FF_OPTIONS=-y ;;
    "w" ) FF_OUTPUT_FMT="wav" ;;
  esac
done
 
shift $(( $OPTIND - 1 ))
FF_INPUT="$1"
 
[[ $FF_INPUT ]] || usage
if ! ([[ -r $FF_INPUT ]] || [[ $FF_INPUT =~ ^(http|mms):// ]]); then
  Die "Invalid Input '$FF_INPUT'"
fi 
 
[[ $FF_SAMPLE_RATE =~ ^[0-9]*00$ ]] || Die "Invalid SAMPLE_RATE"
[[ $FF_NUM_CHANNELS =~ ^[12]$ ]] ||  Die "Invalid NUM_CHANNELS"
 
FF_INPUT=${FF_INPUT/mms:\/\//mmsh://}
 
exec "$FFMPEG_PATH" -loglevel $FF_LOGLEVEL \
     -i "$FF_INPUT" -ar $FF_SAMPLE_RATE \
     -ac $FF_NUM_CHANNELS $FF_OPTIONS -f $FF_OUTPUT_FMT "$FF_OUTFILE"

###インストール (Linux)

  1. たとえば、/usr/bin/wmadec として保存。
  • FFMPEG_PATHを編集する。プラグイン付属のffmpegが使える。
  • スクリプトに実行権限。 ''' chmod 755 /usr/bin/wmadec '''
    • FreeBSDの場合はbashのインストールと1行目 #!/usr/local/bin/bash。
Clone this wiki locally