Skip to content

Instantly share code, notes, and snippets.

View rileyjshaw's full-sized avatar
💭
Riley is typing…

Riley Shaw rileyjshaw

💭
Riley is typing…
View GitHub Profile
@rileyjshaw
rileyjshaw / prepare-video-for-web.sh
Created December 15, 2022 17:50
Prepare a video file for the web
# Source: https://evilmartians.com/chronicles/better-web-video-with-av1-codec
# Encode as H.264. Reduce quality by increasing the CRF value. If you're looking for an output that is roughly "visually lossless" but not technically lossless, use a -crf value of around 17 or 18.
ffmpeg -i <SOURCE> -map_metadata -1 -c:a libfdk_aac -c:v libx264 -crf 28 -preset veryslow -profile:v main -pix_fmt yuv420p -movflags +faststart -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.h264.mp4
# Encode as AV1. Reduce quality by increasing the CP value.
ffmpeg -i <SOURCE> -map_metadata -1 -c:a libopus -c:v librav1e -qp 80 -tile-columns 2 -tile-rows 2 -pix_fmt yuv420p -movflags +faststart -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.av1.mp4
# Encode as HEVC. Reduce quality by increasing the CRF value.
ffmpeg -i <SOURCE> -map_metadata -1 -c:a libfdk_aac -c:v libx265 -crf 28 -preset veryslow -pix_fmt yuv420p -movflags +faststart -tag:v hvc1 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.hevc.mp4
@rileyjshaw
rileyjshaw / concat-with-titles.sh
Last active October 30, 2023 13:37
I have a folder with every Fabriclive set split into individual files. This creates a merged track for each set, with the title spoken at the start of the track.
#!bin/bash
for d in */; do
cd "$d"
title=$(echo "$d" | sed 's/\./ /' | sed 's/ \[.*//g')
echo "$title" | sed 's/FABRICLIVE/Fabric lyve/' | sed -r 's/\(([0-9]+)\)/in \1/g' | sed -r 's/ 0+([1-9][0-9]*)/ \1/g' | say -v Serena -o "00. Title.aiff"
ffmpeg -i "00. Title.aiff" -acodec libmp3lame -ab 192000 -ar 44100 -ac 2 "00. Title.mp3"
command ls -1 *.mp3 | sed s/\'/\'\\\\\'\'/g | awk '$0="file \047"$0"\047"' >> tracklist.txt
ffmpeg -f concat -safe 0 -i tracklist.txt -c copy "../../Merged with titles/$title.mp3"
rm "00. Title.aiff"
rm "00. Title.mp3"
@rileyjshaw
rileyjshaw / format-openswim.sh
Last active April 19, 2024 21:53
Run this from a local folder containing whatever you want to go on the Shokz OpenSwim
#!/bin/bash
# Shokz OpenSwim headphones (formerly AfterShokz Xtrainerz) have a bug where
# tracks are not played in alphabetical or track order. They are played in the
# order that they were copied to the device. Read more about the issue here:
#
# - https://en.help.shokz.com/s/article/How-to-list-the-track-order-on-OpenSwim-formerly-Xtrainerz-OPENSWIM1408
# - https://en.help.shokz.com/s/get-article?urlName=how-to-list-tracks-order-EN
#
# After extensive testing, it seems that specifying transmission order alone is
@rileyjshaw
rileyjshaw / add-track-numbers.sh
Last active July 27, 2022 14:28
Adds ID3v1 and ID3v2 track information to a folder of mp3s, based on the output order of `ls`.
#!/bin/bash
FILES=(*.mp3)
for i in "${!FILES[@]}"; do
id3v2 -T "$((i + 1))/${#FILES[@]}" "${FILES[i]}"
done
@rileyjshaw
rileyjshaw / mp3titles.sh
Created July 27, 2022 14:16
MacOS: Enter all subdirectories of the current folder and add "00. Title.mp3", which reads the folder name.
#!/bin/bash
for d in */; do
cd "$d"
say "$d" -o "00. Title.aiff"
lame -m m "00. Title.aiff" "00. Title.mp3"
rm "00. Title.aiff"
cd ..
done
@rileyjshaw
rileyjshaw / mp3numbers.sh
Created July 26, 2022 14:17
Generate a series of MP3s on MacOS. Filenames are left-padded with 0s.
#!/bin/bash
for i in {001..100}; do
say ${i##+(0)} -o "$i.aiff"
lame -m m "$i.aiff" "$i.mp3"
rm "$i.aiff"
done
@rileyjshaw
rileyjshaw / renumber.sh
Created February 1, 2022 16:23
Rename files to `01.ext`, `02.ext`, etc. based on output order of `ls`
#!/bin/bash
FILES=($(ls -tUr *.{png,jpeg}))
for i in "${!FILES[@]}"; do
mv "${FILES[i]}" "$(printf "%02d.${FILES[i]##*.}" "$((i + 1))")"
done
@rileyjshaw
rileyjshaw / download.sh
Created January 3, 2022 05:17
Download a collection of PDFs from the Internet Archive
#!/bin/bash
# Dependency: https://archive.org/services/docs/api/internetarchive/cli.html
# Usage example: ./download.sh byte-magazine
ia search "collection:$1" --itemlist | parallel 'ia download {} --glob="*.pdf"'
@rileyjshaw
rileyjshaw / make_woffs.sh
Created May 3, 2021 02:32
A one-liner to convert a folder of TTFs (also works with OTFs) to WOFF and WOFF2
mkdir -p woff && for f in *.ttf; do sfnt2woff "$f"; woff2_compress "$f"; done && mv *.woff* woff
@rileyjshaw
rileyjshaw / bracket-parse.js
Created April 20, 2021 02:11
Parse a string with [[enclosed [[nested]] double bracket pairs]]. I used this for https://github.com/rileyjshaw/font-comparison-tool.
/**
* Parse takes a string and returns a nested array. The array nests
* to a deeper level for each [[enclosed double bracket pair]].
*
* eg:
*
* // Output: ['It goes ', ['deeper and ', ['deeper.']]]
* parse('It goes [[deeper and [[deeper.]]]]');
*/
function parse(str, startIdx = 0, isChild = false) {