You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-18Lines changed: 38 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,34 @@
1
1
mp4analyzer.js
2
2
==============
3
3
4
-
mp4analyzer.js is a tool for parsing mp4/mov files and extracting information. It uses HTML5 [FileReader](http://developer.mozilla.org/en-US/docs/Web/API/FileReader) and [DataView](http://developer.mozilla.org/en-US/docs/Web/API/DataView) APIs to read local files. Currently it only returns the codec of the first video and audio streams, but it can be extended to extract anything contained in mp4 atoms.
4
+
mp4analyzer.js is a tool for parsing mp4/mov files and extracting information.
5
+
It uses HTML5 [FileReader](http://developer.mozilla.org/en-US/docs/Web/API/FileReader) and
6
+
[DataView](http://developer.mozilla.org/en-US/docs/Web/API/DataView) APIs to read local files.
7
+
Currently it only returns the codec of the first video and audio streams, but it can be extended
8
+
to extract anything contained in mp4 atoms.
5
9
6
10
Building
7
11
--------
8
12
9
-
mp4analyzer.js has been designed to be minified and optimized with [Google Closure Compiler](https://developers.google.com/closure/compiler/). The included makefile helps in the building process. It contains four targets:
13
+
mp4analyzer.js has been designed to be minified and optimized with
14
+
[Google Closure Compiler](https://developers.google.com/closure/compiler/). The included makefile
15
+
helps in the building process. It contains four targets:
10
16
11
17
*__wrap__: wrap the library in a single uncompressed file (output: build/mp4analyzer.js)
12
18
*__minify__: minify the library with Closure compiler (output: build/mp4analyzer.min.js)
13
-
*__optimize__: minify the library with Closure Compiler in advanced mode (output: build/mp4analyzer.opt.js); this is the best choice and should be preferred. Closure Compiler removes dead code and produces code which is easier to optimize for modern JavaScript engines.
19
+
*__optimize__: minify the library with Closure Compiler's
*__all (default):__ build plain, minified and optimized versions of the library
15
22
16
-
To use Closure Compiler you make tell make where the Closure Compiler's jar file is located:
17
-
```
23
+
To use Closure Compiler you must tell make where the Closure Compiler's jar file is located:
24
+
25
+
```sh
18
26
make CLOSURE_COMPILER=/path/to/compiler.jar
19
27
```
20
-
Make will invoke ```java -jar /path/to/compiler.jar```. Alternatively you can override the full command:
21
-
```
28
+
29
+
Make will invoke ```java -jar /path/to/compiler.jar```. You can also override the full command:
30
+
31
+
```sh
22
32
make CLOSURE_COMMAND=your_compiler_cmd
23
33
```
24
34
@@ -27,7 +37,7 @@ Usage
27
37
28
38
### A trivial example
29
39
30
-
```
40
+
```html
31
41
<!DOCTYPE html>
32
42
<html>
33
43
<head>
@@ -53,34 +63,42 @@ Usage
53
63
54
64
### Namespace
55
65
56
-
mp4analyzer.js exports a global object named ```MP4```. This namespace contains all methods and properties defined by the library.
66
+
mp4analyzer.js exports a global object named ```MP4```. This namespace contains all methods and
67
+
properties defined by the library.
57
68
58
69
### Checking for browser support
59
70
60
-
```
71
+
```js
61
72
MP4.supported=true/false;
62
73
```
63
74
64
75
A boolean property named ```supported``` is defined in the ```MP4``` namespace.
65
-
It will be set to false when the requested APIs are not supported.
76
+
It is set to false if the requested APIs are not supported.
66
77
67
78
### Running the analyzer
68
79
69
-
```
80
+
```js
70
81
MP4.analyze=function( // return type: boolean
71
82
blob, // type: Blob
72
83
callback// type: function(result)
73
84
);
74
85
```
75
86
76
-
To analyze a file you only need to call ```MP4.analyze```. The first argument must be a HTML5 [File](http://developer.mozilla.org/en-US/docs/Web/API/File) or [Blob](http://developer.mozilla.org/en-US/docs/Web/API/Blob) object. A [TypeError](http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) exception is thrown when ```blob``` does not inherit the ```Blob``` object and when ```blob.type``` is not 'video/mp4', 'audio/mp4' or 'video/quicktime'.
77
-
The second argument is a completion callback. The analysis process is asynchronous to avoid blocking the browser while waiting for disk I/O. The argument passed to the callback is the result object.
87
+
To analyze a file you only need to call ```MP4.analyze```. The first argument must be a HTML5
88
+
[File](http://developer.mozilla.org/en-US/docs/Web/API/File) or
A [TypeError](http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) exception
91
+
is thrown when ```blob``` does not inherit the ```Blob``` object and when ```blob.type``` is not 'video/mp4',
92
+
'audio/mp4' or 'video/quicktime'.
93
+
The second argument is a completion callback. The analysis process is asynchronous to avoid blocking the browser
94
+
while waiting for disk I/O. The argument passed to the callback is the result object.
78
95
79
-
```MP4.analyze``` will return ```false``` and do nothing when ```MP4.supported``` is ```false```; it will return ```true``` otherwise.
96
+
```MP4.analyze``` will return ```false``` and do nothing when ```MP4.supported``` is ```false```;
97
+
it will return ```true``` otherwise.
80
98
81
99
### Reading results
82
100
83
-
```
101
+
```js
84
102
{
85
103
video: { // null if no video stream found
86
104
codec:'codec name'
@@ -91,7 +109,9 @@ The second argument is a completion callback. The analysis process is asynchrono
91
109
};
92
110
```
93
111
94
-
This is the structure of the result object passed to the callback. As stated above, the analyzer currently extracts only the codec name for the first video and audio streams. If no video or audio stream is found the concerning field in the result object is set to ```null```.
112
+
This is the structure of the result object passed to the callback. As stated above, the analyzer
113
+
currently extracts only the codec name for the first video and audio streams. If no video or audio stream
114
+
is found, the concerning field in the result object is set to ```null```.
95
115
96
116
```result.video.codec``` contains a FOURCC code. You can find a FOURCC list [there](http://www.fourcc.org/codecs.php).
97
117
```result.audio.codec``` containes one of these strings:
@@ -106,7 +126,7 @@ This is the structure of the result object passed to the callback. As stated abo
106
126
Browser support
107
127
---------------
108
128
109
-
Firefox 15, Chrome 9, Internet Explorer 10, Opera 12.1, Safari 6.0.2
129
+
Firefox >= 15, Chrome >= 9, Internet Explorer >= 10, Opera >= 12.1, Safari >= 6.0.2
0 commit comments