Notice: Undefined variable: title in C:\web\oddsock.org\header.php on line 211

Notice: Undefined variable: title in C:\web\oddsock.org\header.php on line 212

Notice: Undefined variable: title in C:\web\oddsock.org\header.php on line 213

 

Ogg Theora Video streaming with Icecast2

Server Setup

So you just downloaded icecast and you found out that it now supports video. You think to yourself, "wow, neat..*I* want to do video. So how do I go about it ?". Well, then this guide is for you.

Step 1. Get icecast

This can be downloaded here : http://www.icecast.org/download.php. If you are going to compile icecast from source, then if you want to stream OggTheora (Xiph's free video codec) then you will also need to download libtheora. If you build icecast without theora installed, then you WILL NOT BE ABLE TO STREAM THEORA. If you do this, what will end up happening is only the vorbis part of your OggTheora stream will be streamed..And that's not what you want eh ? Anyway, if you are using the RPMS, then those will also require libtheora. You will need at LEAST alpha4 of libtheora, and those can be downloaded here : http://downloads.us.xiph.org/releases/theora. And make sure you get at LEAST alpha4.

Step 2. Configure icecast

Luckily, this is pretty straightforward, just use the icecast_minimal.xml provided config file, change the ports, your hostname, and you should be all ready to go..Easy huh ?

Step 3. Start icecast

Well, I'll include this for completeness, but you can start it like this :

% icecast -c icecast_minimal.xml

Client Setup

Step 1. Get some video files

