-
Notifications
You must be signed in to change notification settings - Fork 36
/
demux-flv.html
180 lines (151 loc) · 4.59 KB
/
demux-flv.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Demuxer</title>
<style type="text/css">
body {
font: 12px/1.5 Tahoma, Helvetica, Arial, '\5FAE\8F6F\96C5\9ED1', sans-serif;
}
div {
outline: none;
}
video {
width: 100%;
height: 100%;
}
</style>
<style type="text/css">
form {
width: 580px;
background: #ccc;
margin: 0 auto;
padding: 20px;
border: 1px solid black;
}
form ol {
padding-left: 0;
}
form li,
div > p {
background: #eee;
display: flex;
justify-content: space-between;
margin-bottom: 10px;
list-style-type: none;
border: 1px solid black;
}
form img {
height: 64px;
order: 1;
}
form p {
line-height: 32px;
padding-left: 10px;
}
form label,
form button {
background-color: #7f9ccb;
padding: 5px 10px;
border-radius: 5px;
border: 1px ridge black;
font-size: 0.8rem;
height: auto;
}
form label:hover,
form button:hover {
background-color: #2d5ba3;
color: white;
}
form label:active,
form button:active {
background-color: #0d3f8f;
color: white;
}
</style>
<!-- browser import -->
<!-- <script type="text/javascript" src="../../dist/demuxer.flv.umd.js"></script>
<script>
const FLVDemux = Demuxer.FLVDemux;
const Events = Demuxer.Events;
</script> -->
<script type="module">
// ES Module import
import { FLVDemux, Events } from '../../dist/demuxer.flv.esm.js';
window.startDemux = function (bytes) {
let demux = new FLVDemux({
debug: true // if env is production, debug should be false or not specified.
// decodeCodec: true // if you want to decode H264 or aac
});
const printObject = [];
demux
.on(Events.DEMUX_DATA, (e) => {
console.log(e);
printObject.push(e);
switch (e.type) {
case 'head':
break;
case 'tag':
// // get audio info
// get onMetaData info
// case FlvDemux.VideoTag.TYPE:
// // get video info
// break;
if (e.tagType == 9) {
console.log(`avcPacketType: `, e.videoData ? e.videoData.avcPacketType : null);
}
break;
}
})
.on(Events.DONE, (e) => {
// consumed & flushed all pipe buffer.
})
.on(Events.ERROR, (e) => {
// encounter some unexpected error.
});
// buffer -> video bytes ArrayBuffer
// If bytes is not continuous, it should be start with tag.
demux.push(bytes);
document.querySelector('#JSONViewer').data = printObject;
};
</script>
<script src="https://unpkg.com/@alenaksu/[email protected]/dist/json-viewer.bundle.js"></script>
</head>
<body style="background-color: darkslategray;">
<form method="post" enctype="multipart/form-data">
<div>
<label for="flv_uploads">Choose a file to upload (FLV, F4V)</label>
<input type="file" id="flv_uploads" name="flv_uploads" accept=".flv, .f4v" />
</div>
<div class="preview">
<p>No files currently selected for upload</p>
</div>
<!-- <div>
<button>Submit</button>
</div> -->
</form>
<json-viewer id="JSONViewer"></json-viewer>
<script>
var input = document.querySelector('input#flv_uploads');
var preview = document.querySelector('.preview');
input.addEventListener('change', fileChanged);
function fileChanged() {
while (preview.firstChild) {
preview.removeChild(preview.firstChild);
}
const curFiles = input.files;
if (curFiles.length === 0) {
const para = document.createElement('p');
para.textContent = 'No files currently selected for upload';
preview.appendChild(para);
} else {
var curFile = curFiles[0]; // only handle one input file
curFile.arrayBuffer().then((bytes) => {
startDemux(bytes);
});
}
}
</script>
</body>
</html>