@@ -6,7 +6,7 @@ defmodule RecordingConverter.Pipeline do
6
6
7
7
alias Membrane.AWS.S3.Source
8
8
alias Membrane.HTTPAdaptiveStream . { SinkBin , Storages }
9
- alias Membrane.Time
9
+ alias Membrane.LiveCompositor
10
10
alias RecordingConverter . { Compositor , ReportParser }
11
11
12
12
@ segment_duration 3
@@ -17,7 +17,12 @@ defmodule RecordingConverter.Pipeline do
17
17
18
18
@ impl true
19
19
def handle_init ( _ctx , opts ) do
20
- output_directory = opts . output_directory
20
+ { [ ] , opts }
21
+ end
22
+
23
+ @ impl true
24
+ def handle_setup ( _ctx , state ) do
25
+ output_directory = state . output_directory
21
26
22
27
with { :ok , files } when files != [ ] <- File . ls ( output_directory ) do
23
28
Logger . warning (
@@ -29,19 +34,6 @@ defmodule RecordingConverter.Pipeline do
29
34
30
35
File . mkdir_p! ( output_directory )
31
36
32
- main_spec =
33
- [
34
- generate_sink_bin ( output_directory ) ,
35
- generate_output_audio_branch ( opts ) ,
36
- generate_output_video_branch ( opts )
37
- ]
38
- |> Enum . reject ( & is_nil ( & 1 ) )
39
-
40
- { [ spec: main_spec ] , opts }
41
- end
42
-
43
- @ impl true
44
- def handle_setup ( _ctx , state ) do
45
37
report_path = s3_file_path ( @ report_file , state )
46
38
47
39
tracks = ReportParser . get_tracks ( state . bucket_name , report_path )
@@ -52,15 +44,21 @@ defmodule RecordingConverter.Pipeline do
52
44
53
45
tracks_spec = Enum . map ( tracks , & create_branch ( & 1 , state ) )
54
46
55
- track_actions =
56
- tracks
57
- |> ReportParser . get_all_track_actions ( )
58
- |> Enum . map ( & notify_compositor / 1 )
47
+ track_actions = ReportParser . get_all_track_actions ( tracks )
59
48
60
- register_image_action =
61
- state . image_url |> Compositor . register_image_action ( ) |> notify_compositor ( )
49
+ register_image_action = Compositor . register_image_action ( state . image_url )
62
50
63
- actions = [ { :spec , tracks_spec } , register_image_action | track_actions ]
51
+ all_compositor_actions = [ register_image_action | track_actions ]
52
+
53
+ main_spec =
54
+ [
55
+ generate_sink_bin ( output_directory ) ,
56
+ generate_output_audio_branch ( state , all_compositor_actions ) ,
57
+ generate_output_video_branch ( state )
58
+ ]
59
+ |> Enum . reject ( & is_nil ( & 1 ) )
60
+
61
+ actions = [ { :spec , main_spec ++ tracks_spec } ]
64
62
65
63
{ actions ,
66
64
% {
@@ -90,24 +88,39 @@ defmodule RecordingConverter.Pipeline do
90
88
91
89
@ impl true
92
90
def handle_child_notification (
93
- { :lc_request_response , req , % Req.Response { status: response_code , body: response_body } ,
94
- _lc_ctx } ,
95
- _child ,
91
+ { :request_result , _req , { :error , error } } ,
92
+ :video_compositor ,
96
93
_membrane_ctx ,
97
94
state
98
95
) do
99
- if response_code != 200 do
100
- raise """
101
- Request failed.
102
- Request: `#{ inspect ( req ) } .
103
- Response code: #{ response_code } .
104
- Response body: #{ inspect ( response_body ) } .
105
- """
106
- end
96
+ raise """
97
+ Request failed with error: #{ inspect ( error ) }
98
+ """
107
99
108
100
{ [ ] , state }
109
101
end
110
102
103
+ @ impl true
104
+ def handle_child_notification (
105
+ { atom , _pad , _lc_ctx } ,
106
+ :video_compositor ,
107
+ _membrane_ctx ,
108
+ state
109
+ )
110
+ when atom in [ :input_delivered , :input_playing , :input_eos ] do
111
+ { [ ] , state }
112
+ end
113
+
114
+ @ impl true
115
+ def handle_child_notification ( :start_of_stream , :hls_sink_bin , _ctx , state ) do
116
+ { [ ] , state }
117
+ end
118
+
119
+ @ impl true
120
+ def handle_child_notification ( { :track_playable , _track } , :hls_sink_bin , _ctx , state ) do
121
+ { [ ] , state }
122
+ end
123
+
111
124
@ impl true
112
125
def handle_child_notification ( :end_of_stream , :hls_sink_bin , _ctx , state ) do
113
126
{ [ terminate: :normal ] , state }
@@ -143,14 +156,12 @@ defmodule RecordingConverter.Pipeline do
143
156
get_child ( :video_compositor )
144
157
|> via_out ( Pad . ref ( :video_output , Compositor . video_output_id ( ) ) ,
145
158
options: [
146
- encoder_preset: :slow ,
147
159
width: @ output_width ,
148
160
height: @ output_height ,
149
- initial:
150
- Compositor . scene ( [
151
- % { type: :input_stream , input_id: "video_input_0" , id: "child_0" }
152
- ] ) ,
153
- send_eos_when: :all_inputs
161
+ encoder: % LiveCompositor.Encoder.FFmpegH264 { preset: :slow } ,
162
+ initial: % {
163
+ root: Compositor . scene ( [ ] )
164
+ }
154
165
]
155
166
)
156
167
|> child ( :output_video_parser , % Membrane.H264.Parser {
@@ -160,27 +171,27 @@ defmodule RecordingConverter.Pipeline do
160
171
|> via_in ( Pad . ref ( :input , :video ) ,
161
172
options: [
162
173
encoding: :H264 ,
163
- segment_duration: Time . seconds ( @ segment_duration )
174
+ segment_duration: Membrane. Time. seconds ( @ segment_duration )
164
175
]
165
176
)
166
177
|> get_child ( :hls_sink_bin )
167
178
end
168
179
169
- defp generate_output_audio_branch ( state ) do
180
+ defp generate_output_audio_branch ( state , compositor_actions ) do
170
181
child ( :video_compositor , % Membrane.LiveCompositor {
171
182
framerate: { 30 , 1 } ,
172
183
composing_strategy: :offline_processing ,
173
- server_setup: Compositor . server_setup ( state . compositor_path )
184
+ server_setup: Compositor . server_setup ( state . compositor_path ) ,
185
+ init_requests: compositor_actions
174
186
} )
175
187
|> via_out ( Pad . ref ( :audio_output , Compositor . audio_output_id ( ) ) ,
176
188
options: [
177
- channels: :stereo ,
178
- initial: % {
179
- inputs: [
180
- % { input_id: "audio_input_0" , volume: 0.2 }
181
- ]
189
+ encoder: % LiveCompositor.Encoder.Opus {
190
+ channels: :stereo
182
191
} ,
183
- send_eos_when: :all_inputs
192
+ initial: % {
193
+ inputs: [ ]
194
+ }
184
195
]
185
196
)
186
197
|> child ( :opus_output_parser , Membrane.Opus.Parser )
@@ -190,7 +201,7 @@ defmodule RecordingConverter.Pipeline do
190
201
|> via_in ( Pad . ref ( :input , :audio ) ,
191
202
options: [
192
203
encoding: :AAC ,
193
- segment_duration: Time . seconds ( @ segment_duration )
204
+ segment_duration: Membrane. Time. seconds ( @ segment_duration )
194
205
]
195
206
)
196
207
|> get_child ( :hls_sink_bin )
0 commit comments