Gathering detailed insights and metrics for @sqhead/mux.js
Gathering detailed insights and metrics for @sqhead/mux.js
Gathering detailed insights and metrics for @sqhead/mux.js
Gathering detailed insights and metrics for @sqhead/mux.js
mux.js
A collection of lightweight utilities for inspecting and manipulating video container formats.
@mux-network/mux.js
Mux Protocol JavaScript API
@hola.org/mux.js
A collection of lightweight utilities for inspecting and manipulating video container formats.
muxjs
Modeling app states with muxjs.
npm install @sqhead/mux.js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,118 Stars
508 Commits
211 Forks
44 Watching
48 Branches
45 Contributors
Updated on 26 Nov 2024
JavaScript (96.22%)
HTML (3.29%)
CSS (0.49%)
Cumulative downloads
Total Downloads
Last day
7.7%
70
Compared to previous day
Last week
-7.7%
313
Compared to previous week
Last month
20.1%
1,337
Compared to previous month
Last year
24%
11,805
Compared to previous year
Lightweight utilities for inspecting and manipulating video container formats.
Maintenance Status: Stable
To install mux.js
with npm run
1npm install --save mux.js
Download a copy of this git repository and then follow the steps in Building
If you're using this project in a node-like environment, just require()
whatever you need. If you'd like to package up a distribution to include separately, run npm run build
. See the package.json
for other handy scripts if you're thinking about contributing.
If you are a collaborator, we have a guide on how to release the project.
If you are interested in contributing to mux.js
, take a look at our docs on streams to get started.
The exported muxjs
object contains the following modules:
muxjs.codecs.Adts
The Adts(Audio Data Transport Stream) module handles audio data, specifically AAC. Includes an AdtsStream
that takes ADTS audio and parses out AAC frames to pass on to the next Stream component in a pipeline.
muxjs.codecs.h264
The h264 module Handles H264 bitstreams, including a NalByteStream
and H264Stream
to parse out NAL Units and pass them on to the next Stream component in a pipeline.
muxjs.mp4.generator
The MP4 Generator module contains multiple functions that can be used to generate fragmented MP4s (fmp4s) that can be used in MSE.
muxjs.mp4.probe
The MP4 Probe contains basic utilites that can be used to parse metadata about an MP4 segment. Some examples include: timescale
and getting the base media decode time of a fragment in seconds.
muxjs.mp4.Transmuxer
Takes MPEG2-TS segments and transmuxes them into fmp4 segments.
Options:
Type: number
Default: 0
The Base Media Decode Time of the first segment to be passed into the transmuxer.
Type: boolean
Default: false
The default behavior of the MP4 Transmuxer is to rewrite the timestamps of media segments to ensure that they begin at 0
on the media timeline in MSE. To avoid this behavior, you may set this option to true
.
Note: This will affect behavior of captions and metadata, and these may not align with audio and video without additional manipulation of timing metadata.
Type: boolean
Default: true
Set to true
to remux audio and video into a single MP4 segment.
muxjs.mp4.CaptionParser
This module reads CEA-608 captions out of FMP4 segments.
muxjs.mp4.WebVTTParser
This module reads WebVTT text out of FMP4 segments.
muxjs.mp4.tools
This module includes utilities to parse MP4s into an equivalent javascript object, primarily for debugging purposes.
muxjs.flv.Transmuxer
Takes MPEG2-TS segments and transmuxes them into FLV segments. This module is in maintenance mode and will not have further major development.
muxjs.flv.tools
This module includes utilities to parse FLV tags into an equivalent javascript object, primarily for debugging purposes.
muxjs.mp2t
Contains Streams specifically to handle MPEG2-TS data, for example ElementaryStream
and TransportPacketStream
. This is used in the MP4 module.
muxjs.mp2t.CaptionStream
Handles the bulk of parsing CEA-608 captions out of MPEG2-TS segments.
muxjs.mp2t.tools
This module contains utilities to parse basic timing information out of MPEG2-TS segments.
Before making use of the Transmuxer it is best to understand the structure of a fragmented MP4 (fMP4).
fMP4's are structured in boxes as described in the ISOBMFF spec.
For a basic fMP4 to be valid it needs to have the following boxes:
Every fMP4 stream needs to start with an ftyp
and moov
box which is then followed by many moof
and mdat
pairs.
It is important to understand that when you append your first segment to Media Source Extensions that this segment will need to start with an ftyp
and moov
followed by a moof
and mdat
. A segment containing a ftyp
and moov
box is often referred to as an Initialization Segment(init
) segment, and segments containing moof
and mdat
boxes, referring to media itself as Media Segments.
If you would like to see a clearer representation of your fMP4 you can use the muxjs.mp4.tools.inspect()
method.
To make use of the Transmuxer method you will need to push data to the transmuxer you have created.
Feed in Uint8Array
s of an MPEG-2 transport stream, get out a fragmented MP4.
Lets look at a very basic representation of what needs to happen the first time you want to append a fMP4 to an MSE buffer.
1// Create your transmuxer: 2// initOptions is optional and can be omitted at this time. 3var transmuxer = new muxjs.mp4.Transmuxer(initOptions); 4 5// Create an event listener which will be triggered after the transmuxer processes data: 6// 'data' events signal a new fMP4 segment is ready 7transmuxer.on('data', function (segment) { 8 // This code will be executed when the event listener is triggered by a Transmuxer.push() method execution. 9 // Create an empty Uint8Array with the summed value of both the initSegment and data byteLength properties. 10 let data = new Uint8Array(segment.initSegment.byteLength + segment.data.byteLength); 11 12 // Add the segment.initSegment (ftyp/moov) starting at position 0 13 data.set(segment.initSegment, 0); 14 15 // Add the segment.data (moof/mdat) starting after the initSegment 16 data.set(segment.data, segment.initSegment.byteLength); 17 18 // Uncomment this line below to see the structure of your new fMP4 19 // console.log(muxjs.mp4.tools.inspect(data)); 20 21 // Add your brand new fMP4 segment to your MSE Source Buffer 22 sourceBuffer.appendBuffer(data); 23}); 24 25// When you push your starting MPEG-TS segment it will cause the 'data' event listener above to run. 26// It is important to push after your event listener has been defined. 27transmuxer.push(transportStreamSegment); 28transmuxer.flush();
Above we are adding in the initSegment
(ftyp/moov) to our data array before appending to the MSE Source Buffer.
This is required for the first part of data we append to the MSE Source Buffer, but we will omit the initSegment
for our remaining chunks (moof/mdat)'s of video we are going to append to our Source Buffer.
In the case of appending additional segments after your first segment we will just need to use the following event listener anonymous function:
1transmuxer.on('data', function(segment){ 2 sourceBuffer.appendBuffer(new Uint8Array(segment.data)); 3});
Here we put all of this together in a very basic example player.
1<html> 2 <head> 3 <title>Basic Transmuxer Test</title> 4 </head> 5 <body> 6 <video controls width="80%"></video> 7 <script src="https://github.com/videojs/mux.js/releases/latest/download/mux.js"></script> 8 <script> 9 // Create array of TS files to play 10 segments = [ 11 "segment-0.ts", 12 "segment-1.ts", 13 "segment-2.ts", 14 ]; 15 16 // Replace this value with your files codec info 17 mime = 'video/mp4; codecs="mp4a.40.2,avc1.64001f"'; 18 19 let mediaSource = new MediaSource(); 20 let transmuxer = new muxjs.mp4.Transmuxer(); 21 22 video = document.querySelector('video'); 23 video.src = URL.createObjectURL(mediaSource); 24 mediaSource.addEventListener("sourceopen", appendFirstSegment); 25 26 function appendFirstSegment(){ 27 if (segments.length == 0){ 28 return; 29 } 30 31 URL.revokeObjectURL(video.src); 32 sourceBuffer = mediaSource.addSourceBuffer(mime); 33 sourceBuffer.addEventListener('updateend', appendNextSegment); 34 35 transmuxer.on('data', (segment) => { 36 let data = new Uint8Array(segment.initSegment.byteLength + segment.data.byteLength); 37 data.set(segment.initSegment, 0); 38 data.set(segment.data, segment.initSegment.byteLength); 39 console.log(muxjs.mp4.tools.inspect(data)); 40 sourceBuffer.appendBuffer(data); 41 // reset the 'data' event listener to just append (moof/mdat) boxes to the Source Buffer 42 transmuxer.off('data'); 43 }) 44 45 fetch(segments.shift()).then((response)=>{ 46 return response.arrayBuffer(); 47 }).then((response)=>{ 48 transmuxer.push(new Uint8Array(response)); 49 transmuxer.flush(); 50 }) 51 } 52 53 function appendNextSegment(){ 54 transmuxer.on('data', (segment) =>{ 55 sourceBuffer.appendBuffer(new Uint8Array(segment.data)); 56 transmuxer.off('data'); 57 }) 58 59 if (segments.length == 0){ 60 // notify MSE that we have no more segments to append. 61 mediaSource.endOfStream(); 62 } 63 64 segments.forEach((segment) => { 65 // fetch the next segment from the segments array and pass it into the transmuxer.push method 66 fetch(segments.shift()).then((response)=>{ 67 return response.arrayBuffer(); 68 }).then((response)=>{ 69 transmuxer.push(new Uint8Array(response)); 70 transmuxer.flush(); 71 }) 72 }) 73 } 74 </script> 75 </body> 76</html>
NOTE: This player is only for example and should not be used in production.
The transmuxer can also parse out supplementary video data like timed ID3 metadata and CEA-608 captions. You can find both attached to the data event object:
1transmuxer.on('data', function (segment) {
2 // create a metadata text track cue for each ID3 frame:
3 segment.metadata.frames.forEach(function(frame) {
4 metadataTextTrack.addCue(new VTTCue(time, time, frame.value));
5 });
6 // create a VTTCue for all the parsed CEA-608 captions:>
7 segment.captions.forEach(function(captionSet) {
8 // Caption sets contains multiple caption cues with text and position data.
9 captionSet.content.forEach(function(cue) {
10 const newCue = new VTTCue(cue.startTime, cue.endTime, cue.text);
11 newCue.line = cue.line;
12 newCue.position = cue.position;
13
14 captionTextTrack.addCue(newCue);
15 });
16 });
17});
Parse MP4s into javascript objects or a text representation for display or debugging:
1// drop in a Uint8Array of an MP4: 2var parsed = muxjs.mp4.tools.inspect(bytes); 3// dig into the boxes: 4console.log('The major brand of the first box:', parsed[0].majorBrand); 5// print out the structure of the MP4: 6document.body.appendChild(document.createTextNode(muxjs.textifyMp4(parsed)));
The MP4 inspector is used extensively as a debugging tool for the transmuxer. You can see it in action by cloning the project and opening the debug page in your browser.
Check out our troubleshooting guide. We have some tips on creating test content. Also, check out our guide on working with captions in Mux.js.
Drop by our slack channel (#playback) on the Video.js slack.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 11/17 approved changesets -- score normalized to 6
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
44 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More