This repository was archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.html
150 lines (94 loc) · 3.85 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Live video MSE using ffmpeg, node.js, and socket.io</title>
<script src ="/socket.io/socket.io.js"></script>
<script src="/flv.min.js"></script>
</head>
<body>
<video id="mse" muted width="640" height="360"></video>
<script>
(function () {
/*
https://cconcolato.github.io/media-mime-support/
h.264 profile, xx is level
baseline = avc1.42E0xx;
constrained main = avc1.4D40xx;
main = avc1.4D00xx
high = avc1.6400xx;
h.264 level (hex values)
3.0 = 1E
3.1 = 1F;
4.0 = 28;
4.1 = 29;
4.2 = 2A;
audio
mp4a.40.2
ex. main 4.1 with audio; mime = 'video/mp4; codecs="avc1.4D0029, mp4a.40.2"'
use -movflags +frag_keyframe+empty_moov+default_base_moof to generate a compatibly fragmented mp4 from ffmpeg
*/
var mime = 'video/mp4; codecs="avc1.4D0029"';
if (!MediaSource.isTypeSupported(mime)) {
alert('Unsupported mime type');
return;
}
var buffer;
var socket;
var video = document.getElementById('mse');
var mediaSource = new MediaSource();
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceended', function(e) {
console.log('sourceended: ' + mediaSource.readyState);
});
mediaSource.addEventListener('sourceclose', function(e) {
console.log('sourceclose: ' + mediaSource.readyState);
//todo remove( buffer = mediaSource.addSourceBuffer(mime))
});
mediaSource.addEventListener('error', function(e) {
console.log('error: ' + mediaSource.readyState);
});
mediaSource.addEventListener('sourceopen', function(e) {
console.log('sourceopen: ' + mediaSource.readyState);
buffer = mediaSource.addSourceBuffer(mime);
buffer.mode = 'sequence';
buffer.addEventListener('update', function(e) {
console.log('update');
});
buffer.addEventListener('updateend', function(e) {
console.log('updateend');
//hack to get safari on mac to start playing, video.currentTime gets stuck on 0
if (mediaSource.duration !== Number.POSITIVE_INFINITY && video.currentTime === 0 && mediaSource.duration > 0) {
video.currentTime = mediaSource.duration - 1;
mediaSource.duration = Number.POSITIVE_INFINITY;
}
video.play();
});
socket = io(null, {transports: ['websocket']});
socket.emit('message', 'start');
socket.on('segment', function (data) {
var data = new Uint8Array(data);
buffer.appendBuffer(data);
});
socket.on('message', function(msg) {
alert('Message from server: ' + msg);
});
}, false);
})();
</script>
<video width="640" height="360" id="videoElement"></video>
<script>
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
var flvPlayer = flvjs.createPlayer({
isLive: true,
type: 'mp4',
url: '/test.mp4'//change to test2.mp4 to get
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
flvPlayer.play();
}
</script>
</body>
</html>