-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
86 lines (84 loc) · 3.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
<!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>Mixer</title>
</head>
<body>
<header class="header">
<nav class="nav">
<a class="active" href="/mixer">Mixer</a>
<a href="/recorder">Recorder</a>
<a id="github" href="https://github.com/yzydeveloper/media-stream" target="_blank">Github</a>
</nav>
</header>
<div class="content">
<h1>Mixer example</h1>
<h2>Combined video</h2>
<video id="combined-video" muted controls autoplay playsinline></video>
<h2>Crop video</h2>
<video id="crop-video" muted controls autoplay playsinline></video>
</div>
<script type="module">
import { Mixer } from '@media-stream/mixer'
import '../../style.css'
// combined video
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then((mediaStream => {
const mixer = new Mixer()
const streamSettings = mediaStream.getVideoTracks()?.[0].getSettings()
mixer.attachStream(mediaStream, {
swidth: streamSettings.width,
sheight: streamSettings.height,
width: 720,
height: 405
})
mixer.attachStream(mediaStream, {
swidth: streamSettings.width,
sheight: streamSettings.height,
width: 720 / 2,
height: 405 / 2
})
mixer.start()
const video = document.querySelector('#combined-video')
video.srcObject = mixer.stream
}))
// crop-video
Promise.all([
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}),
navigator.mediaDevices.getDisplayMedia({
video: true,
audio: true
})
]).then(([stream1, stream2]) => {
const mixer = new Mixer()
const stream1Settings = stream1.getVideoTracks()?.[0].getSettings()
mixer.attachStream(stream1, {
swidth: stream1Settings.width,
sheight: stream1Settings.height,
width: 720,
height: 405
})
const stream2Settings = stream2.getVideoTracks()?.[0].getSettings()
mixer.attachStream(stream2, {
sx: 512,
sy: 240,
swidth: stream2Settings.width,
sheight: stream2Settings.height,
width: 480,
height: 270
})
mixer.start()
const video = document.querySelector('#crop-video')
video.srcObject = mixer.stream
})
</script>
</body>
</html>