-
Notifications
You must be signed in to change notification settings - Fork 91
/
index.html
331 lines (311 loc) · 18.2 KB
/
index.html
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
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="loader.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.490.0/aws-sdk.min.js"></script>
<link rel="icon" type="image/png" href="favicon.ico">
<style>
#playerContainer,
.player {
width: 100%;
height: auto;
min-height: 400px;
background-color: black;
outline: none;
}
.vjs-big-play-button {
display: none !important;
}
</style>
<title>Amazon Kinesis Video Streams Media Viewer</title>
</head>
<body>
<div class="container mb-3">
<div class="row mt-3 mb-3">
<div class="col-md-12">
<h1>Amazon Kinesis Video Streams Media Viewer</h1>
Documentation:
<a href="https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/API_reader_GetHLSStreamingSessionURL.html">HLS</a>
-
<a href="https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/API_reader_GetDASHStreamingSessionURL.html">DASH</a>
</div>
</div>
<div class="row loader"></div>
<div class="main">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Streaming Protocol</label>
<select id="protocol" class="form-control form-control-sm">
<option>HLS</option>
<option>DASH</option>
</select>
</div>
<div class="form-group">
<label>Player</label>
<select id="player" class="form-control form-control-sm">
</select>
</div>
<div class="form-group">
<label>Region</label>
<select id="region" class="form-control form-control-sm">
<option>ap-east-1</option>
<option>ap-northeast-1</option>
<option>ap-northeast-2</option>
<option>ap-south-1</option>
<option>ap-southeast-1</option>
<option>ap-southeast-2</option>
<option>ca-central-1</option>
<option>eu-central-1</option>
<option>eu-west-1</option>
<option>eu-west-2</option>
<option>eu-west-3</option>
<option>sa-east-1</option>
<option selected>us-east-1</option>
<option>us-east-2</option>
<option>us-west-2</option>
</select>
</div>
<div class="form-group">
<label>AWS Access Key</label>
<input id="accessKeyId" type="password" class="form-control form-control-sm"/>
</div>
<div class="form-group">
<label>AWS Secret Key</label>
<input id="secretAccessKey" type="password" class="form-control form-control-sm"/>
</div>
<div class="form-group">
<label>AWS Session Token (Optional)</label>
<input id="sessionToken" type="password" class="form-control form-control-sm" />
</div>
<div class="form-group">
<label>Endpoint (Optional)</label>
<input id="endpoint" type="text" class="form-control form-control-sm" />
</div>
<div class="form-group">
<label>Stream name</label>
<input id="streamName" type="text" class="form-control form-control-sm"/>
</div>
<div class="form-group">
<label>Playback Mode</label>
<select id="playbackMode" class="form-control form-control-sm">
<option selected>LIVE</option>
<option>LIVE_REPLAY</option>
<option>ON_DEMAND</option>
</select>
</div>
<div class="form-group">
<label>Start Timestamp</label>
<input id="startTimestamp" type="datetime-local" class="form-control form-control-sm"/>
</div>
<div class="form-group">
<label>End Timestamp</label>
<input id="endTimestamp" type="datetime-local" class="form-control form-control-sm"/>
</div>
<div class="form-group">
<label>Fragment Selector Type</label>
<select id="fragmentSelectorType" class="form-control form-control-sm">
<option selected>SERVER_TIMESTAMP</option>
<option>PRODUCER_TIMESTAMP</option>
</select>
</div>
<div class="form-group">
<label>Container Format</label>
<select id="containerFormat" class="form-control form-control-sm">
<option selected="">FRAGMENTED_MP4</option>
<option>MPEG_TS</option>
</select>
</div>
<div class="form-group">
<label>Discontinuity Mode</label>
<select id="discontinuityMode" class="form-control form-control-sm">
<option selected>ALWAYS</option>
<option>NEVER</option>
<option>ON_DISCONTINUITY</option>
</select>
</div>
<div class="form-group">
<label>Display Fragment Timestamp</label>
<select id="displayFragmentTimestamp" class="form-control form-control-sm">
<option>ALWAYS</option>
<option selected>NEVER</option>
</select>
</div>
<div class="form-group">
<label>Display Fragment Number</label>
<select id="displayFragmentNumber" class="form-control form-control-sm">
<option>ALWAYS</option>
<option selected>NEVER</option>
</select>
</div>
<div class="form-group">
<label>Max Manifest/Playlist Fragment Results</label>
<input id="maxResults" type="text" class="form-control form-control-sm"/>
</div>
<div class="form-group">
<label>Expires (seconds)</label>
<input id="expires" type="text" class="form-control form-control-sm"/>
</div>
<button id="start" type="submit" class="btn btn-primary">Start Playback</button>
</div>
<div class="col-md-8">
<div id="playerContainer">
<!-- HLS.js elements -->
<video id="hlsjs" class="player" controls autoplay></video>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<!-- VideoJS elements -->
<video id="videojs" class="player video-js vjs-default-skin" controls autoplay></video>
<link rel="stylesheet" href="https://vjs.zencdn.net/6.6.3/video-js.css">
<script src="https://vjs.zencdn.net/6.6.3/video.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.14.1/videojs-contrib-hls.js"></script>
<!-- Shaka Player elements -->
<video id="shaka" class="player" controls autoplay></video>
<script src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/2.4.1/shaka-player.compiled.js">
</script>
<!-- DASH.js elements -->
<video id="dashjs" class="player" controls autoplay=""></video>
<script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script>
</div>
<h3 style="margin-top: 20px;">Logs</h3>
<div class="card bg-light mb-3">
<pre id="logs" class="card-body text-monospace" style="font-family: monospace; white-space: pre-wrap;"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
var DASH_PLAYERS = ['DASH.js', 'Shaka Player'];
var HLS_PLAYERS = ['HLS.js', 'Shaka Player', 'VideoJS'];
$('#start').click(function() {
var protocol = $('#protocol').val();
var streamName = $('#streamName').val();
// Step 1: Configure SDK Clients
var options = {
accessKeyId: $('#accessKeyId').val(),
secretAccessKey: $('#secretAccessKey').val(),
sessionToken: $('#sessionToken').val() || undefined,
region: $('#region').val(),
endpoint: $('#endpoint').val() || undefined
}
var kinesisVideo = new AWS.KinesisVideo(options);
var kinesisVideoArchivedContent = new AWS.KinesisVideoArchivedMedia(options);
// Step 2: Get a data endpoint for the stream
console.log('Fetching data endpoint');
kinesisVideo.getDataEndpoint({
StreamName: streamName,
APIName: protocol === 'DASH' ? "GET_DASH_STREAMING_SESSION_URL" : "GET_HLS_STREAMING_SESSION_URL"
}, function(err, response) {
if (err) { return console.error(err); }
console.log('Data endpoint: ' + response.DataEndpoint);
kinesisVideoArchivedContent.endpoint = new AWS.Endpoint(response.DataEndpoint);
// Step 3: Get a Streaming Session URL
var consoleInfo = 'Fetching ' + protocol + ' Streaming Session URL';
console.log(consoleInfo);
if (protocol === 'DASH') {
kinesisVideoArchivedContent.getDASHStreamingSessionURL({
StreamName: streamName,
PlaybackMode: $('#playbackMode').val(),
DASHFragmentSelector: {
FragmentSelectorType: $('#fragmentSelectorType').val(),
TimestampRange: $('#playbackMode').val() === "LIVE" ? undefined : {
StartTimestamp: new Date($('#startTimestamp').val()),
EndTimestamp: new Date($('#endTimestamp').val())
}
},
DisplayFragmentTimestamp: $('#displayFragmentTimestamp').val(),
DisplayFragmentNumber: $('#displayFragmentNumber').val(),
MaxManifestFragmentResults: parseInt($('#maxResults').val()),
Expires: parseInt($('#expires').val())
}, function(err, response) {
if (err) { return console.error(err); }
console.log('DASH Streaming Session URL: ' + response.DASHStreamingSessionURL);
// Step 4: Give the URL to the video player.
var playerName = $('#player').val();
if (playerName === 'Shaka Player') {
var playerElement = $('#shaka');
playerElement.show();
var player = new shaka.Player(playerElement[0]);
console.log('Created Shaka Player');
player.load(response.DASHStreamingSessionURL).then(function() {
console.log('Starting playback');
});
console.log('Set player source');
} else if(playerName === 'DASH.js') {
var playerElement = $('#dashjs');
playerElement.show();
var player = dashjs.MediaPlayer().create();
console.log('Created DASH.js Player');
player.initialize(document.querySelector('#dashjs'), response.DASHStreamingSessionURL, true);
console.log('Starting playback');
console.log('Set player source');
}
});
} else {
kinesisVideoArchivedContent.getHLSStreamingSessionURL({
StreamName: streamName,
PlaybackMode: $('#playbackMode').val(),
HLSFragmentSelector: {
FragmentSelectorType: $('#fragmentSelectorType').val(),
TimestampRange: $('#playbackMode').val() === "LIVE" ? undefined : {
StartTimestamp: new Date($('#startTimestamp').val()),
EndTimestamp: new Date($('#endTimestamp').val())
}
},
ContainerFormat: $('#containerFormat').val(),
DiscontinuityMode: $('#discontinuityMode').val(),
DisplayFragmentTimestamp: $('#displayFragmentTimestamp').val(),
MaxMediaPlaylistFragmentResults: parseInt($('#maxResults').val()),
Expires: parseInt($('#expires').val())
}, function(err, response) {
if (err) { return console.error(err); }
console.log('HLS Streaming Session URL: ' + response.HLSStreamingSessionURL);
// Step 4: Give the URL to the video player.
var playerName = $('#player').val();
if (playerName == 'HLS.js') {
var playerElement = $('#hlsjs');
playerElement.show();
var player = new Hls();
console.log('Created HLS.js Player');
player.loadSource(response.HLSStreamingSessionURL);
player.attachMedia(playerElement[0]);
console.log('Set player source');
player.on(Hls.Events.MANIFEST_PARSED, function() {
video.play();
console.log('Starting playback');
});
} else if (playerName === 'VideoJS') {
var playerElement = $('#videojs');
playerElement.show();
var player = videojs('videojs');
console.log('Created VideoJS Player');
player.src({
src: response.HLSStreamingSessionURL,
type: 'application/x-mpegURL'
});
console.log('Set player source');
player.play();
console.log('Starting playback');
} else if (playerName === 'Shaka Player') {
var playerElement = $('#shaka');
playerElement.show();
var player = new shaka.Player(playerElement[0]);
console.log('Created Shaka Player');
player.load(response.HLSStreamingSessionURL).then(function() {
console.log('Starting playback');
});
console.log('Set player source');
}
});
}
});
$('.player').hide();
});
</script>
<script src="ui.js"></script>
<a href="https://github.com/aws-samples/amazon-kinesis-video-streams-media-viewer">
<img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_orange_ff7600.png" alt="Fork me on GitHub">
</a>
</body>
</html>