[cvs-annodex] commit (/annodex): +scripts/ +scripts/m2anx +scripts/trunk/

conrad nobody at lists.annodex.net
Thu Sep 9 13:19:10 EST 2004


Update of /annodex (new revision 552)

Added files:
   scripts/
   scripts/m2anx
   scripts/trunk/

Log Message:
add scripts dir, with m2anx


Added: scripts/m2anx
===================================================================
--- scripts/m2anx	2004-09-08 07:17:49 UTC (rev 551)
+++ scripts/m2anx	2004-09-09 03:19:08 UTC (rev 552)
@@ -0,0 +1,392 @@
+#!/bin/sh
+
+## Copyright (C) 2004 Commonwealth Scientific and Industrial Research
+## Organisation (CSIRO) Australia
+##
+## Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions
+## are met:
+##
+## - Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+##
+## - Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in the
+## documentation and/or other materials provided with the distribution.
+##
+## - Neither the name of CSIRO Australia nor the names of its
+## contributors may be used to endorse or promote products derived from
+## this software without specific prior written permission.
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+## PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
+## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+THIS="m2anx"
+
+THEORAENC='$HOME/src/xiph.org/theora/examples/encoder_example'
+
+VERBOSE=""
+DRYRUN=""
+
+video_codec="theora"
+audio_codec="vorbis"
+
+AOPTS=""
+afopts=""
+VOPTS=""
+vfopts=""
+
+version () {
+  echo >&2 "$THIS version "1
+  exit 1
+}
+
+usage () {
+  echo >&2 "$THIS, transcode media to Annodex format, using mplayer"
+  echo >&2
+  echo >&2 "Usage: $THIS [options] input"
+  echo >&2
+  echo >&2 "General options"
+  echo >&2 "  -n, --dry-run               Don't actually run any commands; just print them."
+  echo >&2 "  -o, --output                Specify output filename"
+  echo >&2
+  echo >&2 "Audio options"
+  echo >&2 "  -A, --audio-codec codec     Specify audio codec (null, speex, vorbis)"
+  echo >&2 "                                (default: $audio_codec)"
+  echo >&2 "  -c, --channels channels     Mix to given number of channels"
+  echo >&2 "  -r, --resample rate         Resample audio to given rate"
+  echo >&2
+  echo >&2 "Video options"
+  echo >&2 "  -V, --video-codec codec     Specify video codec (null, theora)"
+  echo >&2 "                                (default: $video_codec)"
+  echo >&2 "  -d, --decimate              Drop frames that don't differ greatly from the"
+  echo >&2 "                              previous  frame"
+  echo >&2 "  -x, --xy                    Scale video width"
+  echo >&2
+  echo >&2 "Miscellaneous options"
+  echo >&2 "  -h, --help                  Display this help and exit"
+  echo >&2 "  -v, --verbose               Print informative messages"
+  echo >&2 "  --version                   Output version information and exit"
+  echo >&2
+  exit 1
+}
+
+############################################################
+## General functions
+############################################################
+
+verbose_echo () {
+  if test "x$VERBOSE" != "x"; then
+    echo $*
+  fi
+}
+
+check_options () {
+  case $video_codec in
+  null|theora) # OK
+    ;;
+  *)
+    echo "$THIS: Unknown video codec $video_codec"
+    exit 1
+  ;;
+  esac
+
+  case $audio_codec in
+  null|speex|vorbis) # OK
+    ;;
+  *)
+    echo "$THIS: Unknown audio codec $audio_codec"
+    exit 1
+  ;;
+  esac
+}
+
+#
+# try_run desc cmd
+#
+try_run () {
+  desc=$1
+  shift
+
+  verbose_echo ==========================================================================
+  verbose_echo $desc ...
+
+  if test "x$DRYRUN" != "x" || test "x$VERBOSE" != "x"; then
+    echo $*
+  fi
+  if test "x$DRYRUN" = "x" ; then
+    eval $*
+    if test "$?" != "0"; then
+      echo "$THIS: Failed command:"
+      echo $*
+      exit 1
+    fi
+  fi
+}
+
+if_audio () {
+  if test "x$audio_codec" != "xnull" ; then
+    eval $*
+  fi
+}
+
+if_video () {
+  if test "x$video_codec" != "xnull" ; then
+    eval $*
+  fi
+}
+
+append_afopt () {
+  if test "x$afopts" = "x" ; then
+    afopts=$1
+  else
+    afopts="$afopts,$1"
+  fi
+}
+
+append_vfopt () {
+  if test "x$vfopts" = "x" ; then
+    vfopts=$1
+  else
+    vfopts="$vfopts,$1"
+  fi
+}
+
+
+############################################################
+## Initialize for clean up
+############################################################
+
+# exit status
+stat=1
+
+cleanup () {
+  try_run "Removing fifos" rm -f $AUDIO $VIDEO
+  try_run "Removing temporary working directory" rm -rf $WORKDIR
+  exit $stat
+}
+
+trap cleanup 0
+trap 'echo $THIS: Interrupted, cleaning up ...' INT QUIT KILL
+
+############################################################
+## BEGIN: Parse options
+############################################################
+
+GETOPTEST=`getopt --version`
+SHORTOPTS="no:hvA:r:c:V:dx:"
+
+case $GETOPTEST in
+getopt*) # GNU getopt
+  TEMP=`getopt -l dry-run -l output:: -l verbose -l version -l help -l audio-codec:: -l resample:: -l channels:: -l video-codec:: -l decimate -l xy:: -- +$SHORTOPTS $@`
+  ;;
+*) # POSIX getopt ?
+  TEMP=`getopt $SHORTOPTS $@`
+  ;;
+esac
+
+if test "$?" != "0"; then
+  usage
+fi
+
+eval set -- "$TEMP"
+
+while test "X$1" != "X--"; do
+  case "$1" in
+    -n|--dry-run)
+      DRYRUN="y"
+      ;;
+    -v|verbose)
+      VERBOSE="y"
+      ;;
+    --version)
+      version
+      ;;
+    -h|--help)
+      usage
+      ;;
+    -A|--audio-codec)
+      shift
+      audio_codec=$1
+      ;;
+    -c|--channels)
+      shift
+      append_afopt "channels=$1"
+      ;;
+    -r|--resample)
+      shift
+      append_afopt "resample=$1"
+      ;;
+    -V|--video-codec)
+      shift
+      video_codec=$1
+      ;;
+    -d|--decimate)
+      append_vfopt decimate
+      ;;
+    -x|--xy)
+      shift
+      #VOPTS="$VOPTS -zoom -vf scale -xy $1"
+      VOPTS="$VOPTS -zoom -xy $1"
+      append_vfopt scale
+      ;;
+  esac
+  shift
+done
+
+# Check that all options parsed ok
+if test "x$1" != "x--"; then
+  usage
+fi
+shift #get rid of the '--'
+
+if test "x$1" = "x"; then
+  usage
+fi
+
+check_options
+
+############################################################
+## Setup
+############################################################
+
+BASE=`basename $1|sed -e "s/\\.[^.]*$//"`
+INPUT=$PWD/$1
+OUTDIR=`dirname $1|sed -e "s#\(^[^/]\)#$PWD\/\1#"`
+CMMLIN=`dirname $1`/$BASE.cmml
+
+WORKDIR="${TMPDIR-/tmp}/$BASE.$$"
+AUDIO="$WORKDIR/audiodump.wav"
+VIDEO="$WORKDIR/stream.yuv"
+
+OGGOUT=$WORKDIR/$BASE.ogg
+SPXOUT=$WORKDIR/$BASE.spx
+
+ANXOUT=$OUTDIR/$BASE.anx
+
+# turn audio filter options into a -af argument
+if test "x$afopts" != "x" ; then
+  AOPTS="-af $afopts $AOPTS"
+fi
+
+# turn video filter options into a -vf argument
+if test "x$vfopts" != "x" ; then
+  VOPTS="-vf $vfopts $VOPTS"
+fi
+
+if test "x$VERBOSE" != "x"; then
+  echo "Input:  $INPUT"
+  echo "Output: $OGGOUT"
+  echo "Audio:  $audio_codec"
+  if test "x$audio_codec" != "xnull" ; then
+    echo "        $AUDIO"
+    echo "        mplayer decode options: $AOPTS"
+  fi
+  echo "Video:  $video_codec"
+  if test "x$video_codec" != "xnull" ; then
+    echo "        $VIDEO"
+    echo "        mplayer decode options: $VOPTS"
+  fi
+  echo
+fi
+
+if test "x$audio_codec" = "xnull" && test "x$video_codec" = "xnull" ; then
+  echo "$THIS: Nothing to do, exiting ..."
+  exit 1
+fi
+
+try_run "Creating temporary working directory" mkdir $WORKDIR
+
+if_audio "try_run \"Making audio fifo\" mkfifo $AUDIO"
+if_video "try_run \"Making video fifo\" mkfifo $VIDEO"
+
+############################################################
+## Decode
+############################################################
+
+# Video
+if test "x$video_codec" != "xnull" ; then
+  try_run "Decoding video" \
+    "(cd $WORKDIR && mplayer -ao null $VOPTS -vo yuv4mpeg $INPUT)" &
+fi
+
+# Audio
+if test "x$audio_codec" != "xnull" ; then
+  try_run "Decoding audio" \
+    "mplayer -format 128 $AOPTS -ao pcm -aofile $AUDIO -vc dummy -vo null $INPUT" &
+fi
+
+############################################################
+## Encode
+############################################################
+
+# theora + vorbis
+if test "x$audio_codec" = "xvorbis" && test "x$video_codec" = "xtheora" ; then
+  try_run "Encoding theora+vorbis" \
+    "$THEORAENC -o $OGGOUT $AUDIO $VIDEO"
+
+# theora only
+elif test "x$video_codec" = "xtheora" ; then
+  try_run "Encoding theora" \
+    "$THEORAENC -o $OGGOUT $VIDEO"
+fi
+
+# speex only
+if test "x$audio_codec" = "xspeex" ; then
+  try_run "Encoding speex" \
+    "speexenc $AUDIO $SPXOUT"
+
+# vorbis only
+elif test "x$audio_codec" = "xvorbis" && test "x$video_codec" = "xnull" ; then
+  try_run "Encoding vorbis" \
+    "oggenc $AUDIO -o $OGGOUT"
+fi
+
+wait # dude!
+
+############################################################
+## Annodex
+############################################################
+
+anx_inputs=""
+
+if test -e $CMMLIN ; then
+  anx_inputs="$anx_inputs -t text/x-cmml $CMMLIN"
+fi
+
+case $audio_codec in
+  speex)
+    anx_inputs="$anx_inputs -t audio/x-speex $SPXOUT"
+    if test "x$video_codec" = "xtheora" ; then
+      anx_inputs="$anx_inputs -t video/x-theora $OGGOUT"
+    fi
+    ;;
+  vorbis)
+    if test "x$video_codec" = "xtheora" ; then
+      anx_inputs="$anx_inputs -t application/ogg $OGGOUT"
+    else
+      anx_inputs="$anx_inputs -t audio/x-vorbis $OGGOUT"
+    fi
+    ;;
+  null)
+    if test "x$video_codec" = "xtheora" ; then
+      anx_inputs="$anx_inputs -t video/x-theora $OGGOUT"
+    fi
+esac
+
+try_run "Annodexing" \
+    "anxenc $anx_inputs -o $ANXOUT"
+
+verbose_echo "Wrote $ANXOUT"
+
+# Set exit status to 0
+stat=0


Property changes on: scripts/m2anx
___________________________________________________________________
Name: svn:executable
   + *


-- 
conrad



More information about the cvs-annodex mailing list