# Membrane RTMP Plugin

[![API Docs](](

This package provides RTMP server which listens to a connection from a client.
After establishing connection it receives RTMP stream, demux it and outputs H264 video and AAC audio.
At this moment only one client can connect to the server.

It is part of [Membrane Multimedia Framework](

## Installation

The package can be installed by adding `membrane_rtmp_plugin` to your list of dependencies in `mix.exs`:

def deps do
    {:membrane_rtmp_plugin, "~> 0.2.0"}

### Prerequisites
In order to successfully build and install the plugin, you need to have **ffmpeg >= 4.4** installed on your system

## Usage
Example Server pipeline can look like this:

defmodule Example.Server do
  use Membrane.Pipeline

  @port 5_000

  @impl true
  def handle_init(_opts) do
    directory = "hls_output"

    spec = %ParentSpec{
      children: %{
        :rtmp_server => %Membrane.RTMP.Bin{port: @port},
        :hls => %Membrane.HTTPAdaptiveStream.SinkBin{
          manifest_module: Membrane.HTTPAdaptiveStream.HLS,
          target_window_duration: 20 |> Membrane.Time.seconds(),
          muxer_segment_duration: 2 |> Membrane.Time.seconds(),
          persist?: false,
          storage: %Membrane.HTTPAdaptiveStream.Storages.FileStorage{directory: directory}
      links: [
        |> via_out(:audio)
        |> via_in(Pad.ref(:input, :audio), options: [encoding: :AAC])
        |> to(:hls),
        |> via_out(:video)
        |> via_in(Pad.ref(:input, :video), options: [encoding: :H264])
        |> to(:hls)

    {{:ok, spec: spec}, %{}}

It will listen to a connection from a client and convert RTMP stream into HLS playlist.

Run it with:

{:ok, pid} = Example.Server.start_link()

After this run ffmpeg which will connect to the running server:

ffmpeg -re -i testsrc.flv -f flv -c:v copy -c:a copy rtmp://localhost:5000

`testsrc.flv` can be downloaded from our [tests](test/fixtures/testsrc.flv).

To run this example you will need following extra dependency

{:membrane_http_adaptive_stream_plugin, github: "membraneframework/membrane_http_adaptive_stream_plugin"}

## Copyright and License

Copyright 2021, [Software Mansion](

[![Software Mansion](](

Licensed under the [Apache License, Version 2.0](LICENSE)