playback-demo.html
14.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Jessibuca Pro 回放流 demo</title>
<script src="./vconsole.js"></script>
<script src="./jessibuca-pro-demo.js"></script>
<link rel="stylesheet" href="./demo.css">
<style>
.container-shell:before {
content: "jessibuca pro 回放流 demo";
}
</style>
</head>
<body class="page">
<div class="root">
<div class="container-shell">
<div id="container"></div>
<div class="input">
<div>
<span><span style="color: red">TPS:动态(根据流):</span>播放器的倍率播放完全是根据服务器端推流的速率,如果服务器端推的是一倍率且动态码率的流,
播放器就按照一倍率动态码率渲染。<span style="color: green">例如 fps会15到30之间跳动。</span>
</span>
</div>
</div>
<div class="input">
<div>
<span><span style="color: red">TPS:定频(本地设置):</span>则支持播放器端控制播放速率(设置FPS+播放倍率),播放器端设置的播放速率是固定的,不会随着流的速率变化而变化。
支持设置播放器的播放倍率(提高渲染倍率)。<span
style="color: green">在推流码率足够的情况下,播放器会按照固定倍率播放</span>
</span>
</div>
</div>
<div class="input">
<div >
<span><span style="color: red">TPS:解码前缓冲数据:</span>对于存在有些流会一下子以2倍甚至4倍的速率推送的情况,如果设置为true,则会根据计算出来的fps,只根据fps和倍率来解码数据,其他数据还是被缓存在队列中,等待解码。
</span>
</div>
</div>
<div class="input">
<div >
<span><span style="color: red">TPS:服务器端倍率推流:</span> 如果服务器端按照倍率推流,播放器端也需要同步的以倍率播放【调用forward(rate)】接口
</span>
</div>
</div>
<div class="input">
<div >
<span style="color: red">TPS:</span> 录像流暂只支持wasm(simd)解码,canvas渲染。
</div>
</div>
<div class="input">
<div class="playbackForward">
<span>FPS设置:</span>
<select id="isUseFpsRender" style="width: 140px">
<option value="false" selected>动态(根据流)</option>
<option value="true">定频(本地设置)</option>
</select>
</div>
</div>
<div class="input">
<span>是否解码前缓冲数据(定频生效)</span>
<select id="isCacheBeforeDecodeForFpsRender" style="width: 50px">
<option value="true">是</option>
<option value="false" selected>否</option>
</select>
</div>
<div class="input">
<span>是否显示操作按钮</span>
<select id="isShowControl" style="width: 50px">
<option value="true" selected>是</option>
<option value="false">否</option>
</select>
</div>
<div class="input">
<span>是否显示24H时间轴</span>
<select id="isShow24H" style="width: 50px">
<option value="true" selected>是</option>
<option value="false">否</option>
</select>
</div>
<div class="input">
<span>只解码I帧(<span style="color:red;">点击重播按钮生效</span>)</span>
<select id="onlyDecoderIFrame" style="width: 50px">
<option value="1">1倍</option>
<option value="2">2倍</option>
<option value="4" selected>4倍</option>
<option value="8">8倍</option>
</select>
</div>
<div class="input">
<div class="playback-fps" style="margin-left: 10px">
<span>FPS(定频(本地设置)生效):</span><input style="width: 50px" type="text" id="playbackFps" value="25">帧
</div>
</div>
<div class="input">
<div class="playback-fps" style="margin-left: 10px">
<span>不断流暂停是否清除缓存数据</span>
<select id="isPlaybackPauseClearCache" style="width: 50px">
<option value="true" selected>是</option>
<option value="false">否</option>
</select>
</div>
</div>
<div class="input">
<span>ui是否使用playbackPause</span>
<select id="uiUsePlaybackPause" style="width: 50px">
<option value="true">是</option>
<option value="false" selected>否</option>
</select>
</div>
<div class="input">
<span>canvas渲染技术:</span>
<select id="isUseWebGPU" onchange="replay()">
<option value="webgl">webgl</option>
<option value="webgpu" selected>webgpu</option>
</select>
<span id="supportWebgpu"></span>
</div>
<div class="input">
<span>是否使用硬解码(https支持)</span>
<select id="playbackUseWCS" style="width: 50px">
<option value="true">是</option>
<option value="false" selected>否</option>
</select>
</div>
<div class="input">
<button onclick="replay()">重播</button>
</div>
<div class="input">
<div>输入URL:</div>
<input
autocomplete="on"
id="playUrl"
value=""
/>
</div>
<div class="input">
<button id="play">播放</button>
<button id="pause">停止(流会断开)</button>
<button id="playbackPause">停止(流不断开)</button>
<button id="playScroll" onclick="currentTimeScroll()">滚动到当前时间</button>
</div>
<div class="input">
<textarea name="" id="playbackTimes" style="width: 100%" rows="10">
[{"start":1653840000,"end":1653841624},{"start":1653841634,"end":1653843420},{"start":1653843429,"end":1653843958},{"start":1653843967,"end":1653845688},{"start":1653845698,"end":1653846480},{"start":1653846490,"end":1653847199},{"start":1653847208,"end":1653848531},{"start":1653848541,"end":1653850863},{"start":1653850872,"end":1653853371},{"start":1653853381,"end":1653857885},{"start":1653857894,"end":1653858352},{"start":1653858362,"end":1653860545},{"start":1653860554,"end":1653861080},{"start":1653861090,"end":1653862017},{"start":1653862026,"end":1653863812},{"start":1653863822,"end":1653865325},{"start":1653865335,"end":1653867374},{"start":1653867383,"end":1653867698},{"start":1653867707,"end":1653868816},{"start":1653868826,"end":1653872829},{"start":1653872838,"end":1653877527},{"start":1653877537,"end":1653879799},{"start":1653879809,"end":1653881953},{"start":1653881963,"end":1653885397},{"start":1653885407,"end":1653886894},{"start":1653886904,"end":1653890591},{"start":1653890600,"end":1653894360},{"start":1653894370,"end":1653903276},{"start":1653903286,"end":1653912848},{"start":1653912858,"end":1653914424},{"start":1653914433,"end":1653915002},{"start":1653915011,"end":1653918125},{"start":1653918135,"end":1653921622},{"start":1653921631,"end":1653924609},{"start":1653924618,"end":1653926399}]
</textarea>
</div>
<div class="input" style="line-height: 30px">
<button id="destroy">销毁</button>
</div>
</div>
</div>
<script src="./demo.js"></script>
<script>
var $player = document.getElementById('play');
var $pause = document.getElementById('pause');
var $playbackPause = document.getElementById('playbackPause');
var $playHref = document.getElementById('playUrl');
var $container = document.getElementById('container');
var $destroy = document.getElementById('destroy');
var $playbackTime = document.getElementById('playbackTimes');
var $playbackFps = document.getElementById('playbackFps');
var $isUseFpsRender = document.getElementById('isUseFpsRender');
var $isShowControl = document.getElementById('isShowControl'); // 是否显示按钮
var $isShow24H = document.getElementById('isShow24H'); // 是否显示24H操作栏
var $onlyDecoderIFrame = document.getElementById('onlyDecoderIFrame');
var $isCacheBeforeDecodeForFpsRender = document.getElementById('isCacheBeforeDecodeForFpsRender');
var $isPlaybackPauseClearCache = document.getElementById('isPlaybackPauseClearCache');
var $uiUsePlaybackPause = document.getElementById('uiUsePlaybackPause');
var $supportWebgpu = document.getElementById('supportWebgpu');
var $isUseWebGPU = document.getElementById('isUseWebGPU');
var $playbackUseWCS = document.getElementById('playbackUseWCS');
var $playScroll = document.getElementById('playScroll');
var forceNoOffscreen = true; //
var jessibuca = null;
var isPlaybackPause = false;
var $isUseWebGPU = document.getElementById('isUseWebGPU');
var isSupportWebgpu = 'gpu' in navigator;
if (isSupportWebgpu) {
$supportWebgpu.style.color = 'green';
$supportWebgpu.innerHTML = '支持webGPU';
} else {
$supportWebgpu.style.color = 'red';
$supportWebgpu.innerHTML = '暂不支持webGPU,降级到webgl渲染';
}
function create() {
const showOperateBtns = $isShowControl.value === 'true';
const onlyDecoderIFrame = Number($onlyDecoderIFrame.value);
jessibuca = new JessibucaPro({
container: $container,
videoBuffer: 0.2, // 缓存时长
isResize: false,
text: "",
loadingText: "加载中",
debug: true,
debugLevel: 'debug',
showPerformance: true,
showBandwidth: showOperateBtns, // 显示网速
showPlaybackOperate: showOperateBtns,
operateBtns: {
fullscreen: showOperateBtns,
screenshot: showOperateBtns,
play: showOperateBtns,
audio: showOperateBtns,
zoom: showOperateBtns,
performance: showOperateBtns,
},
forceNoOffscreen: forceNoOffscreen,
isNotMute: false,
playbackForwardMaxRateDecodeIFrame: onlyDecoderIFrame,
useWebGPU: $isUseWebGPU.value === 'webgpu' // 使用WebGPU
},);
jessibuca.onLog = msg => console.error(msg);
jessibuca.onRecord = (status) => console.log('onRecord', status);
jessibuca.onPause = () => console.log('onPause');
jessibuca.onPlay = () => console.log('onPlay');
jessibuca.onFullscreen = msg => console.log('onFullscreen', msg);
jessibuca.onMute = msg => console.log('onMute', msg);
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$playbackPause.style.display = 'none';
$destroy.style.display = 'none';
$playScroll.style.display = 'none';
jessibuca.on('playbackPreRateChange', (rate) => {
jessibuca.forward(rate);
})
jessibuca.on('playbackSeek',(data)=>{
const currentTime = new Date(1653840000000).setHours(data.hour,data.min, data.second, 0);
jessibuca.setPlaybackStartTime(currentTime);
})
}
create();
function replay() {
if (jessibuca) {
jessibuca.destroy().then(() => {
create();
play();
});
} else {
create();
play();
}
}
function play() {
var href = $playHref.value;
var playTimes = $playbackTime.value;
var playFps = $playbackFps.value || 20;
var isUseFpsRender = $isUseFpsRender.value;
var playTimesArray = JSON.parse(playTimes);
const isShow24H = $isShow24H.value === 'true';
const isCacheBeforeDecodeForFpsRender = $isCacheBeforeDecodeForFpsRender.value === 'true';
if (!href) {
return
}
if (isPlaybackPause) {
jessibuca.playbackResume()
} else {
jessibuca.playback(href, {
playList: playTimesArray,
fps: playFps,
showControl: isShow24H,
isUseFpsRender: isUseFpsRender === 'true',
isCacheBeforeDecodeForFpsRender: isCacheBeforeDecodeForFpsRender,
showRateBtn: true,
supportWheel: true,
uiUsePlaybackPause: $uiUsePlaybackPause.value === 'true',
isPlaybackPauseClearCache: $isPlaybackPauseClearCache.value === 'true',
rateConfig: [
{label: '正常', value: 1},
{label: '2倍', value: 2},
{label: '4倍', value: 4},
{label: '8倍', value: 8},
{label: '16倍', value: 16},
],
useWCS: $playbackUseWCS.value === 'true',
});
}
isPlaybackPause = false;
$player.style.display = 'none';
$pause.style.display = 'inline-block';
$playbackPause.style.display = 'inline-block';
$playScroll.style.display = 'inline-block';
$destroy.style.display = 'inline-block';
}
$player.addEventListener('click', function () {
play();
}, false)
$pause.addEventListener('click', function () {
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$playbackPause.style.display = 'none';
$playScroll.style.display = 'none';
jessibuca.pause();
})
$playbackPause.addEventListener('click', function () {
$playbackPause.style.display = 'none';
$pause.style.display = 'none';
$playScroll.style.display = 'none';
$player.style.display = 'inline-block';
jessibuca.playbackPause();
isPlaybackPause = true;
})
$destroy.addEventListener('click', function () {
if (jessibuca) {
jessibuca.destroy().then(() => {
create();
});
} else {
create();
}
})
function currentTimeScroll(){
if(jessibuca){
jessibuca.playbackCurrentTimeScroll();
}
}
</script>
</body>
</html>