I used mpeg2 files as my source media, primarily because I have a MythTv box, and that captures stuff in mpeg2 (well, technically, it's in NUV format, but renaming .nuv to .mpg works for me :)). I will presume that your media will be in a combination of formats, AVIs, MPG, and maybe some live video. This should all not be a problem. Although, I tried using some Divx encoded AVIs, and wasn't able to decode/encode them fast enough..If I'm getting ahead of you, hold on...

Step 2. Get ffmpeg2theora and ezstream

To broadcast in OggTheora, you'll need an decoder/encoder (that's ffmpeg2theora) and a source client (that's ezstream). ffmpeg2theora will decode pretty much any streams supported by ffmpeg (there are alot) and will encode to theora. It can do this on a file-by-file basis, or you can have it do it on the fly by via stdin/stdout. Both of these tools are also available on a windows platform, although this combination has only been tested on linux.

Download ffmpeg2theora : http://www.v2v.cc/~j/ffmpeg2theora. I recommend the binary distribution as I had a lot of problems getting it to compile (relating to mismatched versions of ffmpeg).

Note: if you are using win32 and are getting messages like "Unable to open file pipe", then you will need the bleeding edge version of ffmpeg2theora, which is only available in binary form here. Note that at the time of the writing of this document, only 0.12 of ffmpeg2theora is available, and the fix to address this issue on win32 will be included in the .13 build of ffmpeg2theora.

Download ezstream : http://downloads.us.xiph.org/releases/ezstream/ezstream-0.2.0.tar.gz. You will need to make sure to get at least 0.1.3. You will also need to make sure you get libshout 2.1 (you can find it here : http://www.icecast.org/download.php.

Step 3. Configure ezstream

We will need to use ezstream's reencoding capabilities for this task. While ezstream doesn't actually do the encoding, it supports external decoders and external encoders. We are going to use ffmpeg2theora as both an external decoder and encoder.

As luck would have it, ezstream (written by yours truly) comes with a example config file that we will use and make a few simple modifications. The following is the ezstream config file "ezstream_reencoding_example.xml" :

<ezstream>

    <url>http://192.168.6.1:8000/testmount.ogg</url>
    <sourcepassword>hackme</sourcepassword>

    <!-- This is what form your output will take. If you are
         reencoding, this is the format to reencode to, if not
         then you need to make sure all your input files are in this
         format -->
    <format>OGG</format>

    <filename>tracks.m3u</filename>

    <!-- The following settings are used to describe your stream
         to the server.  It's up to you to make sure the
         bitrate/quality/samplerate/channels
         match up to your output stream -->

    <svrinfoname>My Stream</svrinfoname>
    <svrinfourl>http://www.oddsock.org</svrinfourl>
    <svrinfogenre>RockNRoll</svrinfogenre>
    <svrinfodescription>This is a stream description</svrinfodescription>
    <svrinfobitrate>128</svrinfobitrate>
    <!-- Quality is only applicable to ogg vorbis streams -->
    <!-- <svrinfoquality>1.0</svrinfoquality> -->
    <svrinfochannels>2</svrinfochannels>
    <svrinfosamplerate>44100</svrinfosamplerate>
    <svrinfopublic>1</svrinfopublic>

    <reencode>
        <enable>1</enable>
        <!-- Each encdec block specifies a pair of programs used for decoding and
             encoding of the stream.  If reencoding is enabled, then all input files
             must be first decoded before being sent to the encoder.  EZSTREAM uses
             file extensions to match up input files with the appropraite decoder,
             and uses the <format> setting to match up the output format with the
             appropriate encoder.

             Note: It it up to you to set the appropriate bitrate/samplerate/channels
             of the output stream by using command line paramters to the encoders. Use
             the examples defined here as a guide.  All output from decoders should be in
             RAW format, and all input to the encoders should also be in RAW format. -->
        <encdec>
                <!-- Support for AVI decoding (input files) -->
                <format>THEORA</format>

                <match>.avi</match>

                <decode>ffmpeg2theora -x 192 -y 128 -a -1 -v 0 @T@ -o /dev/stdout</decode>
        </encdec>
        <encdec>
                <!-- Support for MPG decoding (input files) -->
                <format>THEORA</format>
                <match>.mpg</match>
                <decode>ffmpeg2theora -a -1 -v 2 @T@ -o /dev/stdout</decode>
        </encdec>
        <encdec>
                <!-- Support for FLAC decoding (input files) -->
                <format>FLAC</format>
                <match>.flac</match>
                <decode>flac -s -d --force-raw-format --sign=signed --endian=little @T@ -o -</decode>
                <encode>Not supported Yet</encode>
        </encdec>
        <encdec>
                <!-- Support for MP3 decoding via madplay, and encoding via LAME -->
                <format>MP3</format>
                <match>.mp3</match>
                <decode>madplay -o raw:- @T@ 2>/dev/null</decode>
                <encode>lame -r -x -b 56 -s 44.1 --resample 22.05 -a - - 2>/dev/null</encode>
        </encdec>
        <encdec>
                <!-- Support for Vorbis decoding via oggdec, and encoding via oggenc -->
                <format>VORBIS</format>
                <match>.ogg</match>
                <decode>oggdec --raw=1 @T@ -o - 2>/dev/null</decode>
                <encode>oggenc -Q -r -q 0 --resample=44100 --downmix -t "@M@" -c STREAMER=ezstream -</encode>
        </encdec>
        <!-- New encdec sections can be added for new input/output formats -->
    </reencode>
</ezstream>

The parts in yellow are those that we will need to look at.

The first changes (url, sourcepassword) are those of the icecast server. In the example here, the icecast server is running at IP 192.168.6.1 on port 8000, and we will be creating the mountpoint "/testmount.ogg". Note that for OggTheora streams, the mountpoint needs to end in .ogg.

The second changes (filename) is the playlist file that will contain your source media. As I said before, I'm going to be using mpeg2 files as input, so here is what my tracks.m3u looks like:

% cat tracks.m3u
BATTLESTAR_GALACTICATheGunOnIcePlanetZero_2.mpg

The third set of changes, (svrinfoname, etc.) are all there for the YP entry. These are purely informational for the YP (http://dir.xiph.org). So if you want to list your stream on the YP, make sure you've setup the directories properly in your icecast config and set svrinfopublic = 1 (as it is in the example). All the bitrate/channel settings are ALL INFORMATIONAL. The actual bitrates produced will be controlled by the <decode> line of the ezstream config.

The last change you need to make is with the <match> setting. This setting is used to match input files (extensions) to their appropriate decoders. In the above example, I've setup 2 matches, one for .avi and one for .mpg, that both do the same thing, use ffmpeg2theora to decode and encode the stream. So, in my case, I'm going to keep this as is, but you may need to change the <match> setting if you have files of a different extension.

Also, feel free to tweak the commandline parameters of ffmpeg2theora, the tag @T@ is used for substitution of the actual file name in the statement, and you just need to make sure that all encoded output is sent to stdout (via the -o /dev/stdout option). From there, ezstream will pick it up on stdin and send it to the icecast server.

So conceptually we have :

tracks.m3u -> myfile.mpg --(mpeg)-> ffmpeg2theora --(theora)-> ezstream --(network)-> icecast2 --> listeners(watchers ?).

Step 4. Start it up

So, with everything configured, and your icecast server running, start up ezstream with your config file. Here is what it looks like for me:

% ./ezstream -c ezstream_reencoding_example.xml
Connecting to http://192.168.6.1:8000/testmount.ogg...SUCCESS.
Streaming BATTLESTAR_GALACTICATheGunOnIcePlanetZero_2.mpg
Songinfo is (BATTLESTAR_GALACTICATheGunOnIcePlanetZero_2)
Unknown format OGG, passing right on through!
Input #0, mpeg, from 'BATTLESTAR_GALACTICATheGunOnIcePlanetZero_2.mpg':
  Duration: 00:48:44.1, bitrate: 1395 kb/s
  Stream #0.0: Video: mpeg1video, 352x240, 29.97 fps
  Stream #0.1: Audio: mp2, 44100 Hz, stereo, 224 kb/s
  Deinterlace: on
      0:00:15.21 audio: 35kbps video: 125kbps

At this point, we are up and streaming...so on to the next step....Watching!

Watching The Stream

Step 1. Get a supported player

In order to watch the stream, you need not just a media player that plays OggTheora streams, but one that will stream them as well. So far, the best choice has been VLC (http://www.videolan.org). They have both linux AND win32 versions and both can tune in OggTheora streams.

Keep checking http://www.theora.org for other clients you can use. The Helix and Directshow plugins didn't quite work for me, but have a lot of promise.

Step 2. Play the stream

The final step! opening up http://192.168.6.1:8000/testmount.ogg in VLC yields the following :



ahh...The Cylons in glorious OggTheora...

Misc

This is great, but you only show me how to use files, how about a webcam ?

I don't own a webcam, or rather one that works under linux, so I can't speak for it, but if you can get it to capture in mpeg or AVI, or any format that ffmpeg can decode, then you should be able to feed that right into ffmpeg2theora. So you could do something like :

% grabfromwebcam | ffmpeg2theora - -o /dev/stdout | ezstream -c ezstream_stdin.xml


This guide was written by oddsock.