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:
Feross Aboukhadijeh
2016-09-16 10:14:39 -07:00
parent fa67f9b82b
commit bcd6a38a05
4 changed files with 4 additions and 40 deletions

View File

@@ -18,6 +18,7 @@
"application-config": "^1.0.0",
"auto-launch": "^4.0.1",
"bitfield": "^1.0.2",
"capture-frame": "^1.0.0",
"chromecasts": "^1.8.0",
"create-torrent": "^3.24.5",
"deep-equal": "^1.0.1",

View File

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

View File

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

View File

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