Stable
This commit is contained in:
10
index.js
10
index.js
@@ -15,9 +15,11 @@ module.exports = async options => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fallbackToDefault = (property, defaultValue) => {
|
const fallbackToDefault = (property, defaultValue) => {
|
||||||
options[property] = Object.prototype.hasOwnProperty.call(options, property) ? options[property] : defaultValue
|
options[property] = hasOwnProperty.call(options, property) ? options[property] : defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||||
|
|
||||||
// Buffer Video Element
|
// Buffer Video Element
|
||||||
const video = document.createElement('video')
|
const video = document.createElement('video')
|
||||||
video.src = options.url
|
video.src = options.url
|
||||||
@@ -69,8 +71,8 @@ module.exports = async options => {
|
|||||||
const interval = (options.endTime - options.startTime) / (options.count + 1)
|
const interval = (options.endTime - options.startTime) / (options.count + 1)
|
||||||
|
|
||||||
// Set Width and Height
|
// Set Width and Height
|
||||||
let isWidthSet = Object.prototype.hasOwnProperty.call(options, 'width')
|
let isWidthSet = hasOwnProperty.call(options, 'width')
|
||||||
let isHeightSet = Object.prototype.hasOwnProperty.call(options, 'height')
|
let isHeightSet = hasOwnProperty.call(options, 'height')
|
||||||
const videoDimensionRatio = video.videoWidth / video.videoHeight
|
const videoDimensionRatio = video.videoWidth / video.videoHeight
|
||||||
|
|
||||||
// Reset Width and Height if not valid
|
// Reset Width and Height if not valid
|
||||||
@@ -106,7 +108,7 @@ module.exports = async options => {
|
|||||||
await new Promise(resolve => { seekResolve = resolve })
|
await new Promise(resolve => { seekResolve = resolve })
|
||||||
context.clearRect(0, 0, canvas.width, canvas.height)
|
context.clearRect(0, 0, canvas.width, canvas.height)
|
||||||
context.drawImage(video, 0, 0, canvas.width, canvas.height)
|
context.drawImage(video, 0, 0, canvas.width, canvas.height)
|
||||||
frames.push(canvas.toDataURL(options.format))
|
frames.push({ offset: video.currentTime, image: canvas.toDataURL(options.format) })
|
||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
resolve(frames)
|
resolve(frames)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "video-frames",
|
"name": "video-frames",
|
||||||
"version": "0.1.1",
|
"version": "1.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Client side video frames extraction as base64 encoded images",
|
"description": "Client side video frames extraction as base64 encoded images",
|
||||||
"author": "Utkarsh Verma",
|
"author": "Utkarsh Verma",
|
||||||
|
|||||||
Reference in New Issue
Block a user