Files
bash-goodies/ys
T

41 lines
1.6 KiB
Bash
Raw Normal View History

2026-05-26 15:12:47 +03:00
#!/usr/bin/env bash
# YouStore: convert any set of files/dirs into a video file
2026-05-26 19:38:06 +03:00
# that can be resistant to re-encoding
# Usage: ys [e|d] [vidfile.webm] [path...] [path...]
# Dependencies: tar, zstd, truncate/wc (coreutils), xpar, openssl, ffmpeg
2026-05-26 15:12:47 +03:00
# Created by Luxferre in 2026, released into the public domain
if [[ "$1" = "e" ]]; then
OUTFILE="$2"
shift
shift
PARFILE="$(mktemp -u)"
ENCFILE="$(mktemp -u)"
2026-05-26 19:38:06 +03:00
echo "Compressing and encrypting..."
2026-05-26 15:12:47 +03:00
[[ -z "$YS_PASS" ]] && read -rs -p 'Password: ' YS_PASS
2026-05-26 19:38:06 +03:00
tar --use-compress-program='zstd -T0 -10' -cf - -- $* | \
openssl aes-256-cbc -e -pbkdf2 -out "$ENCFILE" -pass "pass:$YS_PASS"
2026-05-26 15:12:47 +03:00
echo "Adding redundancy..."
xpar -Je -i 3 -H blake2b "$ENCFILE" "$PARFILE"
2026-05-26 19:38:06 +03:00
truncate -s $(( ( $(wc -c < "$PARFILE") + 7199 ) / 7200 * 7200 )) "$PARFILE"
2026-05-26 15:12:47 +03:00
echo "Encoding video..."
2026-05-26 19:38:06 +03:00
ffmpeg -hide_banner -f rawvideo -pixel_format monob -video_size 320x180 -framerate 60 \
-i "$PARFILE" -vf "scale=1280:720:flags=neighbor,format=monob" \
-c:v libvpx-vp9 -lossless 1 -deadline realtime -speed 8 -row-mt 1 -aq-mode 0 \
-pix_fmt yuv420p -f webm "${OUTFILE}"
rm -f "$PARFILE" "$ENCFILE"
2026-05-26 15:12:47 +03:00
echo "Done!"
elif [[ "$1" = "d" ]]; then
PARFILE="$(mktemp -u)"
echo "Decoding video..."
2026-05-26 19:38:06 +03:00
ffmpeg -hide_banner -i "$2" -vf "scale=320:180:flags=neighbor,format=monob" -f rawvideo "$PARFILE"
2026-05-26 15:12:47 +03:00
echo "Restoring, decrypting and decompressing..."
[[ -z "$YS_PASS" ]] && read -rs -p 'Password: ' YS_PASS
2026-05-26 19:38:06 +03:00
xpar -Jdc "$PARFILE" | openssl aes-256-cbc -d -pbkdf2 -pass "pass:$YS_PASS" \
| tar --use-compress-program='zstd -T0' -xf -
2026-05-26 15:12:47 +03:00
rm -f "$PARFILE"
echo "Done!"
else
echo "Invalid mode! Use e or d"
fi