Skip to content

Instantly share code, notes, and snippets.

@slaskis
Created September 18, 2015 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaskis/4a80ce2343b001ee3327 to your computer and use it in GitHub Desktop.
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
#!/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()));
});
#!/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