Broccoli Products home | contact us | about us
(by Lou Burne, last updated 10-APRIL-2012)
File Dump
Project Summary
The FileDump project demonstrates downloading an RTMP stream into an FLV file.

The stream is a lecture from Princeton University.  For other RTMP servers that can be used for testing, see the Feed Directory.
The Code
The File Dump project consists of a single C# code file, FileDump.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 FileDump.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 window of your application. FileDump.cs runs in a console, which is windowless, so this parameter can be null.

EventsEnabled - Set to false to inform the RtmpClient not to send out any status change events.
C Declare the stream and connection references.
D Create a new RTMP connection. The RtmpConnection object returned encapsulates a connection to the remote RTMP server.

There are several variants of RTMP, for example, RTMPT which is RTMP tunneled through HTTP, or RTMPE which is encrypted RTMP.  However RTMPClient currently only supports RTMP.

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

(Live streams can take a few seconds to get going.)
F Call an RtmpConnection function to connect to the streaming application we are interested in.

Some users need to customize their connection with additional parameters. See the Coding Tips for more details.
G Call an RtmpConnection function to create a stream. This returns an RtmpStream object.
H 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.
I Play the stream.

Playing the stream initiates a flow of audio and video data from the RTMP server, and some meta-data.
J 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.
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