Created
September 18, 2015 09:13
-
-
Save slaskis/4a80ce2343b001ee3327 to your computer and use it in GitHub Desktop.
Extract pixel info at a certain position in frames every second-ish in a video stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* eslint-env node */ | |
'use strict'; | |
var fs = require('fs'); | |
var path = require('path'); | |
var Canvas = require('canvas'); | |
var Image = Canvas.Image; | |
var canvas = new Canvas(720, 406); | |
var ctx = canvas.getContext('2d'); | |
function extractPixel(file, x, y, fn) { | |
fs.readFile(file, function(err, buffer){ | |
if (err) { | |
throw err; | |
} | |
var img = new Image(); | |
img.src = buffer; | |
ctx.drawImage(img, 0, 0); | |
var px = ctx.getImageData(x, y, 1, 1); | |
fn(px.data[0], px.data[1], px.data[2], px.data[3]); | |
}); | |
} | |
var file = path.resolve(__dirname, './foo.jpeg'); | |
fs.watchFile(file, {interval: 20}, function () { | |
extractPixel(file, 1, 1, console.log.bind(console, '%s rgba(%s, %s, %s, %s)', new Date())); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ffmpeg -i rtmp://fms.12E5.edgecastcdn.net/0012E5/mp4:videos/8Juv1MVa-485.mp4 -r 1 -f image2 -updatefirst 1 -y foo.jpeg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment