This commit is contained in:
Utkarsh Verma
2022-04-29 16:50:08 +05:30
parent 8395aa3b88
commit 99c3cbeb91
2 changed files with 7 additions and 5 deletions

View File

@@ -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)

View File

@@ -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",