Note: This is part of our “Xuggler Development Tutorials” series.
Hello to everyone!
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.
Linux
Now you have xuggler installed at $XUGGLE_HOME
After completing with the installation we have to write the code that does the trick.
The example project is available here.
Thank you for your time. Hope you'll find this article interesting.
Best Regards
./pat
Hello to everyone!
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-xugglerThen we have to set up some environmental parameters.
Linux
export XUGGLE_HOME=/usr/local/xuggler export PATH=$XUGGLE_HOME/bin:$PATH export LD_LIBRARY_PATH=$XUGGLE_HOME/lib:$LD_LIBRARY_PATHMAC
export XUGGLE_HOME=/usr/local/xuggler export PATH=$XUGGLE_HOME/bin:$PATH export DYLD_LIBRARY_PATH=$XUGGLE_HOME/lib:$DYLD_LIBRARY_PATHWindows
- 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).
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",
"/usr/local/xuggler/share/ffmpeg/libx264-ultrafast.ffpreset",
inputStream, outputStream };
Converter converter = new Converter();
Options options = converter.defineOptions();
CommandLine cmdLine;
try {
cmdLine = converter.parseOptions(options, parameters);
converter.run(cmdLine);
System.out.println("Finish!!!");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
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
./pat
You could just stream from RTMP to RTSP using ffmpeg's ffserver. All you need in ffserver.conf is
ReplyDelete####
Port 8090
RTSPPort 5454
BindAddress 0.0.0.0
MaxHTTPConnections 1000
MaxClients 200
MaxBandwidth 10000
CustomLog -
<Stream 1.mp4>
File "rtmp://wowzahost/live/streamLive3H.263"
Format rtp
</Stream>
####
And then anyone can play rtsp://server:5454/1.mp4
You are right but we wanted to control the streaming in application level. RTMP streams are dynamically created with random names not statically.
ReplyDeletewe have setup the xuggler in windows 2003 and convert the stream using command line in wowza api wich works. now we have moved the server to windows 2008 32 bit OS . the command line is not working in wowza module or from command prompt also .
ReplyDeleteits not giving any erorr also just the blank screen. do you have any idea what could be the problem?
Hello chesponal.
ReplyDeleteI don't know what causes the problem with 2008 installation. What i would suggest is to use wireshark at port 1935 and get a dump of the rtmp conversation.Also you could check wowza logs.You could send me the logs and the dump in order to try to understand what causes the problem.
Is the string in the output URL supposed to start with "rtmp://". Shouldn't it be "rtsp://" if the purpose is to transcode from an H.263/Sorenson file on RTMP to H.264 served over RTSP?
ReplyDeleteHello Peter,
ReplyDeletethe output is "rtmp://wowzahost/live/streamLive3H.264"
Wowza has the ability to publish live rtmp streams with H.264 encoding ,as rtsp streams.We perform the trancoding with xuggler because wowza doesn't do the same re-streaming to rtsp for H.263 streams.
In this example you would be able to open the same stream at the following urls.
"rtmp://wowzahost/live/streamLive3H.264" as rtmp
and
"rtsp://wowzahost/live/streamLive3H.264.sdp" as rtsp
thanks
pat
Hello.
ReplyDeleteWe are student and we work on a project of video conference between ipad.
Now we try to transform the flv stream into H264 to be accept by the ipad.
But I have this error with your code :
Can you help me?
Exception in thread "main" java.lang.RuntimeException: could not open output url: rtmp://localhost/oflaDemo/leflux3
at com.xuggle.xuggler.Converter.setupStreams(Converter.java:662)
at com.xuggle.xuggler.Converter.run(Converter.java:1183)
at com.javacodegeeks.xuggler.Transcoder.main(Transcoder.java:30)
2011-01-06 13:02:40,441 [main] ERROR com.xuggle.xuggler - Could not find output format (../../../../../../../csrc/com/xuggle/xuggler/Container.cpp:339)
Thanks, Flo.
Where the heck I download a win version of ffserver? I'm crazy of looking for it. any news to bergmp at gmail com
ReplyDeleteHai Peter,
ReplyDeleteCheck this link for ffserver for windows
http://www.filerepair.ca/downloads/f/ff/ffserver.exe-DLL-EXE-Download-ffserver.exe.html
hello, I followed the instructions above, when running ant run-tests, got this. am I missing anything -- can anyone help?
ReplyDelete[exec] checking for xlC... no
[exec] checking for C++ compiler default output file name...
[exec] make[2]: *** [/root/downloads/xuggle-xuggler/build/native/x86_64-unknown-linux-gnu/captive/libopencore-amr/csrc/Makefile] Error 1
[exec] make[1]: *** [all-recursive] Error 1
[exec] make: *** [all-recursive] Error 1
[exec] Could not configure library: "/root/downloads/xuggle-xuggler/build/native/x86_64-unknown-linux-gnu/captive/../../../../captive/libopencore-amr"; you may want to try disabling it or installing your own version
[exec] make[2]: Leaving directory `/root/downloads/xuggle-xuggler/build/native/x86_64-unknown-linux-gnu/captive/libopencore-amr'
[exec] make[1]: Leaving directory `/root/downloads/xuggle-xuggler/build/native/x86_64-unknown-linux-gnu/captive'
BUILD FAILED
/root/downloads/xuggle-xuggler/mk/buildtools/buildhelper.xml:1146: exec returned: 2
I've installed Xuggler 3.4. I have wowza publishing a rtsp stream. I can open the RTSP stream with other programs, but xuggler hangs on the open call. Any idea what could cause that?
ReplyDeleteThis 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);
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
ReplyDeleteHowever, 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?