@@ -65,7 +65,7 @@ defmodule ExWebRTC.Recorder.Converter do
65
65
}
66
66
67
67
@ typedoc """
68
- Options that can be passed to `convert_manifest!/2` and `convert_path !/2`.
68
+ Options that can be passed to `convert !/2`.
69
69
70
70
* `:output_path` - Directory where Converter will save its artifacts. `#{ @ default_output_path } ` by default.
71
71
* `:s3_upload_config` - If passed, processed recordings will be uploaded to S3-compatible storage.
@@ -75,13 +75,19 @@ defmodule ExWebRTC.Recorder.Converter do
75
75
See `t:ExWebRTC.Recorder.S3.override_config/0` for more info.
76
76
* `:thumbnails_ctx` - If passed, Converter will generate thumbnails for the output files.
77
77
See `t:thumbnails_ctx/0` for more info.
78
+ * `:only_rids` - By default, when processing a video track with multiple layers (i.e. simulcast),
79
+ Converter generates multiple output files, one per layer. If passed, Converter will only process
80
+ the layers with RIDs present in this list. E.g. if you want to receive a single video file
81
+ from the layer `"h"`, pass `["h"]`. For single-layer tracks RID is set to `nil`,
82
+ so if you want to handle both simulcast and regular tracks, pass `["h", nil]`.
78
83
"""
79
84
@ type option ::
80
85
{ :output_path , Path . t ( ) }
81
86
| { :s3_upload_config , keyword ( ) }
82
87
| { :download_path , Path . t ( ) }
83
88
| { :s3_download_config , keyword ( ) }
84
89
| { :thumbnails_ctx , thumbnails_ctx ( ) }
90
+ | { :only_rids , [ ExWebRTC.MediaStreamTrack . rid ( ) | nil ] }
85
91
86
92
@ type options :: [ option ( ) ]
87
93
@@ -116,7 +122,7 @@ defmodule ExWebRTC.Recorder.Converter do
116
122
117
123
def convert! ( recorder_manifest , options ) when map_size ( recorder_manifest ) > 0 do
118
124
thumbnails_ctx =
119
- case Keyword . get ( options , :thumbnails_ctx , nil ) do
125
+ case Keyword . get ( options , :thumbnails_ctx ) do
120
126
nil ->
121
127
nil
122
128
@@ -127,6 +133,15 @@ defmodule ExWebRTC.Recorder.Converter do
127
133
}
128
134
end
129
135
136
+ rid_allowed? =
137
+ case Keyword . get ( options , :only_rids ) do
138
+ nil ->
139
+ fn _rid -> true end
140
+
141
+ allowed_rids ->
142
+ fn rid -> Enum . member? ( allowed_rids , rid ) end
143
+ end
144
+
130
145
output_path = Keyword . get ( options , :output_path , @ default_output_path ) |> Path . expand ( )
131
146
download_path = Keyword . get ( options , :download_path , @ default_download_path ) |> Path . expand ( )
132
147
File . mkdir_p! ( output_path )
@@ -143,7 +158,7 @@ defmodule ExWebRTC.Recorder.Converter do
143
158
output_manifest =
144
159
recorder_manifest
145
160
|> fetch_remote_files! ( download_path , download_config )
146
- |> do_convert_manifest! ( output_path , thumbnails_ctx )
161
+ |> do_convert_manifest! ( output_path , thumbnails_ctx , rid_allowed? )
147
162
148
163
result_manifest =
149
164
if upload_handler != nil do
@@ -159,6 +174,12 @@ defmodule ExWebRTC.Recorder.Converter do
159
174
S3.UploadHandler . process_result ( upload_handler , task_result )
160
175
end
161
176
177
+ # UploadHandler spawns a task that gets auto-monitored
178
+ # We don't want to propagate this message
179
+ receive do
180
+ { :DOWN , ^ ref , :process , _pid , _reason } -> :ok
181
+ end
182
+
162
183
upload_handler_result_manifest
163
184
|> __MODULE__ . Manifest . from_upload_handler_manifest ( output_manifest )
164
185
else
@@ -197,7 +218,7 @@ defmodule ExWebRTC.Recorder.Converter do
197
218
end
198
219
end
199
220
200
- defp do_convert_manifest! ( manifest , output_path , thumbnails_ctx ) do
221
+ defp do_convert_manifest! ( manifest , output_path , thumbnails_ctx , rid_allowed? ) do
201
222
stream_map =
202
223
Enum . reduce ( manifest , % { } , fn { id , track } , stream_map ->
203
224
% {
@@ -218,6 +239,8 @@ defmodule ExWebRTC.Recorder.Converter do
218
239
output_metadata =
219
240
case kind do
220
241
:video ->
242
+ rid_map = filter_rids ( rid_map , rid_allowed? )
243
+
221
244
convert_video_track ( id , rid_map , output_path , packets )
222
245
223
246
:audio ->
@@ -405,4 +428,8 @@ defmodule ExWebRTC.Recorder.Converter do
405
428
store
406
429
end
407
430
end
431
+
432
+ defp filter_rids ( rid_map , rid_allowed? ) do
433
+ Map . filter ( rid_map , fn { rid , _rid_idx } -> rid_allowed? . ( rid ) end )
434
+ end
408
435
end
0 commit comments