30 June, 2009

Power of the Pipe

For quite some time I've it's been a mystery to me why many Unix-flavored toolsuites offer a command line interface supporting inputting or outputting to stdin/stdout respectively.

For example, ffmpeg can utilize stdin in leu of a input file by specifying -; similarly it can utilize stdout in leu of an output file using the same - specifier.

I've recently become aware of how useful this option can be. In particular it allows you to bypass creating unnecessary temporary files.

For example, using ffmpeg you can redirect the output to stdout and into mplayer to review the impacts of varying codecs and video quality specifiers.

$ ffmpeg -i /var/tmp/foo.mpg -f asf - | mplayer -cache 8192 -

Similarly, you can make use of the similar feature with ImageMagick like so:

$ convert Lenna.jpg - | display -

In each case, redirecting to stdout and piping to a consuming display utility eliminates the need for creating a temporary file.

No comments: