A JavaScript Library To Convert Video Fragments To Gif.
$ npm install core-video-to-gif --save
<script src="./dist/core-video-to-gif.min.js"></script>
const v2g = new CoreVideoToGif({
// specify the video element
el: document.querySelector('video'),
// video 的父容器
parentEl: document.querySelector('.conatiner')
})
v2g.shot({
// options,
start: 5, // ms
end: 8
}, (result) => {
// ...
image.src = result
})
key | Type | Details | Value |
---|---|---|---|
* el | Element | The video element | <video ... > |
workerScript | String | enable Web Worker | Please inclued the [script](https://github.com/JackPu/core-video-to-gif/blob/master/examples/gif.worker.js), and specify the path |
width | Number | The output git width | 600(default: the video original height) |
height | Number | The output gif image height | 600(default: the video original height) |
maxTime | Number | limit the time of gif animation | 5(default: 10) |
fps | Number | the frame per second | 12(default: 6) |
quality | Number | the quality of gif | (1-10) The best is 10 |
onStartShot | Function | call when start shoting | |
onGifProcess | Function | call when making gif | |
onGifFinished | Function | call when gif output |
“*” means it is required.
You could use the method to get the video screenshots.
// get current screenshot
v2g.shot( (result) => {
// ...
image.src = result
})
// get screenshot from 5s - 8s
v2g.shot({
// options,
start: 5, // ms
end: 8
}, (result) => {
// ...
image.src = result
})
key | Type | Details | Value |
---|---|---|---|
start | Number | the screenshot start time | 6(s) |
end | Number | the screenshot end time | 7(s) |
The api is still in draft. Not work!!!
Your contributions and suggestions are welcome 😄😄😄