You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/useful_concepts/running_membrane_in_elixir_application.md
+53-54Lines changed: 53 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,6 @@
2
2
3
3
This guide outlines best practices for integrating Membrane Pipelines into your Elixir application, specifically focusing on how to attach pipelines to your application's supervision tree.
4
4
5
-
6
-
7
5
In most cases, pipelines are used in one of the following scenarios:
8
6
9
7
- Static Orchestration: Maintaining a single, permanent pipeline that always runs with your application (e.g. mixing output from multiple IP cameras into a single HLS stream).
@@ -17,7 +15,7 @@ In most cases, pipelines are used in one of the following scenarios:
17
15
This approach is ideal when your pipeline architecture is fixed and needs to run continuously from the moment your application starts.
18
16
Imagine an application that monitors a security camera feed to detect people or vehicles in real-time. Such an application could consist of two components:
19
17
20
-
- The Membrane Pipeline which connects to an RTSP stream, decodes the video, and extracts raw frames. It sends these frames to the external process (via a Unix socket or standard input), receives the transformed video back, re-encodes it, and broadcasts the final stream using HLS.
18
+
- The Membrane Pipeline which connects to an SRT stream, decodes the video, and extracts raw frames. It sends these frames to the external process (via a Unix socket or standard input), receives the transformed video back, re-encodes it, and broadcasts the final stream using HLS.
21
19
22
20
- The OS Process being a Python script running a machine learning model like [RF-DETR](https://github.com/roboflow/rf-detr). It reads raw video frames and performs object segmentation, coloring the pixels that correspond to detected objects.
23
21
@@ -28,21 +26,7 @@ defmodule MyProject.Pipeline do
28
26
useMembrane.Pipeline
29
27
30
28
@impltrue
31
-
defhandle_init(_ctx, rtsp_url) do
32
-
spec = [
33
-
child(:source, %Membrane.RTSP.Source{
34
-
transport::tcp,
35
-
allowed_media_types: [:video],
36
-
stream_uri: rtsp_url,
37
-
on_connection_closed::send_eos
38
-
})
39
-
]
40
-
41
-
{[spec: spec], %{}}
42
-
end
43
-
44
-
@impltrue
45
-
defhandle_child_pad_added(:source, :output, _ctx, state) do
To ensure reliability, we might wrap this execution in an [Oban](https://hexdocs.pm/oban/Oban.html) worker.
202
+
To ensure reliability, we might wrap execution of the pipeline in an [Oban](https://hexdocs.pm/oban/Oban.html) worker.
210
203
211
204
Oban is the standard library for background job processing in Elixir. It persists jobs to your database, ensuring that your long-running transcoding tasks are fault-tolerant.
212
205
If the pipeline crashes or the server restarts, Oban will automatically retry the job until it succeeds.
213
206
To install Oban in your project, you can follow this [installation guide](https://hexdocs.pm/oban/installation.html).
214
207
215
-
Assuming that Oban is installed in your project we can define an Oban worker:
208
+
Assuming that Oban is installed in your project and the `:default` queue is configured we can define the Oban worker:
0 commit comments