Skip to content

Instantly share code, notes, and snippets.

@gre
Last active August 17, 2017 10:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gre/11219793 to your computer and use it in GitHub Desktop.
Save gre/11219793 to your computer and use it in GitHub Desktop.
[MacOSX] Minimal script for timelapse capturing your screen
#!/bin/bash
# Minimal script for timelapse capturing your screen in MacOSX.
# You must run the script, from an empty directory where the images will be stored.
# Usage: ./timelapse
# or
# Usage: ./timelapse <seconds>
# Default capture every 10 seconds, which is about 10 minutes of 30fps video for a 48 hours record.
# On a Retina Macbook Pro, it will needs about 15 Go of images for 48 hours of images.
# See: https://docs.google.com/spreadsheets/d/1qFeF0cZi19mMjwj-SO5qsuAp3MET0bKBM79JBx69nWI
TIME_BETWEEN_CAPTURES=${1-10}
while ((1)); do
sleep $TIME_BETWEEN_CAPTURES
screencapture -x -t jpg "$(date '+%Y-%m-%d@%Hh%Mm%S').jpg"
done
# Gaëtan Renaudeau - DWTFYW License http://www.wtfpl.net/
@gre
Copy link
Author

gre commented Apr 25, 2014

for generating the video, please come back here in 3 days :-)
I'm going to do it after the ludumdare,
anyway, it is super trivial with ffmpeg

@gre
Copy link
Author

gre commented Apr 30, 2014

@gre
Copy link
Author

gre commented Aug 3, 2017

usage with create-react-app or inside whatever script that runs a server:

fork this script:

timelapseInterval=30
trap 'kill $tlpid; exit' SIGINT
mkdir -p timelapse
hours=$(bc -l <<< "scale=1;`ls -l timelapse | wc -l` / (3600/$timelapseInterval)")
echo "${hours} hours of timelapse!"
cd timelapse
timelapse 30 &
tlpid=$!
cd ..
react-scripts start

@gre
Copy link
Author

gre commented Aug 17, 2017

script to dedup the snapshot that are too close in time interval

const limit = 30 * 1000;

const fs = require("fs");
const path = require("path");
const dir = path.join(__dirname, "./timelapse");

const all = fs
  .readdirSync(dir)
  .map(file => {
    const date = new Date(
      file.replace(/[@]/g, " ").replace(/[hm]/g, ":").replace(/[.]jpg$/g, "")
    );
    return { file, date, millis: date.getTime() };
  })
  .sort((a, b) => a.millis - b.millis)
  .reduce(
    ([prevDateTime, coll], item) => {
      const diff = item.millis - prevDateTime;
      if (!isNaN(diff) && diff < limit) {
        return [prevDateTime, coll.concat(item)];
      } else {
        return [item.millis, coll];
      }
    },
    [0, []]
  )[1]
  .map(item => item.file);

if (all.length > 0) {
  console.log(all.map(file => path.join(dir, file)).join("\n"));
}

example: node timelapse-dedup.js | while read f; do echo mv $f dups; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment