Skip to content

Commit

Permalink
update readmes, convert rtp_to_hls to script
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-hek committed Dec 18, 2023
1 parent c68406e commit 1f4fb0e
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 600 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
demo: rtmp_to_hls
- build_test:
demo: rtp
- build_test:
- build_exs:
demo: rtp_to_hls
- build_test:
demo: rtsp_to_hls
Expand Down
128 changes: 6 additions & 122 deletions rtmp_to_hls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,152 +22,36 @@ The internal architecture of the server is presented below:

### Client

The client is just a simple javascript application using the [HLS.js](https://github.com/video-dev/hls.js/) web player.
The client is just a simple JavaScript application using the [HLS.js](https://github.com/video-dev/hls.js/) web player.

## Prerequisites and running the demo

Below is the instruction for the installation of required dependencies and how to run this demo on various operating systems:
## Running the demo

<details>
<summary>
<b>macOS</b>
</summary>

### Prerequisites

To successfully build and install the plugin, you need to have FFmpeg 4.\* installed on your system.

Furthermore, make sure you have `Elixir` and `Erlang` installed on your machine. For installation details, see: https://elixir-lang.org/install.html

```shell
brew install ffmpeg
```

### Running the demo

To run the demo, clone the membrane_demo repository and checkout to the demo directory:

```shell
git clone https://github.com/membraneframework/membrane_demo
cd membrane_demo/rtmp_to_hls
```

Then you need to download the dependencies of the mix project:
To run the demo, you'll need to have [Elixir installed](https://elixir-lang.org/install.html). Then, download the dependencies and start the server:

```shell
mix deps.get
```

You may be asked to install `Hex` and then `rebar3`.

> In case of issues with the compilation of membrane_h264_ffmpeg_plugin, enter:
>
> ```shell
> mix deps.update bundlex
> ```
>
> and then install pkg-config:
>
> ```shell
> brew install pkg-config
> ```
Finally, you can start the Phoenix server:
```shell
mix phx.server
```

The server will be waiting for an RTMP stream on `localhost:9006`, and the client of the application will be available on `localhost:4000`.

### Exemplary stream generation with OBS
## Exemplary stream generation with OBS

You can send RTMP stream onto `localhost:9006` with your favorite streaming tool. Below we present how to generate an RTMP stream with
[OBS](https://obsproject.com).
Once you have OBS installed, you can perform the following steps:

1. Open the OBS application
2. Open the `Settings` windows
3. Go to the `Stream` tab and set the value in the `Server` field to: `rtmp://localhost:9006` (the address where the server is waiting for the stream)
3. Go to the `Stream` tab and set the value in the `Server` field to `rtmp://localhost:9006` (the address where the server is waiting for the stream)
4. Go to the `Output`, set output mode to `Advanced`, and set `Keyframe Interval` to 2 seconds.
5. Finally, you can go back to the main window and start streaming with the `Start Streaming` button.

Below you can see how to set the appropriate settings (steps 2) and 3) from the list of steps above):
![OBS settings](doc_assets/OBS_settings.webp)

</details>

<details>
<summary>
<b>Ubuntu</b>
</summary>

### Prerequisites

To successfully build and install the plugin, you need to have FFmpeg 4.\* installed on your system.

```shell
apt install ffmpeg
```

Furthermore, make sure you have `Elixir` and `Erlang` installed on your machine. For installation details, see: https://elixir-lang.org/install.html

On Ubuntu, we recommend installation through `asdf`, see: https://asdf-vm.com/guide/getting-started.html

### Running the demo

To run the demo, clone the membrane_demo repository and checkout to the demo directory:
Below you can see how to set the appropriate settings (steps 2. and 3. from the list of steps above):

```shell
git clone https://github.com/membraneframework/membrane_demo
cd membrane_demo/rtmp_to_hls
```

Then you need to download the dependencies of the mix project:

```shell
mix deps.get
```

You may be asked to install `Hex` and then `rebar3`.

> In case of installation issues with Hex on Ubuntu, try updating the system packages first by entering the command:
>
> ```shell
> sudo apt-get update
> ```
> In case of issues with the compilation of membrane_h264_ffmpeg_plugin, enter:
>
> ```shell
> mix deps.update bundlex
> ```
Finally, you can start the Phoenix server:
```shell
mix phx.server
```
The server will be waiting for an RTMP stream on `localhost:9006`, and the client of the application will be available on `localhost:4000`.
### Exemplary stream generation with OBS
You can send RTMP stream onto `localhost:9006` with your favorite streaming tool. Below we present how to generate an RTMP stream with
[OBS](https://obsproject.com).
Once you have OBS installed, you can perform the following steps:
1. Open the OBS application
2. Open the `Settings` windows
3. Go to the `Stream` tab and set the value in the `Server` field to: `rtmp://localhost:9006` (the address where the server is waiting for the stream)
4. Go to the `Output`, set output mode to `Advanced`, and set `Keyframe Interval` to 2 seconds.
5. Finally, you can go back to the main window and start streaming with the `Start Streaming` button.
Below you can see how to set the appropriate settings (steps 2) and 3) from the list of steps above):
![OBS settings](doc_assets/OBS_settings.webp)

