mp4.js is a library that convert mp4 to fmp4 at browser-side in time. it supports web player can play remote mp4 video file as stream.
Usually web player can play ordinary mp4 file by video,but it can’t control loading media data or switch media resource smoothly.
If you use mp4.js than can load any media data as any indicated time,because it can analyze meta information and get binaray data without changing by service.
Usage
the package provides three version such as commonjs、esmodule、umd.
parameter requires remote address of mp4 file which supports CORS
false
options
parameter include withCredentials and videoOnly
true
chunkSize
parameter means data length per request which help minimize the network traffic
true
Method
mp4.getData(start,end,chunkSize)
parameter
description
optional
start
parameter requires initial position by byte
false
end
parameter requires end position by byte
false
chunkSize
parameter means data length number per request
true
return
Promise instance which outputs object incaluding xhr state
-
Usually you need’t use it directly because MP4 provides advanced interface. Of course you can use it control more details.
mp4.getMetaInfo(start,end)
parameter
description
optional
start
parameter requires initial position by byte,default is zero
false
end
parameter requires end position by byte
true
this interface can get basic information about the mp4 file such as ftyp、moov、mdat. if succees it will trigger ‘moovReady’ event and the property mp4.meta is available.
mp4.packMeta()
parameter
description
return
Array.buffer
You know the moov box is indifferent between mp4 and fmp4,so we need repack the moov box. you just call the function once when MSE initialize because it includes ftyp and moov box.
Introduction
mp4.js is a library that convert mp4 to fmp4 at browser-side in time. it supports web player can play remote mp4 video file as stream.
Usually web player can play ordinary mp4 file by video,but it can’t control loading media data or switch media resource smoothly.
If you use mp4.js than can load any media data as any indicated time,because it can analyze meta information and get binaray data without changing by service.
Usage
the package provides three version such as commonjs、esmodule、umd.
you can reffer more code in examples directory.
Examples
you can visit xgplayer website to experience it. if you just develop locally by reffering github examples
API
MP4 Class
Method
Usually you need’t use it directly because MP4 provides advanced interface. Of course you can use it control more details.
this interface can get basic information about the mp4 file such as ftyp、moov、mdat. if succees it will trigger ‘moovReady’ event and the property mp4.meta is available.
You know the moov box is indifferent between mp4 and fmp4,so we need repack the moov box. you just call the function once when MSE initialize because it includes ftyp and moov box.
in most time, the interface is enough.
empty mse buffer cache and download cache.
Event
MP4.MSE Class
MP4.MSE extends raw MSE API and Event.
Other
if you’re interested in this package, xgplayer and xgplayer-mp4 is better way to learn that gives more usage and compatibility in products.
License
MIT