-
Notifications
You must be signed in to change notification settings - Fork 27
/
MultiCodecEncoding.ts
1226 lines (1083 loc) · 41.6 KB
/
MultiCodecEncoding.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ConfigProvider from '../common/ConfigProvider';
import {join} from 'path';
import BitmovinApi, {
AacAudioConfiguration,
AclEntry,
AclPermission,
AudioAdaptationSet,
AudioMediaInfo,
CmafMuxing,
CodecConfiguration,
ConsoleLogger,
DashCmafRepresentation,
DashFmp4Representation,
DashManifest,
DashProfile,
DashRepresentationType,
DashWebmRepresentation,
DolbyDigitalAudioConfiguration,
DolbyDigitalChannelLayout,
Encoding,
EncodingOutput,
Fmp4Muxing,
H264VideoConfiguration,
H265VideoConfiguration,
HlsManifest,
HttpInput,
Input,
MessageType,
Muxing,
MuxingStream,
Output,
Period,
PresetConfiguration,
S3Output,
Status,
Stream,
StreamInfo,
StreamInput,
StreamSelectionMode,
Task,
TsMuxing,
VideoAdaptationSet,
VorbisAudioConfiguration,
Vp9VideoConfiguration,
WebmMuxing
} from '@bitmovin/api-sdk';
/**
* This example demonstrates how to use different codecs and muxing types in a single encoding.
*
* <p>The following configuration parameters are expected:
*
* <ul>
* <li>BITMOVIN_API_KEY - Your API key for the Bitmovin API
* <li>BITMOVIN_TENANT_ORG_ID - (optional) The ID of the Organisation in which you want to perform the encoding.
* <li>HTTP_INPUT_HOST - The Hostname or IP address of the HTTP server hosting your input files,
* e.g.: my-storage.biz
* <li>HTTP_INPUT_FILE_PATH - The path to your input file on the provided HTTP server Example:
* videos/1080p_Sintel.mp4
* <li>S3_OUTPUT_BUCKET_NAME - The name of your S3 output bucket. Example: my-bucket-name
* <li>S3_OUTPUT_ACCESS_KEY - The access key of your S3 output bucket
* <li>S3_OUTPUT_SECRET_KEY - The secret key of your S3 output bucket
* <li>S3_OUTPUT_BASE_PATH - The base path on your S3 output bucket where content will be written.
* Example: /outputs
* </ul>
*
* <p>Configuration parameters will be retrieved from these sources in the listed order:
*
* <ol>
* <li>command line arguments (eg BITMOVIN_API_KEY=xyz)
* <li>properties file located in the root folder of the JAVA examples at ./examples.properties
* (see examples.properties.template as reference)
* <li>environment variables
* <li>properties file located in the home folder at ~/.bitmovin/examples.properties (see
* examples.properties.template as reference)
* </ol>
*/
const exampleName = `MultiCodecEncoding`;
const DATE_STRING = new Date().toISOString();
const HLS_AUDIO_GROUP_AAC_FMP4 = 'audio-aac-fmp4';
const HLS_AUDIO_GROUP_AAC_TS = 'audio-aac-ts';
const HLS_AUDIO_GROUP_DOLBY_DIGITAL_FMP4 = 'audio-dolby-digital-fmp4';
const configProvider: ConfigProvider = new ConfigProvider();
const bitmovinApi: BitmovinApi = new BitmovinApi({
apiKey: configProvider.getBitmovinApiKey(),
// uncomment the following line if you are working with a multi-tenant account
// tenantOrgId: configProvider.getBitmovinTenantOrgId(),
logger: new ConsoleLogger()
});
class Rendition {
height: number;
bitrate: number;
constructor(height: number, bitrate: number) {
this.height = height;
this.bitrate = bitrate;
}
}
class H264AndAacEncodingTracking {
public encoding: Encoding;
renditions: Array<Rendition> = [
new Rendition(234, 145000),
new Rendition(360, 365000),
new Rendition(432, 730000),
new Rendition(540, 2000000),
new Rendition(720, 3000000)
];
h264VideoStreams: Map<Rendition, Stream> = new Map<Rendition, Stream>();
h264TsMuxings: Map<Rendition, TsMuxing> = new Map<Rendition, TsMuxing>();
h264CmafMuxings: Map<Rendition, CmafMuxing> = new Map<Rendition, CmafMuxing>();
aacAudioStream: Stream;
aacFmp4Muxing: Fmp4Muxing;
aacTsMuxing: TsMuxing;
readonly H264_TS_SEGMENTS_PATH = 'video/h264/ts';
readonly H264_CMAF_SEGMENTS_PATH = 'video/h264/cmaf';
readonly AAC_FMP4_SEGMENTS_PATH = 'audio/aac/fmp4';
readonly AAC_TS_SEGMENTS_PATH = 'audio/aac/ts';
constructor(encoding: Encoding) {
this.encoding = encoding;
}
}
class H265AndDolbyDigitalEncodingTracking {
encoding: Encoding;
renditions: Array<Rendition> = [
new Rendition(540, 600000),
new Rendition(720, 2400000),
new Rendition(1080, 4500000),
new Rendition(2160, 11600000)
];
h265VideoStreams: Map<Rendition, Stream> = new Map<Rendition, Stream>();
h265Fmp4Muxings: Map<Rendition, Fmp4Muxing> = new Map<Rendition, Fmp4Muxing>();
dolbyDigitalAudioStream: Stream;
dolbyDigitalFmp4Muxing: Fmp4Muxing;
readonly H265_FMP4_SEGMENTS_PATH = 'video/h265/fmp4';
readonly DOLBY_DIGITAL_FMP4_SEGMENTS_PATH = 'audio/dolby-digital/fmp4';
constructor(encoding: Encoding) {
this.encoding = encoding;
}
}
class Vp9AndVorbisEncodingTracking {
encoding: Encoding;
renditions: Array<Rendition> = [
new Rendition(540, 600000),
new Rendition(720, 2400000),
new Rendition(1080, 4500000),
new Rendition(2160, 11600000)
];
vp9WebmMuxings: Map<Rendition, WebmMuxing> = new Map<Rendition, WebmMuxing>();
vorbisWebmMuxing: WebmMuxing;
readonly VP9_WEBM_SEGMENTS_PATH = 'video/vp9/webm';
readonly VORBIS_WEBM_SEGMENTS_PATH = 'audio/vorbis/webm';
constructor(encoding: Encoding) {
this.encoding = encoding;
}
}
async function main() {
const input = await createHttpInput(configProvider.getHttpInputHost());
const inputPath = configProvider.getHttpInputFilePath();
const output = await createS3Output(
configProvider.getS3OutputBucketName(),
configProvider.getS3OutputAccessKey(),
configProvider.getS3OutputSecretKey()
);
const h264AndAacEncodingTracking = await createH264AndAacEncoding(input, inputPath, output);
const h265AndDolbyDigitalEncodingTracking = await createH265AndDolbyDigitalEncoding(input, inputPath, output);
const vp9AndVorbisEncodingTracking = await createVp9AndVorbisEncoding(input, inputPath, output);
await Promise.all([
executeEncoding(h264AndAacEncodingTracking.encoding),
executeEncoding(h265AndDolbyDigitalEncodingTracking.encoding),
executeEncoding(vp9AndVorbisEncodingTracking.encoding)
]);
const dashManifest = await createDashManifestWithRepresentations(
output,
h264AndAacEncodingTracking,
h265AndDolbyDigitalEncodingTracking,
vp9AndVorbisEncodingTracking
);
await executeDashManifest(dashManifest);
const hlsManifest = await createHlsManifestWithRepresentations(
output,
h264AndAacEncodingTracking,
h265AndDolbyDigitalEncodingTracking
);
await executeHlsManifest(hlsManifest);
}
/**
* Creates the encoding with H264 codec/TS muxing, H264 codec/CMAF muxing, AAC codec/fMP4 muxing
*
* @param input the input that should be used
* @param inputPath the path to the input file
* @param output the output that should be used
* @return the tracking information for the encoding
*/
async function createH264AndAacEncoding(
input: Input,
inputPath: string,
output: Output
): Promise<H264AndAacEncodingTracking> {
const encoding = await createEncoding(
'H.264 Encoding',
'H.264 -> TS muxing, H.264 -> CMAF muxing, AAC -> fMP4 muxing, AAC -> TS muxing'
);
const encodingTracking = new H264AndAacEncodingTracking(encoding);
for (const rendition of encodingTracking.renditions) {
const videoConfiguration = await createH264VideoConfig(rendition.height, rendition.bitrate);
const videoStream = await createStream(encoding, input, inputPath, videoConfiguration);
const cmafMuxing = await createCmafMuxing(
encoding,
output,
`${encodingTracking.H264_CMAF_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
videoStream
);
const tsMuxing = await createTsMuxing(
encoding,
output,
`${encodingTracking.H264_TS_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
videoStream
);
encodingTracking.h264VideoStreams.set(rendition, videoStream);
encodingTracking.h264CmafMuxings.set(rendition, cmafMuxing);
encodingTracking.h264TsMuxings.set(rendition, tsMuxing);
}
const aacConfig = await createAacAudioConfig();
const aacAudioStream = await createStream(encoding, input, inputPath, aacConfig);
encodingTracking.aacAudioStream = aacAudioStream;
encodingTracking.aacFmp4Muxing = await createFmp4Muxing(
encoding,
output,
encodingTracking.AAC_FMP4_SEGMENTS_PATH,
aacAudioStream
);
encodingTracking.aacTsMuxing = await createTsMuxing(
encoding,
output,
encodingTracking.AAC_TS_SEGMENTS_PATH,
aacAudioStream
);
return encodingTracking;
}
/**
* Creates the encoding with H265 codec/fMP4 muxing, Dolby Digital codec/fMP4 muxing
*
* @param input the input that should be used
* @param inputPath the path to the input file
* @param output the output that should be used
* @return the tracking information for the encoding
*/
async function createH265AndDolbyDigitalEncoding(
input: Input,
inputPath: string,
output: Output
): Promise<H265AndDolbyDigitalEncodingTracking> {
const encoding = await createEncoding('H.265 Encoding', 'H.265 -> fMP4 muxing, Dolby Digital -> fMP4 muxing');
const encodingTracking = new H265AndDolbyDigitalEncodingTracking(encoding);
for (const rendition of encodingTracking.renditions) {
const videoConfiguration = await createH265VideoConfig(rendition.height, rendition.bitrate);
const videoStream = await createStream(encoding, input, inputPath, videoConfiguration);
const fmp4Muxing = await createFmp4Muxing(
encoding,
output,
`${encodingTracking.H265_FMP4_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
videoStream
);
encodingTracking.h265VideoStreams.set(rendition, videoStream);
encodingTracking.h265Fmp4Muxings.set(rendition, fmp4Muxing);
}
const dolbyDigitalConfig = await createDolbyDigitalAudioConfig();
const dolbyDigitalAudioStream = await createStream(encoding, input, inputPath, dolbyDigitalConfig);
encodingTracking.dolbyDigitalAudioStream = dolbyDigitalAudioStream;
encodingTracking.dolbyDigitalFmp4Muxing = await createFmp4Muxing(
encoding,
output,
encodingTracking.DOLBY_DIGITAL_FMP4_SEGMENTS_PATH,
dolbyDigitalAudioStream
);
return encodingTracking;
}
/**
* Created the encoding with VP9 codec/WebM muxing, Vorbis codec / WebM muxing
*
* @param input the input that should be used
* @param inputPath the path to the input file
* @param output the output that should be used
* @return the tracking information for the encoding
*/
async function createVp9AndVorbisEncoding(
input: Input,
inputPath: string,
output: Output
): Promise<Vp9AndVorbisEncodingTracking> {
const encoding = await createEncoding('VP9/Vorbis Encoding', 'VP9 -> WebM muxing, Vorbis -> WebM muxing');
const encodingTracking = new Vp9AndVorbisEncodingTracking(encoding);
for (const rendition of encodingTracking.renditions) {
const videoConfiguration = await createVp9VideoConfiguration(rendition.height, rendition.bitrate);
const videoStream = await createStream(encoding, input, inputPath, videoConfiguration);
const fmp4Muxing = await createWebmMuxing(
encoding,
output,
`${encodingTracking.VP9_WEBM_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
videoStream
);
encodingTracking.vp9WebmMuxings.set(rendition, fmp4Muxing);
}
const vorbisAudioConfig = await createVorbisAudioConfiguration();
const vorbisAudioStream = await createStream(encoding, input, inputPath, vorbisAudioConfig);
encodingTracking.vorbisWebmMuxing = await createWebmMuxing(
encoding,
output,
encodingTracking.VORBIS_WEBM_SEGMENTS_PATH,
vorbisAudioStream
);
return encodingTracking;
}
/**
* Creates the DASH manifest with all the representations.
*
* @param output the output that should be used
* @param h264AndAacEncodingTracking the tracking information for the H264/AAC encoding
* @param h265AndDolbyDigitalEncodingTracking the tracking information for the H265 encoding
* @param vp9AndVorbisEncodingTracking the tracking information for the VP9/Vorbis encoding
* @return the created DASH manifest
*/
async function createDashManifestWithRepresentations(
output: Output,
h264AndAacEncodingTracking: H264AndAacEncodingTracking,
h265AndDolbyDigitalEncodingTracking: H265AndDolbyDigitalEncodingTracking,
vp9AndVorbisEncodingTracking: Vp9AndVorbisEncodingTracking
): Promise<DashManifest> {
const dashManifest = await createDashManifest('stream.mpd', DashProfile.LIVE, output, '/');
const period = await bitmovinApi.encoding.manifests.dash.periods.create(dashManifest.id!, new Period());
const videoAdaptationSetVp9 = await bitmovinApi.encoding.manifests.dash.periods.adaptationsets.video.create(
dashManifest.id!,
period.id!,
new VideoAdaptationSet()
);
const videoAdaptationSetH265 = await bitmovinApi.encoding.manifests.dash.periods.adaptationsets.video.create(
dashManifest.id!,
period.id!,
new VideoAdaptationSet()
);
const videoAdaptationSetH264 = await bitmovinApi.encoding.manifests.dash.periods.adaptationsets.video.create(
dashManifest.id!,
period.id!,
new VideoAdaptationSet()
);
const vorbisAudioAdaptationSet = await createAudioAdaptionSet(dashManifest, period, 'en');
const dolbyDigitalAudioAdaptationSet = await createAudioAdaptionSet(dashManifest, period, 'en');
const aacAudioAdaptationSet = await createAudioAdaptionSet(dashManifest, period, 'en');
for (const [rendition, vp9WebmMuxing] of vp9AndVorbisEncodingTracking.vp9WebmMuxings) {
await createDashWebmRepresentation(
vp9AndVorbisEncodingTracking.encoding,
vp9WebmMuxing,
dashManifest,
period,
`${vp9AndVorbisEncodingTracking.VP9_WEBM_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
videoAdaptationSetVp9.id!
);
}
// Add VORBIS WEBM muxing to VORBIS audio adaptation set
await createDashWebmRepresentation(
vp9AndVorbisEncodingTracking.encoding,
vp9AndVorbisEncodingTracking.vorbisWebmMuxing,
dashManifest,
period,
vp9AndVorbisEncodingTracking.VORBIS_WEBM_SEGMENTS_PATH,
vorbisAudioAdaptationSet.id!
);
// Add representations to H265 adaptation set
// Add H265 FMP4 muxing to H265 video adaptation set
for (const [rendition, h265Fmp4Muxing] of h265AndDolbyDigitalEncodingTracking.h265Fmp4Muxings) {
await createDashFmp4Representation(
h265AndDolbyDigitalEncodingTracking.encoding,
h265Fmp4Muxing,
dashManifest,
period,
`${h265AndDolbyDigitalEncodingTracking.H265_FMP4_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
videoAdaptationSetH265.id!
);
}
// Add Dolby Digital FMP4 muxing to Dolby Digital audio adaptation set
await createDashFmp4Representation(
h265AndDolbyDigitalEncodingTracking.encoding,
h265AndDolbyDigitalEncodingTracking.dolbyDigitalFmp4Muxing,
dashManifest,
period,
h265AndDolbyDigitalEncodingTracking.DOLBY_DIGITAL_FMP4_SEGMENTS_PATH,
dolbyDigitalAudioAdaptationSet.id!
);
// Add representations to H264 adaptation set
// Add H264 CMAF muxing to H264 video adaptation set
for (const [rendition, h264CmafMuxing] of h264AndAacEncodingTracking.h264CmafMuxings) {
await createDashCmafRepresentation(
h264AndAacEncodingTracking.encoding,
h264CmafMuxing,
dashManifest,
period,
`${h264AndAacEncodingTracking.H264_CMAF_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
videoAdaptationSetH264.id!
);
}
// Add AAC FMP4 muxing to AAC audio adaptation set
await createDashFmp4Representation(
h264AndAacEncodingTracking.encoding,
h264AndAacEncodingTracking.aacFmp4Muxing,
dashManifest,
period,
h264AndAacEncodingTracking.AAC_FMP4_SEGMENTS_PATH,
aacAudioAdaptationSet.id!
);
return dashManifest;
}
async function createHlsManifestWithRepresentations(
output: Output,
h264AndAacEncodingTracking: H264AndAacEncodingTracking,
h265AndDolbyDigitalEncodingTracking: H265AndDolbyDigitalEncodingTracking
): Promise<HlsManifest> {
const hlsManifest = await createHlsMasterManifest('master.m3u8', output, '/');
// Create h265 audio playlists
await createAudioMediaPlaylist(
h265AndDolbyDigitalEncodingTracking.encoding,
hlsManifest,
h265AndDolbyDigitalEncodingTracking.dolbyDigitalFmp4Muxing,
h265AndDolbyDigitalEncodingTracking.dolbyDigitalAudioStream,
'audio_dolby_digital_fmp4.m3u8',
h265AndDolbyDigitalEncodingTracking.DOLBY_DIGITAL_FMP4_SEGMENTS_PATH,
HLS_AUDIO_GROUP_DOLBY_DIGITAL_FMP4
);
// Create h265 video playlists
for (const [rendition, h265Fmp4Muxing] of h265AndDolbyDigitalEncodingTracking.h265Fmp4Muxings) {
await createVideoStreamPlaylist(
h265AndDolbyDigitalEncodingTracking.encoding,
hlsManifest,
h265Fmp4Muxing,
h265AndDolbyDigitalEncodingTracking.h265VideoStreams.get(rendition)!,
`video_h265_${rendition.height}p_${rendition.bitrate}.m3u8`,
`${h265AndDolbyDigitalEncodingTracking.H265_FMP4_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
HLS_AUDIO_GROUP_DOLBY_DIGITAL_FMP4
);
}
// Create h264 audio playlists
await createAudioMediaPlaylist(
h264AndAacEncodingTracking.encoding,
hlsManifest,
h264AndAacEncodingTracking.aacFmp4Muxing,
h264AndAacEncodingTracking.aacAudioStream,
'audio_aac_fmp4.m3u8',
h264AndAacEncodingTracking.AAC_FMP4_SEGMENTS_PATH,
HLS_AUDIO_GROUP_AAC_FMP4
);
await createAudioMediaPlaylist(
h264AndAacEncodingTracking.encoding,
hlsManifest,
h264AndAacEncodingTracking.aacTsMuxing,
h264AndAacEncodingTracking.aacAudioStream,
'audio_aac_ts.m3u8',
h264AndAacEncodingTracking.AAC_TS_SEGMENTS_PATH,
HLS_AUDIO_GROUP_AAC_TS
);
// Create h264 video playlists
for (const [rendition, h264TsMuxing] of h264AndAacEncodingTracking.h264TsMuxings) {
await createVideoStreamPlaylist(
h264AndAacEncodingTracking.encoding,
hlsManifest,
h264TsMuxing,
h264AndAacEncodingTracking.h264VideoStreams.get(rendition)!,
`video_h264_${rendition.height}p_${rendition.bitrate}.m3u8`,
`${h264AndAacEncodingTracking.H264_TS_SEGMENTS_PATH}/${rendition.height}p_${rendition.bitrate}`,
HLS_AUDIO_GROUP_AAC_TS
);
}
return hlsManifest;
}
/** Creates the HLS master manifest. */
async function createHlsMasterManifest(name: string, output: Output, outputPath: string): Promise<HlsManifest> {
const hlsManifest = new HlsManifest({
name: name,
outputs: [buildEncodingOutput(output, outputPath)]
});
return bitmovinApi.encoding.manifests.hls.create(hlsManifest);
}
/**
* Creates an HLS audio media playlist.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/manifests#/Encoding/PostEncodingManifestsHlsMediaAudioByManifestId
*
* @param encoding the encoding where the resources belong to
* @param manifest the manifest where the audio playlist should be added
* @param audioMuxing the audio muxing that should be used
* @param audioStream the audio stream of the muxing
* @param audioSegmentsPath the path to the audio segments
*/
async function createAudioMediaPlaylist(
encoding: Encoding,
manifest: HlsManifest,
audioMuxing: Muxing,
audioStream: Stream,
uri: string,
audioSegmentsPath: string,
audioGroup: string
) {
const audioMediaInfo = new AudioMediaInfo({
name: uri,
uri: uri,
groupId: audioGroup,
encodingId: encoding.id,
streamId: audioStream.id,
muxingId: audioMuxing.id,
language: 'en',
assocLanguage: 'en',
autoselect: false,
isDefault: false,
forced: false,
segmentPath: audioSegmentsPath
});
await bitmovinApi.encoding.manifests.hls.media.audio.create(manifest.id!, audioMediaInfo);
}
/**
* Creates an HLS video playlist
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/manifests#/Encoding/PostEncodingManifestsHls
*
* @param encoding the encoding where the resources belong to
* @param manifest the master manifest where the video stream playlist should belong to
* @param videoMuxing the muxing that should be used
* @param videoStream the stream of the muxing
* @param uri the relative uri of the playlist file that will be generated
* @param segmentPath the path pointing to the respective video segments
*/
async function createVideoStreamPlaylist(
encoding: Encoding,
manifest: HlsManifest,
videoMuxing: Muxing,
videoStream: Stream,
uri: string,
segmentPath: string,
audioGroup: string
) {
const streamInfo = new StreamInfo({
uri: uri,
encodingId: encoding.id,
streamId: videoStream.id,
muxingId: videoMuxing.id,
audio: audioGroup,
segmentPath: segmentPath
});
await bitmovinApi.encoding.manifests.hls.streams.create(manifest.id!, streamInfo);
}
/**
* Creates a DASH WEBM representation
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/manifests#/Encoding/PostEncodingManifestsDashPeriodsAdaptationsetsRepresentationsWebmByManifestIdAndPeriodIdAndAdaptationsetId
*
* @param encoding the encoding where the resources belong to
* @param muxing the muxing that should be used for this representation
* @param dashManifest the dash manifest to which the representation should be added
* @param period the period to which the represenation should be added
* @param segmentPath the path to the WEBM segments
* @param adaptationSetId the adaptationset to which the representation should be added
*/
async function createDashWebmRepresentation(
encoding: Encoding,
muxing: WebmMuxing,
dashManifest: DashManifest,
period: Period,
segmentPath: string,
adaptationSetId: string
) {
const dashWebmRepresentation = new DashWebmRepresentation({
type: DashRepresentationType.TEMPLATE,
encodingId: encoding.id,
muxingId: muxing.id,
segmentPath: segmentPath
});
await bitmovinApi.encoding.manifests.dash.periods.adaptationsets.representations.webm.create(
dashManifest.id!,
period.id!,
adaptationSetId,
dashWebmRepresentation
);
}
/**
* Creates a DASH fMP4 representation.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/all#/Encoding/PostEncodingEncodingsMuxingsFmp4ByEncodingId
*
* @param encoding the encoding where the resources belong to
* @param muxing the muxing that should be used for this representation
* @param dashManifest the dash manifest to which the representation should be added
* @param period the period to which the represenation should be added
* @param segmentPath the path to the WEBM segments
* @param adaptationSetId the adaptationset to which the representation should be added
*/
async function createDashFmp4Representation(
encoding: Encoding,
muxing: Fmp4Muxing,
dashManifest: DashManifest,
period: Period,
segmentPath: string,
adaptationSetId: string
) {
const dashFmp4Representation = new DashFmp4Representation({
type: DashRepresentationType.TEMPLATE,
encodingId: encoding.id,
muxingId: muxing.id,
segmentPath: segmentPath
});
await bitmovinApi.encoding.manifests.dash.periods.adaptationsets.representations.fmp4.create(
dashManifest.id!,
period.id!,
adaptationSetId,
dashFmp4Representation
);
}
/**
* Creates a DASH CMAF representation
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/manifests#/Encoding/PostEncodingManifestsDashPeriodsAdaptationsetsRepresentationsCmafByManifestIdAndPeriodIdAndAdaptationsetId
*
* @param encoding the encoding where the resources belong to
* @param muxing the muxing that should be used for this representation
* @param dashManifest the dash manifest to which the representation should be added
* @param period the period to which the representation should be added
* @param segmentPath the path the the CMAF segments
* @param adaptationSetId the adaptation set to which the representation should be added
*/
async function createDashCmafRepresentation(
encoding: Encoding,
muxing: CmafMuxing,
dashManifest: DashManifest,
period: Period,
segmentPath: string,
adaptationSetId: string
) {
const dashCmafRepresentation = new DashCmafRepresentation({
type: DashRepresentationType.TEMPLATE,
encodingId: encoding.id,
muxingId: muxing.id,
segmentPath: segmentPath
});
await bitmovinApi.encoding.manifests.dash.periods.adaptationsets.representations.cmaf.create(
dashManifest.id!,
period.id!,
adaptationSetId,
dashCmafRepresentation
);
}
/**
* Creates a DASH manifest
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/manifests#/Encoding/PostEncodingManifestsDash
*
* @param name the resource name
* @param dashProfile the DASH profile of the manifest (ON_DEMAND, LIVE)
* @param output the output of the manifest
* @param outputPath the output path where the manifest is written to
* @return the created manifest
*/
async function createDashManifest(
name: string,
dashProfile: DashProfile,
output: Output,
outputPath: string
): Promise<DashManifest> {
const dashManifest = new DashManifest({
name: name,
profile: dashProfile,
outputs: [buildEncodingOutput(output, outputPath)]
});
return bitmovinApi.encoding.manifests.dash.create(dashManifest);
}
/** Creates an audio adaption set for the dash manifest */
async function createAudioAdaptionSet(
dashManifest: DashManifest,
period: Period,
language: string
): Promise<AudioAdaptationSet> {
const audioAdaptationSet = new AudioAdaptationSet({
lang: language
});
return bitmovinApi.encoding.manifests.dash.periods.adaptationsets.audio.create(
dashManifest.id!,
period.id!,
audioAdaptationSet
);
}
/**
* Creates an Encoding object. This is the base object to configure your encoding.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodings
*
* @param name A name that will help you identify the encoding in our dashboard (required)
* @param description A description of the encoding (optional)
*/
function createEncoding(name: string, description: string): Promise<Encoding> {
const encoding = new Encoding({
name: name,
description: description
});
return bitmovinApi.encoding.encodings.create(encoding);
}
/**
* Adds a video or audio stream to an encoding
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsStreamsByEncodingId
*
* @param encoding The encoding to which the stream will be added
* @param input The input resource providing the input file
* @param inputPath The path to the input file
* @param codecConfiguration The codec configuration to be applied to the stream
*/
function createStream(
encoding: Encoding,
input: Input,
inputPath: string,
codecConfiguration: CodecConfiguration
): Promise<Stream> {
const streamInput = new StreamInput({
inputId: input.id,
inputPath: inputPath,
selectionMode: StreamSelectionMode.AUTO,
});
const stream = new Stream({
inputStreams: [streamInput],
codecConfigId: codecConfiguration.id
});
return bitmovinApi.encoding.encodings.streams.create(encoding.id!, stream);
}
/**
* Creates a resource representing an AWS S3 cloud storage bucket to which generated content will
* be transferred. For alternative output methods see <a
* href="https://bitmovin.com/docs/encoding/articles/supported-input-output-storages">list of
* supported input and output storages</a>
*
* <p>The provided credentials need to allow <i>read</i>, <i>write</i> and <i>list</i> operations.
* <i>delete</i> should also be granted to allow overwriting of existings files. See <a
* href="https://bitmovin.com/docs/encoding/faqs/how-do-i-create-a-aws-s3-bucket-which-can-be-used-as-output-location">creating
* an S3 bucket and setting permissions</a> for further information
*
* <p>For reasons of simplicity, a new output resource is created on each execution of this
* example. In production use, this method should be replaced by a <a
* href="https://bitmovin.com/docs/encoding/api-reference/sections/outputs#/Encoding/GetEncodingOutputsS3">get
* call</a> retrieving an existing resource.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/outputs#/Encoding/PostEncodingOutputsS3
*
* @param bucketName The name of the S3 bucket
* @param accessKey The access key of your S3 account
* @param secretKey The secret key of your S3 account
*/
function createS3Output(bucketName: string, accessKey: string, secretKey: string): Promise<S3Output> {
const s3Output = new S3Output({
bucketName: bucketName,
accessKey: accessKey,
secretKey: secretKey
});
return bitmovinApi.encoding.outputs.s3.create(s3Output);
}
/**
* Creates a resource representing an HTTP server providing the input files. For alternative input
* methods see <a
* href="https://bitmovin.com/docs/encoding/articles/supported-input-output-storages">list of
* supported input and output storages</a>
*
* <p>For reasons of simplicity, a new input resource is created on each execution of this
* example. In production use, this method should be replaced by a <a
* href="https://bitmovin.com/docs/encoding/api-reference/sections/inputs#/Encoding/GetEncodingInputsHttpByInputId">get
* call</a> to retrieve an existing resource.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/inputs#/Encoding/PostEncodingInputsHttp
*
* @param host The hostname or IP address of the HTTP server e.g.: my-storage.biz
*/
function createHttpInput(host: string): Promise<HttpInput> {
const input = new HttpInput({
host: host
});
return bitmovinApi.encoding.inputs.http.create(input);
}
/**
* Creates a progressive TS muxing.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsMuxingsTsByEncodingId
*
* @param encoding The encoding to add the muxing to
* @param output The output that should be used for the muxing to write the segments to
* @param outputPath The output path where the fragments will be written to
* @param stream A list of streams to be added to the muxing
*/
function createTsMuxing(encoding: Encoding, output: Output, outputPath: string, stream: Stream): Promise<TsMuxing> {
const muxing = new TsMuxing({
outputs: [buildEncodingOutput(output, outputPath)],
streams: [new MuxingStream({streamId: stream.id})],
segmentLength: 4.0
});
return bitmovinApi.encoding.encodings.muxings.ts.create(encoding.id!, muxing);
}
/**
* Creates a CMAF muxing. This will generate segments with a given segment length for adaptive
* streaming.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/all#/Encoding/PostEncodingEncodingsMuxingsCmafByEncodingId
*
* @param encoding The encoding to add the muxing to
* @param output The output that should be used for the muxing to write the segments to
* @param outputPath The output path where the fragmented segments will be written to
* @param stream The stream that is associated with the muxing
*/
function createCmafMuxing(encoding: Encoding, output: Output, outputPath: string, stream: Stream): Promise<CmafMuxing> {
const muxing = new CmafMuxing({
outputs: [buildEncodingOutput(output, outputPath)],
streams: [new MuxingStream({streamId: stream.id})],
segmentLength: 4.0
});
return bitmovinApi.encoding.encodings.muxings.cmaf.create(encoding.id!, muxing);
}
/**
* Creates a CMAF muxing. This will generate segments with a given segment length for adaptive
* streaming.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/all#/Encoding/PostEncodingEncodingsMuxingsCmafByEncodingId
*
* @param encoding The encoding to add the muxing to
* @param output The output that should be used for the muxing to write the segments to
* @param outputPath The output path where the fragmented segments will be written to
* @param stream The stream that is associated with the muxing
*/
function createWebmMuxing(encoding: Encoding, output: Output, outputPath: string, stream: Stream): Promise<WebmMuxing> {
const muxing = new WebmMuxing({
outputs: [buildEncodingOutput(output, outputPath)],
streams: [new MuxingStream({streamId: stream.id})],
segmentLength: 4.0
});
return bitmovinApi.encoding.encodings.muxings.webm.create(encoding.id!, muxing);
}
/**
* Creates an MP4 muxing.
*
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsMuxingsMp4ByEncodingId
*
* @param encoding The encoding to add the MP4 muxing to
* @param output The output that should be used for the muxing to write the segments to
* @param outputPath The output path where the fragments will be written to
* @param stream A list of streams to be added to the muxing
*/
function createFmp4Muxing(encoding: Encoding, output: Output, outputPath: string, stream: Stream): Promise<Fmp4Muxing> {
const muxing = new Fmp4Muxing({
outputs: [buildEncodingOutput(output, outputPath)],
streams: [new MuxingStream({streamId: stream.id})],
segmentLength: 4.0
});
return bitmovinApi.encoding.encodings.muxings.fmp4.create(encoding.id!, muxing);
}
/**
* Builds an EncodingOutput object which defines where the output content (e.g. of a muxing) will
* be written to. Public read permissions will be set for the files written, so they can be
* accessed easily via HTTP.
*
* @param output The output resource to be used by the EncodingOutput
* @param outputPath The path where the content will be written to
*/
function buildEncodingOutput(output: Output, outputPath: string): EncodingOutput {
const aclEntry = new AclEntry({
permission: AclPermission.PUBLIC_READ
});
return new EncodingOutput({
outputPath: buildAbsolutePath(outputPath),
outputId: output.id,
acl: [aclEntry]
});
}
/**
* Builds an absolute path by concatenating the S3_OUTPUT_BASE_PATH configuration parameter, the
* name of this example and the given relative path