Skip to content

Instantly share code, notes, and snippets.

View positlabs's full-sized avatar
🌶️
Focusing

Josh Beckwith positlabs

🌶️
Focusing
View GitHub Profile
@positlabs
positlabs / time-lapse.sh
Created November 1, 2013 20:41
gphoto2 bash script for taking time-lapse photo sets
echo "attempting to kill all PTPCamera processes..."
# releases camera from the OS so we can use it
killall PTPCamera
gphoto2 \
--folder "time-lapse" \
--capture-image-and-download \
--set-config "/main/imgsettings/imageformat=5" \
--filename "frames/"%Y%m%d%H%M%S.%C \
@positlabs
positlabs / spark-convert-audio.sh
Last active August 5, 2021 20:20
FFMPEG audio conversion for Spark AR
#! /bin/bash
# This command converts audio according to the specifications listed in the Spark docs:
# https://sparkar.facebook.com/ar-studio/learn/documentation/docs/audio
# mono m4a, 44.1kHz sample rate, 16-bit-depth resolution
# Usage:
# convert-audio.sh myaudio.mp3 converted.m4a
# Notes:
# Always use m4a for output file type
# Change "64k" to a higher value to improve bitrate/quality. e.g. 96k 128k 192k
@positlabs
positlabs / encode-lens-studio.sh
Last active August 5, 2021 19:33
Lens Studio video asset encoder. Max dimension of 1280 using H.264 / AVC / MP4
#!/bin/bash
# Lens Studio video asset encoder. Max dimension of 1280 using H.264 / AVC / MP4
# https://lensstudio.snapchat.com/guides/2d/video/
# USAGE: ./encode-lens-studio.sh myvideo.mov
ffmpeg -i $1 \
-vf "scale='if(gt(iw, ih), min(1280, iw-mod(iw, 16)), -16)':'ifnot(gt(iw, ih), min(1280, ih-mod(ih, 16)), -16)'" \
-c:v libx264 \
-crf 23 \
-preset veryslow \
-c:a copy \
@positlabs
positlabs / spark-export.sh
Created July 16, 2021 19:15
Exports all arproj files in a directory
#!/bin/bash
for project in **/*.arproj;
do /Applications/Spark\ AR\ Studio.app/Contents/MacOS/sparkTerminalAppleMac export $project;
done;
@positlabs
positlabs / spark-ambient-color.js
Created June 23, 2021 15:10
Setting the color of an ambient light source in script
const Scene = require('Scene')
const {log} = require('Diagnostics')
const {RGBA} = require('Reactive')
;(async function () {
const light = await Scene.root.findFirst('ambientLight0')
log(light)
light.color = new RGBA(1, 1, 179/255, 1)
@positlabs
positlabs / spark-webm.sh
Created May 27, 2021 19:25
webm conversion for spark preview videos
#!/bin/bash
# https://trac.ffmpeg.org/wiki/Encode/VP9
# Converts video file to webm using two-pass encoding
# Installation on Mac: add script to /usr/local/bin
# Usage:
# webm ./path/to/video.mp4
# Outputs ./path/to/video.mp4.webm
# Max size is 720 pixels wide. Change -vf scale to adjust
vec4 getLutColor(vec2 rg, float sliceNo, std::Texture2d colorLutTex, vec2 gridSize) {
vec2 pixelSize = 1.0 / colorLutTex.size;
vec2 scale = 1.0 / gridSize;
float row = floor(sliceNo * scale.x);
float col = sliceNo - row * gridSize.x; // mod(sliceNo, gridSize.x);
vec2 colorLutCoords = (vec2(col, row) + rg) * scale;
// offset by 0.5 pixel and fit within range [0.5px, width-0.5px]
@positlabs
positlabs / Vignette.js
Created March 21, 2013 19:47
A simple canvas vignette
Vignette = function (canvas) {
var alpha = .7,
context,
visible,
data;
(function initView() {
context = canvas.getContext("2d");
#! /bin/bash
# export all arproj found in sub directories. e.g. you want to export several projects in one folder
for i in */*.arproj
do
echo "============================"
/Applications/Spark\ AR\ Studio/Spark\ AR\ Studio.app/Contents/MacOS/sparkTerminalAppleMac export "$i" -d ./
echo "============================"
done
@positlabs
positlabs / batch-resize-webm.sh
Last active September 22, 2020 19:12
Lossless batch encode and resize command
# Batch encode webm files in a directory
for i in *.webm;
do
ffmpeg -y -i $i -b:v 0 -crf 30 -pass 1 -an -f webm /dev/null
ffmpeg -y -i $i -vf scale=640:640:force_original_aspect_ratio=decrease -b:v 0 -crf 30 -pass 2 "_${i}"
done