ExRTMP.Client (RTMP Server and Client v0.4.1)

View Source

RTMP Client implementation.

This module provides functionality to connect to an RTMP server, publish and play streams.

Media Handling

When playing a stream, the client will demux the incoming RTMP streams into audio and video frames before passing them to the receiver process (the calling process by default).

The format of the data received by the receiver is:

  • {:video, client_pid, video_data} - A video frame.
  • {:audio, client_pid, audio_data} - An audio frame.

The video_data is in the following format:

  • {:codec, atom(), init_data} - The codec type and initialization data.
  • {:sample, payload, dts, pts, keyframe?} - A video sample, the payload depends on the codec type. In the case of avc, the payload is a list of NAL units, for other codecs, it is the raw video frame data.

The audio_data is in the following format:

  • {:codec, atom(), init_data} - The codec type and initialization data.
  • {:sample, payload, timestamp} - An audio sample.

Publishing Media

When publishing a stream, the client can send FLV tags to the server using the send_tag/3 function. The tags must be either ExFLV.Tag.AudioData or ExFLV.Tag.VideoData structs.

Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes a stream and close connection.

Connects to the RTMP server.

Plays a stream on the RTMP server.

Publishes a stream to the RTMP server.

Sends an FLV tag to the server.

Starts a new RTMP client.

Starts and links a new RTMP client.

Stops the RTMP client.

Types

start_options()

@type start_options() :: [
  uri: String.t(),
  stream_key: String.t(),
  name: GenServer.name(),
  receiver: Process.dest()
]

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(client)

@spec close(GenServer.name() | pid()) :: :ok

Deletes a stream and close connection.

connect(client)

@spec connect(GenServer.name() | pid()) :: :ok | {:error, any()}

Connects to the RTMP server.

play(client)

@spec play(GenServer.name() | pid()) :: :ok | {:error, any()}

Plays a stream on the RTMP server.

publish(client)

@spec publish(GenServer.name() | pid()) :: :ok | {:error, any()}

Publishes a stream to the RTMP server.

send_tag(client, timestamp, tag)

Sends an FLV tag to the server.

start(opts)

@spec start(start_options()) :: GenServer.on_start()

Starts a new RTMP client.

For available options see start_link/1.

start_link(opts)

@spec start_link(start_options()) :: GenServer.on_start()

Starts and links a new RTMP client.

Options

  • :uri - The RTMP server URI to connect to. This option is required.

  • :stream_key - The stream key. This option is required.

  • :name - The name to register the client process. This option is optional.

stop(client)

@spec stop(GenServer.name() | pid()) :: :ok

Stops the RTMP client.