just some stuff

downsampling a live stream for relaying

06 Apr 2011

A quick description on how to downsample an icecast stream with ffmpeg and using ezstream to stream it back to the server.

the problem

recently, i had to donwsample a live stream ( to an icecast server ) which was streamed upwards in 64kbit, but there was also to bee a downsampled stream for mobile devices (32kbit.) There are quite a few exmamples using ices2 etc for this, but it did not work for me. anyway, i am a big fan of ezstream for playing a playlist to an icecast server, so i looked into ezstream for my purpose.

ffmpeg, ezstream

you can use ffmpeg to "play" the original stream and just hand it over to ezstream. ezstream can be configured to use stdin ( pipe) as an input. so here is the actual line which fetches the live stream from the server and hands it over to ezstream:

ffmpeg -i http://radio.indybay.org:8000/x26radio -acodec libmp3lame -ar 44100 -f mp3 \ 

pipe:1 | ezstream -c ezstream_stdin.xml
and , of course, the ezstream_stdin.xml example, which uses madplay via ezstream to reencode the stream. there is probably a way of using ffmpeg directly for that, but i am lazy so i used the way ezstream is normally handling the re-encoding via madplay.

      For streaming from standard input, the default for continuous streaming
      is bad. Set <stream_once /> to 1 here to prevent ezstream from spinning
      endlessly when the input stream stops:
      The following settings are used to describe your stream to the server.
      It's up to you to make sure that the bitrate/quality/samplerate/channels
      information matches up with your input stream files.
    <svrinfoname>downsampled mobile stream</svrinfoname>
    <svrinfodescription>Oh well so live</svrinfodescription>
    <!-- Allow the server to advertise the stream on a public YP directory: -->

<reencode> <!-- Enable the reencoding feature: --> <enable>1</enable> <encdec> <!-- Support for MP3 decoding via madplay, and encoding via LAME: --> <format>MP3</format> <match>.mp3</match> <!-- Note: madplay uses host byte order for raw samples. --> <decode>madplay -b 16 -R 44100 -S -o raw:- "@T@"</decode> <encode>lame --preset cbr 32 -r -s 44.1 --bitwidth 16 - -</encode> </encdec> </reencode>