Video tag + Canvas
Canvas screenshot mainly relies on its drawImage method and only supports passing ing, video(image, canvas or video).
let video = this.$refs.videoPlay / / video element
let canvas = document.createElement('canvas') // Create the canvas tag
let w = window.innerWidth
let h = window.innerWidth / 16 * 9 // Calculate the aspect ratio
canvas.width = w
canvas.height = h // Set width and height
const ctx = canvas.getContext('2d') // Create canvas
ctx.drawImage(video, 0.0, w, h)
ctx.drawImage(video, 0.0, w, h) / / screenshots
let imgUrl = canvas.toDataURL('image/png') // Get the image base64
// base64 transfers images
getImage(dataUrl, fileName) {
let arr = dataUrl.split(', '), mime = arr[0].match(/ : (. *?) ; /) [1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n)
while(n--){
u8arr[n] = bstr.charCodeAt(n)
}
return new File([u8arr], fileName, {type:mime})
}
Copy the code
The pit of found
- Since it is only supported by incoming ING, video(image, canvas or video), so used
vue-video-player
When the plugin is used, some formats of streams are not played based on video, so the above screenshots do not exist. See DOM elements for details.
Ali Cloud Web player SDK supports Flash and Html5 two playback technologies.
- This is going a little too far, but the player itself supports screenshots, documentation is robust leave a portal,
- But there is one sentence in particularFlash is enabled with the snapshot property. If snapshot:true is set, RTMP streams do not support snapshots.It does not support RTMP streaming video screenshots
LivePlayer
The document addressIn fact, it’s just so-so.
Introduction (copied from the document)
- H5 live/on-demand player, simple to use, powerful, free to use
- It should also be based on video.js, although it is not stated, but the videoJS thrown from integration must be imported, so there is no need to explain anything.
- The author has a group, at the bottom of the document, the reply depends on the mood (is a joke)
function
- Support MP4 playback
- Support M3U8 /HLS playback;
- Support HTTP-FLV/WS-FLV playback;
- Support RTMP playback;
- Support live broadcast and on-demand broadcast;
- Player snapshot screenshot support;
- Support on-demand multi definition playback;
- Support full screen or proportional display;
- Built-in Flash supports extreme speed and smooth mode;
- The built-in Flash supports HTTP-FLV playback.
- Automatic detection of Internet Explorer compatible playback;
- Support custom stacking layer; v1.7.9
Integration (mainly VUE)
- First download the plug-in
npm install @liveqing/liveplayer
NPM install [email protected]
- File configuration actually gives you three ways
- Copy the required files to the project static folder and import them in index
liveplayer-lib.min.js
- Build your own project scaffolding edit webpack.config.js
const CopyWebpackPlugin = require('copy-webpack-plugin'); // Don't forget to introduce...... // copy js lib and swf files to dist dir new CopyWebpackPlugin([ { from: 'node_modules/@liveqing/liveplayer/dist/component/crossdomain.xml'}, { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer.swf'}, { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer-lib.min.js', to: 'js/'} ]), ......Copy the code
- Vue – cli editor vue. Config. Js
const CopyWebpackPlugin = require('copy-webpack-plugin'); module.exports = { configureWebpack: { plugins: [ new CopyWebpackPlugin([ { from: 'node_modules/@liveqing/liveplayer/dist/component/crossdomain.xml'}, { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer.swf'} { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer-lib.min.js', to: 'js/'}, ]) ] } } Copy the code
- In index.html
<script src="js/liveplayer-lib.min.js"></script>
The plugin moves the file below the JS folder.
- Copy the required files to the project static folder and import them in index
use
- Vue components
<LivePlayer :videoUrl="videoUrl" fluent autoplay live stretch></LivePlayer> ...... Import LivePlayer from '@liveqing/ LivePlayer '// import components...... Components: {// Register component LivePlayer}......Copy the code
Some of the pit
- Vue’s method of listening is not through
addEventListener
Instead, the component registers the corresponding function listening as@snapInside="addScreenshots"
, listens for an internal screenshot event and returns a Base64 string. - If the component container is a popover, there will be a large number of console warnings after closing the popover (actually using vue-video-player, it can be resolved by setting the ref to the player component to obtain the element and executing reload(). There are many methods that are not documented on the player Ref prototype, so if you have any problems, take a look
ckplayer
- The document address
- But it doesn’t feel very serious. Also support screenshots click in to search for screenshots keyword
- Since the above LivePlayer has solved the problem, there will be no more attempts on this.
- This may be a good choice for those who need video inserts.