@eluvio/elv-client-js 4.0.77 → 4.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,6 +97,7 @@ var LiveconfTemplate = {
97
97
  sync_audio_to_stream_id: -1,
98
98
  video_bitrate: null,
99
99
  video_seg_duration_ts: null,
100
+ video_time_base: null,
100
101
  xc_type: 3
101
102
  }
102
103
  }
@@ -156,57 +157,170 @@ var LiveConf = /*#__PURE__*/function () {
156
157
  return roundedFrameRate * 2;
157
158
  }
158
159
  }
160
+
161
+ /*
162
+ * Calculates mez segment durations based on input stream parameters
163
+ *
164
+ * Live input formats have fixed timebase:
165
+ * - MPEG-TS/SRT input stream timebase is 90000
166
+ * - RTMP input stream timebase is 1000 and gets translated to 16000 if not otherwise specified
167
+ *
168
+ * This causes frame duration irregularities for certain frame rates.
169
+ * For example RTMP 60fps has frames of durations 16 and 17. MPEG-TS 59.94fps has frames of
170
+ * durations 1001 and 1002.
171
+ *
172
+ * Live mez segmentation requires that the segment be cut at the specific number of frames, and when
173
+ * the frame durations are irregular we adjust both the video timebase and the video frame duration
174
+ * to make the math possible. This adjustment is also required for live-to-vod conversion.
175
+ *
176
+ * For example for MPEG-TS 59.94fps, the mez segment timebase needs to be 60000
177
+ * (and resulting frame duration is 1001) and for RTMP 60fps the timebase needs to be 15360 (resulting frame
178
+ * duration is 256).
179
+ *
180
+ * @sourceTimescale - adjusted source video stream timescale (eg. MPEGTS 90000, RTMP 16000 )
181
+ * @sampleRate - audio sample rate (commonly 48000 but can be different)
182
+ * @audioCodec - audio codec as a string (eg. "aac")
183
+ * @return - segment encoding parameters
184
+ */
159
185
  }, {
160
186
  key: "calcSegDuration",
161
187
  value: function calcSegDuration(_ref) {
162
- var sourceTimescale = _ref.sourceTimescale;
188
+ var sourceTimescale = _ref.sourceTimescale,
189
+ sampleRate = _ref.sampleRate,
190
+ audioCodec = _ref.audioCodec;
191
+ var seg = {};
192
+ switch (this.probeKind()) {
193
+ case "rtmp":
194
+ seg = this.calcSegDurationRtmp({
195
+ sourceTimescale: sourceTimescale,
196
+ sampleRate: sampleRate,
197
+ audioCodec: audioCodec
198
+ });
199
+ break;
200
+ case "udp":
201
+ case "srt":
202
+ seg = this.calcSegDurationMpegts({
203
+ sourceTimescale: sourceTimescale,
204
+ sampleRate: sampleRate,
205
+ audioCodec: audioCodec
206
+ });
207
+ break;
208
+ default:
209
+ throw "protocol not supported - " + this.probeKind();
210
+ }
211
+ if (audioCodec == "aac") {
212
+ seg.audio = 29.76 * sampleRate;
213
+ } else {
214
+ seg.audio = 29.76 * 48000; // Other codecs are resampled @48000
215
+ }
216
+
217
+ return seg;
218
+ }
219
+ }, {
220
+ key: "calcSegDurationMpegts",
221
+ value: function calcSegDurationMpegts(_ref2) {
222
+ var sourceTimescale = _ref2.sourceTimescale;
163
223
  var videoStream = this.getStreamDataForCodecType("video");
164
224
  var frameRate = videoStream.frame_rate;
165
225
  var seg = {};
166
- seg.audio = 29.76 * 48000;
167
226
  switch (frameRate) {
168
227
  case "24":
169
- seg.video = 30 * sourceTimescale;
228
+ seg.video = sourceTimescale * 30;
170
229
  seg.keyint = 48;
171
230
  seg.duration = "30";
172
231
  break;
173
232
  case "25":
174
- seg.video = 30 * sourceTimescale;
233
+ seg.video = sourceTimescale * 30;
175
234
  seg.keyint = 50;
176
235
  seg.duration = "30";
177
236
  break;
178
237
  case "30":
179
- seg.video = 30 * sourceTimescale;
238
+ seg.video = sourceTimescale * 30;
180
239
  seg.keyint = 60;
181
240
  seg.duration = "30";
182
241
  break;
183
242
  case "30000/1001":
184
- seg.video = 30.03 * sourceTimescale;
243
+ seg.video = sourceTimescale * 30;
185
244
  seg.keyint = 60;
186
245
  seg.duration = "30.03";
187
246
  break;
188
247
  case "48":
189
- seg.video = 30 * sourceTimescale;
248
+ seg.video = sourceTimescale * 30;
190
249
  seg.keyint = 96;
191
250
  seg.duration = "30";
192
251
  break;
193
252
  case "50":
194
- seg.video = 30 * sourceTimescale;
253
+ seg.video = sourceTimescale * 30;
195
254
  seg.keyint = 100;
196
255
  seg.duration = "30";
197
256
  break;
198
257
  case "60":
199
- seg.video = 30 * sourceTimescale;
258
+ seg.video = sourceTimescale * 30;
200
259
  seg.keyint = 120;
201
260
  seg.duration = "30";
202
261
  break;
203
262
  case "60000/1001":
204
- seg.video = 30.03 * sourceTimescale;
263
+ seg.videoTimeBase = 60000;
264
+ seg.video = seg.videoTimeBase * 30.03;
205
265
  seg.keyint = 120;
206
266
  seg.duration = "30.03";
207
267
  break;
208
268
  default:
209
- console.log("Unsupported frame rate", frameRate);
269
+ throw "unsupported frame rate for MPEGTS - " + frameRate;
270
+ break;
271
+ }
272
+ return seg;
273
+ }
274
+ }, {
275
+ key: "calcSegDurationRtmp",
276
+ value: function calcSegDurationRtmp(_ref3) {
277
+ var sourceTimescale = _ref3.sourceTimescale;
278
+ var videoStream = this.getStreamDataForCodecType("video");
279
+ var frameRate = videoStream.frame_rate;
280
+ var seg = {};
281
+ switch (frameRate) {
282
+ case "24":
283
+ seg.video = sourceTimescale * 30;
284
+ seg.keyint = 48;
285
+ seg.duration = "30";
286
+ break;
287
+ case "25":
288
+ seg.video = sourceTimescale * 30;
289
+ seg.keyint = 50;
290
+ seg.duration = "30";
291
+ break;
292
+ case "30":
293
+ seg.video = sourceTimescale * 30;
294
+ seg.keyint = 60;
295
+ seg.duration = "30";
296
+ break;
297
+ case "30000/1001":
298
+ seg.video = sourceTimescale * 30.03;
299
+ seg.keyint = 60;
300
+ seg.duration = "30.03";
301
+ break;
302
+ case "48":
303
+ seg.video = sourceTimescale * 30;
304
+ seg.keyint = 96;
305
+ seg.duration = "30";
306
+ break;
307
+ case "50":
308
+ seg.video = sourceTimescale * 30;
309
+ seg.keyint = 100;
310
+ seg.duration = "30";
311
+ break;
312
+ case "60":
313
+ seg.video = sourceTimescale * 30;
314
+ seg.keyint = 120;
315
+ seg.duration = "30";
316
+ break;
317
+ case "60000/1001":
318
+ seg.video = sourceTimescale * 30.03;
319
+ seg.keyint = 120;
320
+ seg.duration = "30.03";
321
+ break;
322
+ default:
323
+ throw "unsupported frame rate for RTMP - " + frameRate;
210
324
  break;
211
325
  }
212
326
  return seg;
@@ -218,32 +332,33 @@ var LiveConf = /*#__PURE__*/function () {
218
332
  var videoStream = this.getStreamDataForCodecType("video");
219
333
  switch (this.probeKind()) {
220
334
  case "udp":
335
+ case "srt":
221
336
  sync_id = videoStream.stream_id;
222
337
  break;
223
338
  case "rtmp":
224
- sync_id = -1; // Pending fabric API: videoStream.stream_index
339
+ sync_id = videoStream.stream_index;
225
340
  break;
226
341
  }
227
342
  return sync_id;
228
343
  }
229
344
  }, {
230
345
  key: "generateLiveConf",
231
- value: function generateLiveConf(_ref2) {
232
- var audioBitrate = _ref2.audioBitrate,
233
- audioIndex = _ref2.audioIndex,
234
- partTtl = _ref2.partTtl,
235
- channelLayout = _ref2.channelLayout;
346
+ value: function generateLiveConf(_ref4) {
347
+ var audioBitrate = _ref4.audioBitrate,
348
+ audioIndex = _ref4.audioIndex,
349
+ partTtl = _ref4.partTtl,
350
+ channelLayout = _ref4.channelLayout;
236
351
  // gather required data
237
352
  var conf = JSON.parse(JSON.stringify(LiveconfTemplate));
238
353
  var fileName = this.overwriteOriginUrl || this.probeData.format.filename;
239
354
  var audioStream = this.getStreamDataForCodecType("audio");
240
355
  var sampleRate = parseInt(audioStream.sample_rate);
356
+ var audioCodec = audioStream.codec_name;
241
357
  var videoStream = this.getStreamDataForCodecType("video");
242
358
  var sourceTimescale;
243
- console.log("AUDIO", audioStream);
244
- console.log("VIDEO", videoStream);
245
359
 
246
360
  // Fill in liveconf all formats have in common
361
+ conf.live_recording.probe_info = this.probeData;
247
362
  conf.live_recording.fabric_config.ingress_node_api = this.nodeUrl || null;
248
363
  conf.live_recording.fabric_config.ingress_node_id = this.nodeId || null;
249
364
  conf.live_recording.recording_config.recording_params.description;
@@ -267,6 +382,11 @@ var LiveConf = /*#__PURE__*/function () {
267
382
  sourceTimescale = 90000;
268
383
  conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
269
384
  break;
385
+ case "srt":
386
+ sourceTimescale = 90000;
387
+ conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
388
+ conf.live_recording.recording_config.recording_params.live_delay_nano = 4000000000;
389
+ break;
270
390
  case "rtmp":
271
391
  sourceTimescale = 16000;
272
392
  conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
@@ -279,7 +399,9 @@ var LiveConf = /*#__PURE__*/function () {
279
399
  break;
280
400
  }
281
401
  var segDurations = this.calcSegDuration({
282
- sourceTimescale: sourceTimescale
402
+ sourceTimescale: sourceTimescale,
403
+ sampleRate: sampleRate,
404
+ audioCodec: audioCodec
283
405
  });
284
406
 
285
407
  // Segment conditioning parameters
@@ -287,6 +409,15 @@ var LiveConf = /*#__PURE__*/function () {
287
409
  conf.live_recording.recording_config.recording_params.xc_params.audio_seg_duration_ts = segDurations.audio;
288
410
  conf.live_recording.recording_config.recording_params.xc_params.video_seg_duration_ts = segDurations.video;
289
411
  conf.live_recording.recording_config.recording_params.xc_params.force_keyint = segDurations.keyint;
412
+
413
+ // Optional override output timebase and frame duration (ts)
414
+ if (segDurations.videoTimeBase) {
415
+ conf.live_recording.recording_config.recording_params.xc_params.video_time_base = segDurations.videoTimeBase;
416
+ conf.live_recording.recording_config.recording_params.source_timescale = segDurations.videoTimeBase;
417
+ }
418
+ if (segDurations.videoFrameDurationTs) {
419
+ conf.live_recording.recording_config.recording_params.xc_params.video_frame_duration_ts = segDurations.videoFrameDurationTs;
420
+ }
290
421
  switch (videoStream.height) {
291
422
  case 2160:
292
423
  conf.live_recording.recording_config.recording_params.ladder_specs.unshift(LadderTemplate[2160], LadderTemplate[1080], LadderTemplate[720], LadderTemplate[540], LadderTemplate["540_low"]);