RTMP To RTSP re-stream using wowza and xuggler

Note: This is part of our “Xuggler Development Tutorials” series.

Hello to everyone!

    For the last three months we have been working on a teleconference project. We decided that a web based application, using technologies like Flex would be the best approach for such a demanding project. As the complexity of the software and the demands of telecommunication providers increased, the challenges we faced were noteworthy. One challenge was a request to feed live video from an agent that is utilizing our software to their RTSP server. The problem we faced is that Flex uses RTMP protocol in video and audio transmission and we needed something fast to do the re-streaming without re-inventing the wheel.

    In this article we will try to give enough information to deal with a complex problem, RTMP to RTSP re-streaming for a live stream. Our solution is based on wowza streaming server that supports both RTMP and RTSP and xuggler that brings the power of FFMPEG in java applications.

    Wowza supports RTMP to RTSP re-streaming for H.264 live streams but not for H.263. By default the video captured from ActionScript Camera object is H.263 encoded. We will provide the code based on xuggler that does the transcoding of H.263 to H.264 in real time and publish the H.264 stream to Wowza.

    First of all we need to set up xuggler. We need the latest version of FFMPEG and H.264 so it is necessary to checkout xuggler from it’s svn repository.

    svn checkout http://xuggle.googlecode.com/svn/trunk/java/xuggle-xuggler xuggle-xuggler

    Then we have to set up some environmental parameters.


    export XUGGLE_HOME=/usr/local/xuggler
    export PATH=$XUGGLE_HOME/bin:$PATH


    export XUGGLE_HOME=/usr/local/xuggler
    export PATH=$XUGGLE_HOME/bin:$PATH


    • Set XUGGLE_HOME to a directory of your choice (make sure the directory exists on disk). When building, you must make sure that your XUGGLE_HOME is on your C: drive, and is in a path with no spaces in it. Sorry. This restriction does not apply if you use the installer.
    • Add %XUGGLE_HOME%\bin; to the start of your PATH environment variable.
    • Optionally, set %XUGGLE_REPO% to a directory where you want ant to install published ivy jars (if you don’t set it, it defaults to dist/ivy in your build directory).

    Then we have to build and install xuggler.

    ant run-tests
    sudo ant install

    Now you have xuggler installed at $XUGGLE_HOME

    After completing with the installation we have to write the code that does the trick.

    package com.javacodegeeks.xuggler;
    import org.apache.commons.cli.CommandLine;
    import org.apache.commons.cli.Options;
    import org.apache.commons.cli.ParseException;
    import com.xuggle.xuggler.Converter;
    public class Transcoder {
         * @param args
        public static void main(String[] args) {
            String inputStream = "rtmp://wowzahost/live/streamLive3H.263";
            String outputStream = "rtmp://wowzahost/live/streamLive3H.264";
            String[] parameters = new String[] { "--acodec", "libfaac", "--vcodec",
                    "libx264", "--vpreset",
                    inputStream, outputStream };
            Converter converter = new Converter();
            Options options = converter.defineOptions();
            CommandLine cmdLine;
            try {
                cmdLine = converter.parseOptions(options, parameters);
            } catch (ParseException e) {
                // TODO Auto-generated catch block

    Points to notice.

    • At the directory $XUGGLE_HOME/share/ffmpeg you will find all the avail ables presets for x264.Better quality means more delay. You will have to choose what is suitable for your needs.
    • You will not have to change acodec and vcodec
    • The latest version of FFMPEG can read and write RTMP Streams.

    The example project is available here.

    Thank you for your time. Hope you’ll find this article interesting.

    Best Regards

    Related Whitepaper:

    Java Essential Training

    Author David Gassner explores Java SE (Standard Edition), the language used to build mobile apps for Android devices, enterprise server applications, and more!

    The course demonstrates how to install both Java and the Eclipse IDE and dives into the particulars of programming. The course also explains the fundamentals of Java, from creating simple variables, assigning values, and declaring methods to working with strings, arrays, and subclasses; reading and writing to text files; and implementing object oriented programming concepts. Exercise files are included with the course.

    Get it Now!  

    2 Responses to "RTMP To RTSP re-stream using wowza and xuggler"

    1. David Peterson says:

      I’ve installed Xuggler 3.4.   I have wowza publishing a rtmp stream (based upon an original ffmpeg stream).  I can open the RTMP stream with other programs, but xuggler hangs on the open call.  Any idea what could cause that?

      inputUrl: rtmp://localhost/live/4/1/2000_720.stream

      This call hangs:
      retval = mIContainer.open(inputURL, IContainer.Type.READ, iFmt);

      Tried changing it to this, but it also hangs.:

      retval = mIContainer.open(inputURL, IContainer.Type.READ, iFmt, true, false);

    2. David Peterson says:

      Sorry, but my post seemed to get lost so I am re-posting.  I am running Xuggler 3.4.  I can open a stream broadast from ffmpeg->Wowza 3 with other applications:  rtmp://localhost/live/4/1/2000_720.stream

      However, opening with Xuggler hangs on the IContainer.open.
      This:  mIContainer.open(inputURL, IContainer.Type.READ, iFmt, true, false);

      and this:  mIContainer.open(inputURL, IContainer.Type.READ, iFmt);

      Anyone have an idea as to why it would hang?

      Resolved. Ran into this defect: http://code.google.com/p/xuggle/issues/detail?id=284

    Leave a Reply

    six × = 48

    Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
    All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
    Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
    Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

    Sign up for our Newsletter

    20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

    As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

    • Fresh trends
    • Cases and examples
    • Research and insights
    • Two complimentary e-books