@invintusmedia/tomp4 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +95 -0
- package/dist/tomp4.js +1617 -0
- package/package.json +43 -0
- package/src/fmp4-to-mp4.js +375 -0
- package/src/hls.js +280 -0
- package/src/index.js +311 -0
- package/src/ts-to-mp4.js +1154 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TVWIT
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<div><b>toMp4</b></div>
|
|
3
|
+
<div>turn streams into files</div>
|
|
4
|
+
<div><code>npm install tomp4</code></div>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
you've got an HLS stream, or some `.ts` segments, or fMP4 chunks.
|
|
10
|
+
|
|
11
|
+
you want an `.mp4` file.
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import toMp4 from 'tomp4'
|
|
15
|
+
|
|
16
|
+
const mp4 = await toMp4('https://example.com/stream.m3u8')
|
|
17
|
+
mp4.download('my-video.mp4')
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
that's it. no ffmpeg. no wasm. no dependencies.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### from different sources
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// HLS playlist (auto-picks highest quality)
|
|
28
|
+
const mp4 = await toMp4('https://example.com/master.m3u8')
|
|
29
|
+
|
|
30
|
+
// single .ts segment
|
|
31
|
+
const mp4 = await toMp4('https://example.com/segment.ts')
|
|
32
|
+
|
|
33
|
+
// raw bytes you already have
|
|
34
|
+
const mp4 = await toMp4(uint8Array)
|
|
35
|
+
|
|
36
|
+
// pick your quality
|
|
37
|
+
const hls = await toMp4.parseHls('https://example.com/master.m3u8')
|
|
38
|
+
console.log(hls.qualities) // ['1080p', '720p', '480p']
|
|
39
|
+
const mp4 = await toMp4(hls.select('720p'))
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### use the result
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// download it
|
|
46
|
+
mp4.download('video.mp4')
|
|
47
|
+
|
|
48
|
+
// play it
|
|
49
|
+
video.src = mp4.toURL()
|
|
50
|
+
|
|
51
|
+
// get the bytes
|
|
52
|
+
mp4.data // Uint8Array
|
|
53
|
+
mp4.toArrayBuffer()
|
|
54
|
+
mp4.toBlob()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### what it does
|
|
60
|
+
|
|
61
|
+
remuxes video. no transcoding.
|
|
62
|
+
|
|
63
|
+
| input | output |
|
|
64
|
+
|-------|--------|
|
|
65
|
+
| `.ts` (MPEG-TS) | `.mp4` |
|
|
66
|
+
| `.m4s` (fMP4) | `.mp4` |
|
|
67
|
+
| `.m3u8` (HLS) | `.mp4` |
|
|
68
|
+
|
|
69
|
+
video: H.264, H.265
|
|
70
|
+
audio: AAC
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
### what it doesn't do
|
|
75
|
+
|
|
76
|
+
- transcode (no converting h264→h265, etc)
|
|
77
|
+
- handle DRM/encrypted streams
|
|
78
|
+
- support MP3, AC-3 audio (yet)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### browser + node
|
|
83
|
+
|
|
84
|
+
works in both. ~50kb minified.
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<script type="module">
|
|
88
|
+
import toMp4 from './dist/tomp4.js'
|
|
89
|
+
</script>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
MIT
|
|
95
|
+
|