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:
@@ -18,6 +18,7 @@
|
|||||||
"application-config": "^1.0.0",
|
"application-config": "^1.0.0",
|
||||||
"auto-launch": "^4.0.1",
|
"auto-launch": "^4.0.1",
|
||||||
"bitfield": "^1.0.2",
|
"bitfield": "^1.0.2",
|
||||||
|
"capture-frame": "^1.0.0",
|
||||||
"chromecasts": "^1.8.0",
|
"chromecasts": "^1.8.0",
|
||||||
"create-torrent": "^3.24.5",
|
"create-torrent": "^3.24.5",
|
||||||
"deep-equal": "^1.0.1",
|
"deep-equal": "^1.0.1",
|
||||||
|
|||||||
@@ -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 {}
|
class InvalidTorrentError extends TorrentError {}
|
||||||
|
|
||||||
/* Miscellaneous */
|
|
||||||
|
|
||||||
class IllegalArgumentError extends ExtendableError {}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
CastingError,
|
CastingError,
|
||||||
PlaybackError,
|
PlaybackError,
|
||||||
@@ -49,6 +45,5 @@ module.exports = {
|
|||||||
PlaybackTimedOutError,
|
PlaybackTimedOutError,
|
||||||
InvalidSoundNameError,
|
InvalidSoundNameError,
|
||||||
TorrentKeyNotFoundError,
|
TorrentKeyNotFoundError,
|
||||||
InvalidTorrentError,
|
InvalidTorrentError
|
||||||
IllegalArgumentError
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module.exports = torrentPoster
|
module.exports = torrentPoster
|
||||||
|
|
||||||
const captureVideoFrame = require('./capture-video-frame')
|
const captureFrame = require('capture-frame')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
function torrentPoster (torrent, cb) {
|
function torrentPoster (torrent, cb) {
|
||||||
@@ -61,7 +61,7 @@ function torrentPosterFromVideo (file, torrent, cb) {
|
|||||||
function onSeeked () {
|
function onSeeked () {
|
||||||
video.removeEventListener('seeked', onSeeked)
|
video.removeEventListener('seeked', onSeeked)
|
||||||
|
|
||||||
const buf = captureVideoFrame(video)
|
const buf = captureFrame(video)
|
||||||
|
|
||||||
// unload video element
|
// unload video element
|
||||||
video.pause()
|
video.pause()
|
||||||
|
|||||||
Reference in New Issue
Block a user