Broccoli Products home | contact us | about us
(by Lou Burne, last updated 10-APRIL-2012)
RED5 Servers
Project Summary
RED5 Servers are a popular choice for serving RTMP streams.

This project is for anyone who is having problems downloading a stream from a RED5 server.  It demonstrates the streaming of RTMP data from a RED5 server into a FLV file. 

The example used is a 90 second trailer for the film Toy Story 3.
Toy Story 3 Trailer
The Code
The project consists of a single C# code file, Red5Download.cs.  This file contains a single function, Main, which is described below.

To build the project, use the most recent build of the RtmpClient, which can be found in the file archive.

Main Function (Main)
The main application function in Red5Download.cs works as follows:
 
A Create an FlvStuffer object.  The FlvStuffer is a class for saving RTMP audio, video and meta-data messages into an FLV file.
B Create an RtmpClient object. The RtmpClient constructor takes one parameters, a reference to the main application window. Since Red5Download.cs runs in a console, which is windowless, this parameter can be null.

EventsEnabled - Set EventsEnabled to false so the RtmpClient doesn't waste time composing events when no one is listening.
C Create a new RTMP connection. The RtmpConnection object returned encapsulates a connection to the remote RTMP server.

The behavior flags instruct the RtmpClient library to automatically respond to any request for pings or data acknowledgements that come from the server.
D As this is not a live stream, only a short timeout is required. 

(Live streams can take a few seconds to get going.)
E Connect to the RTMP application.

The RTMP application we are connecting to uses standard connection parameters.
F Open a new RTMP stream.
G Register a callback function for the new stream.

Instead of a separate callback function defined in our code file, we are using a C# anonymous function. 

For each RTMP message received on our stream, we display the details on the console, and then pass the message to the FlvStuffer to update the FLV file.

This callback could be made more efficient by limiting the callbacks to only those types of messages we need to put into the FLV file, i.e., audio, video and meta-data.
H Play the stream, from the beginning (ts=0), to the end (ts=PlayAll).
I Loop until the streaming stops, or the user presses the "C" key.
K Clean up the RTMP session. Delete the stream, close the connection.

The RtmpClient object will be disposed of when it falls out of scope.
L Closing the FlvStuffer will set the correct duration for the FLV file, and flush and close the FLV file.
What To Do With An Flv File
Flv files are usually played in an Adobe Flash player embedded in a web page.

VLC Media Player
To play an Flv without using a browser try VideoLan's VLC Media Player, which is open-source, and plays a huge range of formats, both audio and video.

Flv is a skeleton file format, and finding a single free application to convert an Flv file to another format is not easy. 

There are two freely available applications, Mplayer and Lame.

Mplayer will convert an FLV file into a WAV audio file or AVI video file.

Lame is a freely available open-source application for converting WAV files into MP3.

Mplayer and Lame are both console applications, so can be run from a batch file or by starting a process in code.

The batch file for converting an FLV called hello.flv into an MP3 will look like this:

Mplayer hello.flv -ao pcm:file=output1.wav

Lame --priority 0 -b 128 -h --resample 44.1 output1.wav output1.mp3
Contact form 
Use the contact form to send comments and requests for information to Broccoli Products.
Topic:
Message:
Email:
Broccoli Products Ltd © 1998-2012 Broccoli Products Ltd
Reg Number: 2895355
Reg Office: 27 Old Gloucester Street, London. WC1N 3AX
Privacy Policy
Copyright Notice
Liability Disclaimer
Contact Us