Skip to content

Instantly share code, notes, and snippets.

Avatar
🌶️
Focusing

Josh Beckwith positlabs

🌶️
Focusing
View GitHub Profile
@positlabs
positlabs / encode-lens-studio.sh
Last active Aug 5, 2021
Lens Studio video asset encoder. Max dimension of 1280 using H.264 / AVC / MP4
View encode-lens-studio.sh
#!/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 Jul 16, 2021
Exports all arproj files in a directory
View spark-export.sh
#!/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 Jun 23, 2021
Setting the color of an ambient light source in script
View spark-ambient-color.js
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
webm conversion for spark preview videos
View spark-webm.sh
#!/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
View spark-lut.sca
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]
View spark-batch-export.sh
#! /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 Sep 22, 2020
Lossless batch encode and resize command
View batch-resize-webm.sh
# 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
@positlabs
positlabs / framePulse.js
Created Jul 18, 2020
Spark frame pulse
View framePulse.js
const R = require('Reactive')
const Patches = require('Patches')
const Animation = require('Animation')
let frame = 0
const td = Animation.timeDriver({durationMilliseconds: 1, loopCount: Infinity, mirror: false})
td.onAfterIteration().subscribe(() => {
frame ++
Patches.inputs.setScalar('currentFrame', frame)
Patches.inputs.setPulse('frame', R.once())
@positlabs
positlabs / spark-convert-audio.sh
Last active Aug 5, 2021
FFMPEG audio conversion for Spark AR
View spark-convert-audio.sh
#! /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 / screen-plane.js
Created Jun 20, 2019
Spark AR script to resize plane to match screen size
View screen-plane.js
/*
Resize plane to match screen size
*/
const Scene = require('Scene')
const camera = Scene.root.find('Camera')
const plane = Scene.root.find('plane0')
plane.width = camera.focalPlane.width
plane.height = camera.focalPlane.height