- JSMpeg player is based on jsmpeg.
- The video must be compressed into the TS format of MPEG1 / MP2.
- Apple device automatically plays without sound, you need to guide the user to click on the video in the lower right corner of the video icon to unlock the sound. (no similar problem in non-autoplay mode)
$ npm install jsmpeg-player --save
# or
$ yarn add jsmpeg-player
import JSMpeg from 'jsmpeg-player';
# OR
const JSMpeg = require('jsmpeg-player');
new JSMpeg.VideoElement(videoWrapper, videoUrl [, options] [, overlayOptions])
-
JSMpeg.VideoElement
config:videoWrapper
: [String | Element] The wrapper of the video. Height and width of wrapper must be initialized.videoUrl
: [String] A URL to an MPEG .ts fileoptions
: [Object] support:canvas
: [String | Element] The HTML canvas element to use for video rendering. If none is given, the renderer will create its own canvas element. Default''
.canvasWidth
: [Number] Set the width of the HTML canvas element.0
means autoset. Default0
.canvasHeight
: [Number] Set the height of the HTML canvas element.0
means autoset. Default0
.poster
: [String] URL to an image to use as the poster to show before the video plays. (Recommended to set it manually)autoplay
: [Boolean] Whether to start playing immediately. Defaultfalse
.loop
: [Boolean] Whether to loop the video (static files only). Defaultfalse
.[overwrite]control
: [Boolean] Whether the user can control. Defaulttrue
.decodeFirstFrame
: [Boolean] Whether to decode and display the first frame of the video. Defaulttrue
.picMode
: [Boolean] Picture mode (no playButton). Defaultfalse
.progressive
: [Boolean] whether to load data in chunks (static files only). Defaulttrue
.chunkSize
[Number] The chunk size in bytes to load at a time. Default1024*1024
(1mb).hooks
: [Object] The hook functionplay
: [Function] The hook function when the video play.pause
: [Function] The hook function when the video pause.stop
: [Function] The hook function when the video stop.load
: [Function] The hook function when the video established.
overlayOptions
: [Object] More options can view the jsmpeg options
-
JSMpeg.VideoElement
instance supports the following methods:play()
: Start playbackpause()
: Pause playbackstop()
: Stop playback and seek to the beginningdestroy()
: Stop playback and empty video wrapper
-
JSMpeg.VideoElement.player
instance API can view the JSMpeg.Player API
<div id="videoWrapper"></div>
<script src="JSMpeg.min.js"></script>
<script>
var videoUrl = '../static/media/test_video.ts';
new JSMpeg.VideoElement('#videoWrapper', videoUrl);
</script>
To use via a CDN include this in your HTML:
<script src="https://cdn.jsdelivr.net/npm/jsmpeg-player@2/build/JSMpeg.min.js"></script>
$ ffmpeg -i input.mp4 -f mpegts
-codec:v mpeg1video -s 640x360 -b:v 700k -r 25 -bf 0
-codec:a mp2 -ar 44100 -ac 1 -b:a 64k
output.ts
- options
-s
: video size-b:v
: video bit rate-r
: frame rate-ar
: sampling rate-ac
: number of audio channels-b:a
: audio bit rate