blog.kfish.org

My name is Conrad Parker, and I live in Kyoto, Japan. I am working towards a PhD in Computer Science at Kyoto University, finishing September 2009. I also work on some free software projects including the Sweep sound editor and the Annodex media system, and various smaller projects which you can read about here.

Tuesday, 27 September 2005

Transcoding through fifos

When converting media files from one format to another (transcoding), a lot of intermediate data is generated: you plug a decoder into an encoder, and many megabytes of raw, uncompressed media data are shovelled between the two. Ideally you don't want to write this data to a disk file. The old-school Unix way to handle this is to use a named pipe:
#!/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:

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home