Transcoding through fifos
#!/bin/sh
INPUT=$1
BASE=`basename $INPUT`
OUTPUT=`echo $BASE|sed -e "s/\\.[^.]*$/.spx/g"`
FIFO="${TMPDIR-/tmp}/$BASE.$$"
mkfifo $FIFO
mpg123 -w $FIFO $INPUT &
speexenc $FIFO $OUTPUT
rm -f $FIFO
m2anx is a much longer script using this technique to transcode (and optionally annodex) from any format supported by mplayer to Ogg Theora, Ogg Vorbis or Ogg Speex. It uses multiple named pipes to handle the audio, video, and muxing in parallel, and uses a shell trap to clean up the named pipes on exit.
The new-school Unix way to handle this problem is to build media pipelines using GStreamer. If you're just after a simple and reliable command-line theora encoder try ffmpeg2theora.
Labels: scripting

