Using Red5 Pro To Record and View Video On Demand

Video-On-Demand (VOD) is a subscriber paradigm wherein users can select a pre-recorded stream to watch if and when they wish to do so. As opposed to live streaming content, VOD content is stored on the streaming server, or on a CDN (see Using AWS S3 for Video On Demand, for on-demand consumption.

No special configuration changes are required to get VOD working with Red5 Pro. VOD works out of the box with Red5 Pro.

Setting up video on demand using Red5 Pro is a very simple process. To complete the setup successfully you would need a few simple basic components:

  1. Media file: A video file encoded in a Red5 Pro compatible file format(Explained below). The format and its content codec need to be compliant with the protocol you choose to stream over.
  2. Red5 Pro media server: A Red5 Pro server instance deployed online for serving vod media content to subscribers.
  3. Video player: A video player capable of playing your vod stream. To decode media frames being received from the server you will need a compatible video player which understands the protocol that the media is streamed over. Currently Red5 Pro supports VOD over RTMP(desktop) and RTSP (mobile) only.

Recording a Stream

To record a file using a mobile client using the Red5 Pro Streaming SDK, set R5Record type to Record instead of Live.

Using the Red5 Pro iOS Streaming SDK:

self.publishStream!.publish(Testbed.getParameter("stream1") as! String, type: R5RecordTypeRecord)

Using the Red5 Pro Android Streaming SDK:

publish.publish(TestContent.GetPropertyString("stream1"), R5Stream.RecordType.Record);

To record with Flash or WebRTC, set streamMode to record instead of live. See the HTML5 SDK docs for more information.

Server-side:

You will find a /streams directory listed under the app directory you are publishing to. For example, if you publish to a webapp called vod, you will see this directory in /webapps/vod/streams. While you are publishing/recording, you will see the placeholder files (.info and .ser).

inprogress

And, when you stop broadcasting, there will be a Flash Video (flv) file in the directory with your stream name (i.e., stream1.flv)

finished'

You can convert the flv file to an mp4 file using transcode post processing.

In addition to the FLV, mobile and WebRTC clients will automatically record an HLS stream (for Flash, you need to force HLS recording).

Preparing a Video File for Streaming

Red5 Pro supports the following media formats for streaming:

  • Streaming Video (FLV, F4V, MP4, 3GP)
  • Streaming Audio (MP3, F4A, M4A, AAC)

In order for Red5 Pro to be able to stream a recorded media to client, it needs to be in a format understood by Red5 Pro, supported by the protocol used (RTMP/RTSP) and also readable by the client side player.

A file format is like a container which holds audio and/or video data in a single file. Each file format in turn allows storing data encoded in specific codecs only. To keep things simple, we won't be venturing into the depth of codecs and encoding here. Let us, however, take a look at the basic video formats that are compatible with Red5 Pro and the codecs they support.

Commonly used video formats for VOD transmission:

If your file is not in one of these formats you might need to encode your video for compatibility with flash player using a tool such as Adobe media encoder or the open source ffmpeg encoder.

Useful Links

Subscribing to a Recorded File

If you want to subscribe to your recorded stream using the Red5 Pro client SDK, you simply need to include the file extension (so "stream.flv", or "file.mp4") when calling the subscribe method.

The client is smart enough to look for the recorded file in the "streams" subdirectory if you include a file extension. Without the extension, it assumes the stream is live.

You can view the list of available mp4 and flv files in the live streams directory by visiting http://localhost:5080/live/mediafiles:

{"mediafiles":[{"name":"stream1.flv","lastModified":1506014299000,"length":21739350,"url":"stream1.flv"},{"name":"stream2.flv","lastModified":1506012451000,"length":1560502,"url":"stream2.flv"},{"name":"stream3.flv","lastModified":1506012893000,"length":30032180,"url":"stream3.flv"}]}

You can also view the available HLS (m3u8) files by visiting http://localhost:5080/live/playlists:

{"playlists":[{"name":"stream4.m3u8","lastModified":1506012452000,"length":836,"url":"stream4.m3u8"},{"name":"stream5.m3u8","lastModified":1506014300000,"length":1786,"url":"stream5.m3u8"},{"name":"stream6.m3u8","lastModified":1506012894000,"length":2481,"url":"stream6.m3u8"}]}

If you are using the Red5 Pro cloud storage plugin, these calls will also list out the files that are stored in your cloud storage bucket. For HLS VOD details, look here).


Third-Party Subscribers

You can also use a desktop player such as VLC to subscribe to a recorded file. VLC can subscribe to FLV, MP4, and HLS video on demand.

With VLC media player, Open Media

finished

Go to the Network Tab, and type in the URL of your stream (for example, http://127.0.0.0:5080/vod/streams/stream2.flv)

finished

then press open to view.

finished