RTMP Examples 3.4

334 views
Skip to first unread message

Martin

unread,
Jun 14, 2010, 12:48:02 PM6/14/10
to xuggler-users
Hi Xuggle Experts,

I want to build a xuggler based live-encoder (client) with rtmp
streaming support.

Xuggle 3.4 has build in RTMP Support. Has someone of you a small
Xuggle RTMP Example?
- First Step: Streaming existing mp4 file to Streaming server with
xuggle (not commandline based)
- Second Step: Streaming Live-Encding IContainer with MediaWriter to
Streaming Server
- etc.

This parts are working already:
- Capture DV Cam by dsj
- Encode Video and Audio Stream from DV Cam with xuggle (h.264 / AAC) -
> export to mp4 file
- Play exported mp4 file with Adobe Flash Player

Next step would be RTMP streaming to a Streaming-Server (Wowza).
I've tried it with MediaWriter... It looks like the connection to the
server works, there is also a log entry with a publish notification,
but playing the live-stream is not working.

Here is the example which is not working:
-----------------------
String rtmpOut = "rtmp://localhost/live/video";
_mediaWriter = ToolFactory.makeWriter(rtmpOut);

_mediaWriter.open();
_mediaWriter.setForceInterleave(true);

if (getSupportsVideo()) {
_mediaWriter.addVideoStream(EncodingConstants.VIDEO_STREAM_ID, 0,
ICodec.guessEncodingCodec(null, null, "test.mp4", null,
ICodec.Type.CODEC_TYPE_VIDEO), frameRate, VideoConstants.SCREEN_WIDTH,
VideoConstants.SCREEN_HEIGHT);
}

if (getSupportsAudio()) {
_mediaWriter.addAudioStream(EncodingConstants.AUDIO_STREAM_ID, 0,
ICodec.guessEncodingCodec(null, null, "test.mp4", null,
ICodec.Type.CODEC_TYPE_AUDIO), _af.getChannels(),
(int)_af.getSampleRate());
}

// Set encoding
IContainer myContainer = _mediaWriter.getContainer();
IStreamCoder outStreamCoder =
myContainer.getStream(0).getStreamCoder();

ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_H264);
outStreamCoder.setCodec(codec);

int retval;
retval = Configuration.configure("presets/libx264-default.ffpreset",
outStreamCoder);
if (retval < 0)
throw new RuntimeException("could not configure coder from preset
file");

outStreamCoder.setBitRate(400000);
outStreamCoder.setBitRateTolerance(90000);

int width, height;
width = VideoConstants.SCREEN_WIDTH;
height = VideoConstants.SCREEN_HEIGHT;

outStreamCoder.setPixelType(IPixelFormat.Type.YUV420P);
outStreamCoder.setHeight(height);
outStreamCoder.setWidth(width);
outStreamCoder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
outStreamCoder.setGlobalQuality(0);
(...)
-----------------------

I had to modify the MediaWriter construktor a littlebit:
-----------------------
MediaWriter(String url)
{
super(url, IContainer.make());

// record the url and absense of the input container

mInputContainer = null;

// WORKAROUND FOR RTMP
if (url.substring(0, 4).equals("rtmp")){
// set flv container format
mContainerFormat = IContainerFormat.make();
mContainerFormat.setOutputFormat("flv", url, null);

} else {
// create null container format
mContainerFormat = null;
}
}
-----------------------

Thanks for your answers!
Martin
Reply all
Reply to author
Forward
0 new messages