Use capture-frame package
See: https://github.com/feross/capture-frame Capture video screenshot from a `<video>` tag (at the current time) Changes from our version: - Added tests in Chrome/Firefox browsers. - Use built-in TypeError (which is meant for bad arguments) instead of custom IllegalArgumentError.
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
module.exports = captureVideoFrame
|
||||
|
||||
const {IllegalArgumentError} = require('./errors')
|
||||
|
||||
function captureVideoFrame (video, format) {
|
||||
if (typeof video === 'string') {
|
||||
video = document.querySelector(video)
|
||||
}
|
||||
|
||||
if (video == null || video.nodeName !== 'VIDEO') {
|
||||
throw new IllegalArgumentError('First argument must be a <video> element or selector')
|
||||
}
|
||||
|
||||
if (format == null) {
|
||||
format = 'png'
|
||||
}
|
||||
|
||||
if (format !== 'png' && format !== 'jpg' && format !== 'webp') {
|
||||
throw new IllegalArgumentError('Second argument must be one of "png", "jpg", or "webp"')
|
||||
}
|
||||
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = video.videoWidth
|
||||
canvas.height = video.videoHeight
|
||||
|
||||
canvas.getContext('2d').drawImage(video, 0, 0)
|
||||
|
||||
const dataUri = canvas.toDataURL('image/' + format)
|
||||
const data = dataUri.split(',')[1]
|
||||
|
||||
return new Buffer(data, 'base64')
|
||||
}
|
||||
@@ -35,10 +35,6 @@ class TorrentKeyNotFoundError extends TorrentError {
|
||||
|
||||
class InvalidTorrentError extends TorrentError {}
|
||||
|
||||
/* Miscellaneous */
|
||||
|
||||
class IllegalArgumentError extends ExtendableError {}
|
||||
|
||||
module.exports = {
|
||||
CastingError,
|
||||
PlaybackError,
|
||||
@@ -49,6 +45,5 @@ module.exports = {
|
||||
PlaybackTimedOutError,
|
||||
InvalidSoundNameError,
|
||||
TorrentKeyNotFoundError,
|
||||
InvalidTorrentError,
|
||||
IllegalArgumentError
|
||||
InvalidTorrentError
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module.exports = torrentPoster
|
||||
|
||||
const captureVideoFrame = require('./capture-video-frame')
|
||||
const captureFrame = require('capture-frame')
|
||||
const path = require('path')
|
||||
|
||||
function torrentPoster (torrent, cb) {
|
||||
@@ -61,7 +61,7 @@ function torrentPosterFromVideo (file, torrent, cb) {
|
||||
function onSeeked () {
|
||||
video.removeEventListener('seeked', onSeeked)
|
||||
|
||||
const buf = captureVideoFrame(video)
|
||||
const buf = captureFrame(video)
|
||||
|
||||
// unload video element
|
||||
video.pause()
|
||||
|
||||
Reference in New Issue
Block a user