-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.html
108 lines (99 loc) · 2.65 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>canvas2video demo</title>
<style>
* {
padding: 0;
margin: 0;
}
#container {
width: 300px;
height: 300px;
}
</style>
<script src="https://unpkg.com/[email protected]/dist/spritejs.min.js"></script>
</head>
<body>
<div style="width: 300px; margin: auto;">
<h1>canvas2video(webm)</h1>
<div id="container"></div>
<div id="videoContainer" style="display: none;">
<h2>视频</h2>
<video
width="300"
height="300"
controls="true"
autoplay="true"
id="video"
></video>
</div>
</div>
<script src="../dist/canvas2video.js"></script>
<script src="https://unpkg.com/@ffmpeg/ffmpeg/dist/ffmpeg.min.js"></script>
<script>
const { Scene, Label, Group } = spritejs;
const container = document.getElementById("container");
const scene = new Scene({
container,
width: 300,
height: 300,
});
const fglayer = scene.layer("fglayer", {
bgcolor: 'red'
});
// fglayer.canvas.style.backgroundColor = "#3f097a";
const group = new Group();
group.attr({
pos: [150, 150],
});
fglayer.append(group);
const text1 = new Label("Hello World !");
text1.attr({
anchor: [0.5, 0.5],
font: "bold 24px Arial",
fillColor: "#ffdc45",
});
const text2 = new Label("SpriteJS.org");
text2.attr({
anchor: [0.5, 0.5],
y: 60,
font: "bold 24px Arial",
fillColor: "#ffdc45",
});
group.animate(
[
{ scale: 1.5, rotate: -30 },
{ scale: 1, rotate: 0 },
{ scale: 1.5, rotate: 30 },
],
{
duration: 3000,
iterations: Infinity,
direction: "alternate",
}
);
group.append(text1, text2);
</script>
<script>
const canvas2videoInstance = new Canvas2Video({
canvas: document.querySelector("canvas"),
outVideoType: "webm",
});
canvas2videoInstance.startRecord();
setTimeout(() => {
canvas2videoInstance.stopRecord();
}, 3000);
canvas2videoInstance
.getStreamURL()
.then((url) => {
console.log("url", url);
document.querySelector("#videoContainer").style.display = "block";
document.querySelector("video").src = url;
})
.catch((err) => console.error(err));
</script>
</body>
</html>