forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codecs.html
134 lines (114 loc) · 3.67 KB
/
codecs.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
<html>
<body>
<div id="output"></div>
<script>
function getSupportedMimeTypes(media, types, codecs) {
const supported = [];
types.forEach((type) => {
const mimeType = `${media}/${type}`;
codecs.forEach((codec2) => { // video/webm;codecs=pcm
console.log(codec2);
codecs.forEach((codec) => {
try {
if (codec && codec2){
if (codec ==codec2){return;}
var x = [
mimeType+';codecs='+codec.toLowerCase()+', '+codec2.toLowerCase()+''//,
//mimeType+';codecs:'+codec.toLowerCase()+', '+codec2.toLowerCase()+'',
];
for (var i=0;i<x.length;i++){
let variation = x[i];
if (MediaRecorder.isTypeSupported(variation)){
try {
//options.mimeType = variation;
//new MediaRecorder(stream, options);
//mediaSource.addSourceBuffer(variation);
supported.push(variation);
break;
//console.log(options);
} catch(e){
//console.warn(options, e);
console.error(e);
}
}
}
} else if (codec){
var x = [
mimeType+';codecs='+codec.toLowerCase()//,
//mimeType+';codecs:'+codec.toLowerCase()
];
for (var i=0;i<x.length;i++){
let variation = x[i];
if (MediaRecorder.isTypeSupported(variation)){
try {
//options.mimeType = variation;
//console.log(options);
//new MediaRecorder(stream, options);
//mediaSource.addSourceBuffer(variation);
supported.push(variation);
break;
//console.log(options);
} catch(e){
//console.warn(options);
console.error(e);
}
}
}
}
} catch(e){console.error(e);}
});
});
if (MediaRecorder.isTypeSupported(mimeType))
supported.push(mimeType);
});
return supported;
};
var options = {};
options.videoBitsPerSecond = parseInt(2500 * 1024);
const videoTypes = ["webm", "mpeg", "mp4", "x-matroska"];
const audioTypes = ["webm", "mpeg", "ogg", "x-matroska"];
const codecs = ["vp9", "vp9.0", "vp8", "vp8.0", "avc1", "av1x", "av1", "h265", "h.265", "h264", "h.264", "av01.0.04M.08", "vp09.00.10.08", "avc1.42001E", ""]
const acodecs = ["opus", "pcm", "mp4a.40.2", "aac", "mpeg", "mp4a", "mp3", "vorbis", "L16", "wav", ""];
document.getElementById("output").innerHTML= "";
var supportedVideos = null;
var supportedAudios = null;
var stream = null;
var mediaSource = new MediaSource();
var video = document.createElement("video");
video.autoplay = true;
video.muted = false;
video.setAttribute("playsinline","");
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', sourceOpen);
function sourceOpen(e) {
console.log("2");
navigator.mediaDevices.getUserMedia({audio:true,video:true}).then(function(s) {
stream = s;
console.log("START");
supportedAudios = getSupportedMimeTypes("audio", audioTypes, acodecs);
console.log("DONE AUDIO");
supportedVideos = getSupportedMimeTypes("video", videoTypes, [...codecs, ...acodecs]); // video/webm;codecs=pcm
for (var i=0;i<supportedVideos.length;i++){
document.getElementById("output").innerHTML += supportedVideos[i]+"<br/>";
}
for (var i=0;i<supportedAudios.length;i++){
document.getElementById("output").innerHTML += supportedAudios[i]+"<br/>";
}
console.log("DONE");
stream.getTracks(x=>{
stream.removeTrack(x);
x.stop();
x =null;
});
stream=null;
s = null;
}).catch(function(err) {
/* handle the error */
});
}
//for (var i=0;i<supportedAudios.length;i++){
//document.getElementById("output").innerHTML += supportedAudios[i]+"<br/>";
//}
</script>
</body>
</html>