</details>
## Copyright and License

Copyright 2018, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane)
Expand Down
183 changes: 13 additions & 170 deletions rtp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,196 +2,39 @@

This project demonstrates handling RTP in Membrane.

This example uses [RTP plugin](https://github.com/membraneframework/membrane_rtp_plugin) that is responsible for
receiving and sending RTP streams.
This example uses [RTP plugin](https://github.com/membraneframework/membrane_rtp_plugin) that is responsible for receiving and sending RTP streams.

## Prerequisites and running the demo
## Running the demo

Below is the instruction for the installation of required dependencies and how to run this demo on various operating systems:

<details>
<summary>
<b>macOS</b>
</summary>

### Prerequisites

Make sure you have the following packages installed in your system:

- FFmpeg 4.x
- SDL 2
- PortAudio

```shell
brew install ffmpeg portaudio sdl2
```

Furthermore, make sure you have `Elixir` and `Erlang` installed on your machine. For installation details, see: https://elixir-lang.org/install.html

### Run the demo

To run the demo, clone the membrane_demo repository and checkout to the demo directory:

```shell
git clone https://github.com/membraneframework/membrane_demo
cd membrane_demo/rtp
```

Then you need to download the dependencies of the mix project:

```shell
mix deps.get
```

You may be asked to install `Hex` and then `rebar3`.

> In case of issues with the compilation of ex_libsrtp, enter:
>
> ```shell
> mix deps.update bundlex
> ```
>
> and then install pkg-config and srtp:
>
> ```shell
> brew install pkg-config srtp
> ```
> In case of issues with compilation of membrane_opus_plugin, install `opus`:
>
> ```shell
> brew install opus
> ```
>
> and if you have macOS M1/M2 (Apple silicon) add following lines to your `~/.zshrc` file:
>
> ```shell
> export C_INCLUDE_PATH=$C_INCLUDE_PATH:$(brew --cellar)/opus/1.3.1/include
> export LIBRARY_PATH=$LIBRARY_PATH:$(brew --cellar)/opus/1.3.1/lib
> ```
>
> and restart your terminal.
Finally, you can run the demo:
- Open a terminal in the project directory
- Type: `mix run --no-halt receive.exs`
- Open another terminal in the project directory
- Type: `mix run --no-halt send.exs`
You should be able to see an SDL player showing an example video.
The sender pipeline (run with `send.exs`) takes sample audio and video files and sends them with RTP.
The receiving pipeline (run with `receive.exs`) depayloads the audio and video streams and plays them.
If you wish to stream using SRTP, add a `--secure` flag when running both `receive.exs` and `send.exs`.
Alternatively, the stream can be sent using [gstreamer](https://gstreamer.freedesktop.org/). In this case, you only need to start the receiving pipeline:
```shell
mix run --no-halt receive.exs
```
and launch gstreamer:
```shell
gst-launch-1.0 -v audiotestsrc ! audio/x-raw,rate=48000,channels=2 ! opusenc ! rtpopuspay pt=120 ! udpsink host=127.0.0.1 port=5002\
videotestsrc ! video/x-raw,format=I420 ! x264enc key-int-max=10 tune=zerolatency ! rtph264pay pt=96 ! udpsink host=127.0.0.1 port=5000
```
</details>
<details>
<summary>
<b>Ubuntu</b>
</summary>
### Prerequisites
Make sure you have the following packages installed in your system:
- FFmpeg 4.x
- SDL 2
- PortAudio
```shell
apt install ffmpeg portaudio19-dev libsdl2-dev
```
Furthermore, make sure you have `Elixir` and `Erlang` installed on your machine. For installation details, see: https://elixir-lang.org/install.html
On Ubuntu, we recommend installation through `asdf`, see: https://asdf-vm.com/guide/getting-started.html
### Run the demo
To run the demo, clone the membrane_demo repository and checkout to the demo directory:
```shell
git clone https://github.com/membraneframework/membrane_demo
cd membrane_demo/rtp
```
Then you need to download the dependencies of the mix project:
```shell
mix deps.get
```
You may be asked to install `Hex` and then `rebar3`.
> In case of installation issues with Hex on Ubuntu, try updating the system packages first by entering the command:
>
> ```shell
> sudo apt-get update
> ```
> In case of issues with the compilation of ex_libsrtp, enter:
>
> ```shell
> mix deps.update bundlex
> ```
> In case of issues with compilation of membrane_opus_plugin, install `opus`:
>
> ```shell
> apt install libopus-dev
> ```
>
> and then install `libavcodec`:
>
> ```shell
> apt install libavcodec-dev
> ```
Finally, you can run the demo:
To run the demo, you'll need to have [Elixir installed](https://elixir-lang.org/install.html). Then, do the following:

- Open a terminal in the project directory
- Type: `mix run --no-halt receive.exs`
- Type `mix deps.get` to download dependencies
- Type `mix run receive.exs` to run the receiving pipeline
- Wait until the script runs
- Open another terminal in the project directory
- Type: `mix run --no-halt send.exs`
- Type `mix run send.exs` to run the sending pipeline

You should be able to see an SDL player showing an example video.
You should be able to see a player showing an example video.

The sender pipeline (run with `send.exs`) takes sample audio and video files and sends them with RTP.
The receiving pipeline (run with `receive.exs`) depayloads the audio and video streams and plays them.
The sender pipeline (run with `send.exs`) takes sample audio and video files and sends them via RTP.
The receiving pipeline (run with `receive.exs`) receives the audio and video streams and plays them.

If you wish to stream using SRTP, add a `--secure` flag when running both `receive.exs` and `send.exs`.

Alternatively, the stream can be sent using [gstreamer](https://gstreamer.freedesktop.org/). In this case, you only need to start the receiving pipeline:
You can also use another tool, like [GStreamer](https://gstreamer.freedesktop.org/), to send the stream. In this case, you only need to start the receiving pipeline:

```shell
mix run --no-halt receive.exs
mix run receive.exs
```

and launch gstreamer:
and launch GStreamer:

```shell
gst-launch-1.0 -v audiotestsrc ! audio/x-raw,rate=48000,channels=2 ! opusenc ! rtpopuspay pt=120 ! udpsink host=127.0.0.1 port=5002\
videotestsrc ! video/x-raw,format=I420 ! x264enc key-int-max=10 tune=zerolatency ! rtph264pay pt=96 ! udpsink host=127.0.0.1 port=5000
```

</details>
## Copyright and License

Copyright 2018, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane)
Expand Down
2 changes: 2 additions & 0 deletions rtp/receive.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ alias Membrane.Demo.RTP.ReceivePipeline
secure?: "--secure" in System.argv(),
srtp_key: String.duplicate("a", 30)
})

Process.sleep(:infinity)
2 changes: 2 additions & 0 deletions rtp/send.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ alias Membrane.Demo.RTP.SendPipeline
secure?: "--secure" in System.argv(),
srtp_key: String.duplicate("a", 30)
})

Process.sleep(:infinity)
3 changes: 1 addition & 2 deletions rtp_to_hls/.formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
import_deps: [:membrane_core]
inputs: ["*.exs"]
]
Loading

0 comments on commit 1f4fb0e

Please sign in to comment.