GStreamer and stdin

Posted on Tue 16 June 2009 in misc

GStreamer is the media framework used by the Gnome Desktop. For the most part it's working is hidden from users as media players setup up the processing pipelines required. However sometimes you just want to play something from the command line and that's where a lot of head scratching can be involved as you try and work out the correct incantation. Thankfully the developers have tried to make command line invocations simple. The "playbin" option mostly does the right thing:

gst-launch playbin uri=file:///home/alex/broken.ogg

However while I was indulging a little nostalgia and playing with sc68 I found myself wanting to use that other *nix convention of pipes. The sc68 player doesn't actually deal with playback but provides a raw audio stream that can be "piped" to an audio output. Unfortunately searching for "gstreamer pipes" on Google brings up a lot of overly technical discussions about GStreamer's multimedia processing pipeline which while undoubtedly powerful and flexible (and modelled after Unix pipes) doesn't actually help me with my problem. After some playing about with gst-inspect and grep I finally found something that looked promising, the "fdsrc" element. The fd refers to a "file descriptor" and it's relevance to pipes would probably be missed by someone not familiar with *nix terminology. Eventually I arrived at my solution:
./sc68/sc68 music/Jochen\ Hippel\ \(Mad\ Max\)/Atari\ ST/Cuddly\ Demo.sc68 | gst-launch-0.10 fdsrc ! audioparse ! audioconvert ! audioresample ! alsasink

Of course the real aim of exercise was to replace my current ring tone with something a bit more retro. Here another utility comes in, the LAME mp3 encoder. This follows the "standard" convention of using - in place of file names to indicate input (or output) should from standard input (or of course to standard output). The command line was easily guessed:
./sc68/sc68 music/Jochen\ Hippel\ \(Mad\ Max\)/Atari\ ST/Cuddly\ Demo.sc68 | lame -r - cuddly.mp3
Track      : 0/6
Title      : Cuddly Demo
Author     : Jochen Hippel (Mad Max)
Composer   : Jochen Hippel (Mad Max)
Replay     : built-in
Hardware   : Yamaha-2149
Start time : 0:00
Duration   : 06 13:07
Track      : 1/6
Title      : Color Shock
Author     : Jochen Hippel (Mad Max)
Composer   : Jochen Hippel (Mad Max)
Replay     : mcoder
Hardware   : Yamaha-2149
Start time : 0:00
Duration   : 01 03:12
Assuming raw pcm input file
LAME 3.98.2 64bits (http://www.mp3dev.org/)
Using polyphase lowpass filter, transition band: 16538 Hz - 17071 Hz
Encoding  to cuddly.mp3
Encoding as 44.1 kHz j-stereo MPEG-1 Layer III (11x) 128 kbps qval=3

And bingo, one very retro ring tone for my phone :-)