Usually very straightforward, ffmpeg
picks the output format using the file extension. Wave to mp3, 5 seconds only, 128kb/s, is:
ffmpeg -i input.wav -b:a 128k -t 00:00:05 output.mp3
Compiling ffmpeg
However, as soon as you want to use fancy codecs like AAC, you’re in trouble, because ffmpeg (being free software) doesn’t ship with those codecs included. Time to build it yourself! Check out the instructions here