-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
154 lines (126 loc) · 6.38 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
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<title>MediaInfo JS Test Page</title>
<link rel="icon" type="image/x-icon" href="https://mediaarea.net/images/f060656-9e9e132.ico" />
</head>
<a href="http://ohayou.aimo.moe"" target="frame1">Aimo</a>
<p>
<div id="full" style="width:0px; height:0px; position:fixed; right:180px; bottom:150px; z-index:100; text-align:center; background-color:transparent; cursor:pointer;">
<center>
<input type="file" id="input" />
</center>
<a href="#" onclick="goTop();return false;"><img src="totop.png" border=0 alt="Top"></a>
</div>
<script src="/javascripts/top.js" type="text/javascript"></script>
</p>
<body>
<center>
<p><h2><a href="https://mediaarea.net/en/MediaInfo/"" target="frame1">Mediainfo for JavaScripts</a></p></h2>
<p>/* Copy(Ctrl+C), CheckAll(Ctrl+A), Close(Ctrl+F4); */</p>
<p><input type="file" id="input" /></p>
</center>
<hr />
<p><pre id="result"></pre></p>
<script src="MediaInfo.js"></script>
<script type="text/javascript">
var MediaInfoModule, MI, processing = false, CHUNK_SIZE = 1024 * 1024;
var finish = function() {
MI.Close();
MI.delete();
processing = false;
}
// Examples about how to get results
var showResult = function() {
document.getElementById('result').innerText = 'Inform with Complete=false:\n';
MI.Option('Complete');
document.getElementById('result').innerText += MI.Inform();
document.getElementById('result').innerText += 'Inform with Complete=true:\n';
MI.Option('Complete', '1');
document.getElementById('result').innerText += MI.Inform();
document.getElementById('result').innerText += 'Custom Inform:\n';
MI.Option('Inform', 'General;Example: FileSize=%FileSize%')
document.getElementById('result').innerText += MI.Inform() + '\n\n';
MI.Option('Inform'); // Reset custom output
document.getElementById('result').innerText += 'Get with Stream=General and Parameter=\'FileSize\':\n';
document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.General, 0, 'FileSize') + '\n\n';
document.getElementById('result').innerText += 'GetI with Stream=General, Parameter=2, and InfoKind=Name:\n';
document.getElementById('result').innerText += MI.GetI(MediaInfoModule.Stream.General, 0, 2, MediaInfoModule.Info.Name) + '\n\n';
document.getElementById('result').innerText += 'GetI with Stream=General, Parameter=2, and InfoKind=Text:\n';
document.getElementById('result').innerText += MI.GetI(MediaInfoModule.Stream.General, 0, 2) + '\n\n';
document.getElementById('result').innerText += 'Count_Get with StreamKind=Audio:\n';
document.getElementById('result').innerText += MI.Count_Get(MediaInfoModule.Stream.Audio) + '\n\n';
document.getElementById('result').innerText += 'Get with Stream=General and Parameter=\'AudioCount\':\n';
document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.General, 0, 'AudioCount') + '\n\n';
document.getElementById('result').innerText += 'Get with Stream=Audio and Parameter=\'StreamCount\':\n';
document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.Audio, 0, 'StreamCount') + '\n';
finish();
}
var parseFile = function(file, callback) {
if (processing) {
return;
}
processing = true;
var offset = 0;
// Initialise MediaInfo
MI = new MediaInfoModule.MediaInfo();
MI.Option('File_FileName', file.name);
MI.Open_Buffer_Init(file.size, 0);
var loop = function(length) {
if (processing) {
var r = new FileReader();
var blob = file.slice(offset, offset + length);
r.onload = processChunk;
r.readAsArrayBuffer(blob);
} else {
finish()
}
};
var processChunk = function(e) {
if (e.target.error === null) {
// Send the buffer to MediaInfo
var state = MI.Open_Buffer_Continue(e.target.result);
//Test if there is a MediaInfo request to go elsewhere
var seekTo = MI.Open_Buffer_Continue_Goto_Get();
if(seekTo === -1) {
offset += e.target.result.byteLength;
} else {
offset = seekTo;
MI.Open_Buffer_Init(file.size, seekTo); // Inform MediaInfo we have seek
}
} else {
finish();
alert('An error happened reading your file!');
return;
}
// Bit 3 set means finalized
if (state&0x08 || e.target.result.byteLength < 1) {
MI.Open_Buffer_Finalize();
callback();
return;
}
loop(CHUNK_SIZE);
};
// Start
loop(CHUNK_SIZE);
}
// Initialise emscripten module
MediaInfoModule = MediaInfoLib({'postRun': function() {
console.debug('MediaInfo ready');
// Information about MediaInfo
document.getElementById('result').innerText = 'Info_Parameters:\n';
document.getElementById('result').innerText += MediaInfoModule.MediaInfo.Option_Static('Info_Parameters') + '\n\n';
document.getElementById('result').innerText += 'Info_Codecs:\n';
document.getElementById('result').innerText += MediaInfoModule.MediaInfo.Option_Static('Info_Codecs') + '\n';
// Get selected file
var input = document.getElementById('input');
input.onchange = function() {
if(input.files.length > 0) {
document.getElementById('result').innerText = "Processing...";
parseFile(input.files[0], showResult);
}
}
}});
</script>
</body>
</html>