some ys optimizations
This commit is contained in:
@@ -1,43 +1,38 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# YouStore: convert any set of files/dirs into a video file
|
# YouStore: convert any set of files/dirs into a video file
|
||||||
# that's also (somewhat) resistant to re-encoding
|
# that can be resistant to re-encoding
|
||||||
# Usage: ys [e|d] [vidfile] [path...] [path...]
|
# Usage: ys [e|d] [vidfile.webm] [path...] [path...]
|
||||||
# Dependencies: tar, zstd, truncate (coreutils), xpar, openssl, ffmpeg
|
# Dependencies: tar, zstd, truncate/wc (coreutils), xpar, openssl, ffmpeg
|
||||||
# Created by Luxferre in 2026, released into the public domain
|
# Created by Luxferre in 2026, released into the public domain
|
||||||
|
|
||||||
BASEW=320 # base frame width
|
|
||||||
BASEH=180 # base frame height
|
|
||||||
SCL=4 # frame scale factor
|
|
||||||
FR=60 # frame rate in the output video
|
|
||||||
CODEC_PARAMS='-c:v libvpx-vp9 -lossless 1 -deadline realtime -speed 8 -row-mt 1 -aq-mode 0 -pix_fmt yuv420p -f webm'
|
|
||||||
|
|
||||||
BPF=$(( BASEW * BASEH / 8 )) # bytes per frame
|
|
||||||
if [[ "$1" = "e" ]]; then
|
if [[ "$1" = "e" ]]; then
|
||||||
OUTFILE="$2"
|
OUTFILE="$2"
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
ARCHFILE="$(mktemp -u)"
|
|
||||||
PARFILE="$(mktemp -u)"
|
PARFILE="$(mktemp -u)"
|
||||||
ENCFILE="$(mktemp -u)"
|
ENCFILE="$(mktemp -u)"
|
||||||
echo "Compressing..."
|
echo "Compressing and encrypting..."
|
||||||
tar --use-compress-program='zstd -19' -cf "$ARCHFILE" -- $*
|
|
||||||
echo "Encrypting..."
|
|
||||||
[[ -z "$YS_PASS" ]] && read -rs -p 'Password: ' YS_PASS
|
[[ -z "$YS_PASS" ]] && read -rs -p 'Password: ' YS_PASS
|
||||||
openssl aes-256-cbc -e -pbkdf2 -in "$ARCHFILE" -out "$ENCFILE" -pass "pass:$YS_PASS"
|
tar --use-compress-program='zstd -T0 -10' -cf - -- $* | \
|
||||||
|
openssl aes-256-cbc -e -pbkdf2 -out "$ENCFILE" -pass "pass:$YS_PASS"
|
||||||
echo "Adding redundancy..."
|
echo "Adding redundancy..."
|
||||||
xpar -Je -i 3 -H blake2b "$ENCFILE" "$PARFILE"
|
xpar -Je -i 3 -H blake2b "$ENCFILE" "$PARFILE"
|
||||||
truncate -s $(( ( $(stat -c%s "$PARFILE") + BPF - 1 ) / BPF * BPF )) "$PARFILE"
|
truncate -s $(( ( $(wc -c < "$PARFILE") + 7199 ) / 7200 * 7200 )) "$PARFILE"
|
||||||
echo "Encoding video..."
|
echo "Encoding video..."
|
||||||
ffmpeg -hide_banner -f rawvideo -pixel_format monob -video_size ${BASEW}x${BASEH} -framerate $FR -i "$PARFILE" -vf "scale=iw*${SCL}:ih*${SCL}:flags=neighbor,format=monob" $CODEC_PARAMS "${OUTFILE}.webm"
|
ffmpeg -hide_banner -f rawvideo -pixel_format monob -video_size 320x180 -framerate 60 \
|
||||||
rm -f "$ARCHFILE" "$PARFILE" "$ENCFILE"
|
-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"
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
elif [[ "$1" = "d" ]]; then
|
elif [[ "$1" = "d" ]]; then
|
||||||
PARFILE="$(mktemp -u)"
|
PARFILE="$(mktemp -u)"
|
||||||
echo "Decoding video..."
|
echo "Decoding video..."
|
||||||
ffmpeg -hide_banner -i "$2" -vf "scale=${BASEW}:${BASEH}:flags=neighbor,format=monob" -f rawvideo "$PARFILE"
|
ffmpeg -hide_banner -i "$2" -vf "scale=320:180:flags=neighbor,format=monob" -f rawvideo "$PARFILE"
|
||||||
echo "Restoring, decrypting and decompressing..."
|
echo "Restoring, decrypting and decompressing..."
|
||||||
[[ -z "$YS_PASS" ]] && read -rs -p 'Password: ' YS_PASS
|
[[ -z "$YS_PASS" ]] && read -rs -p 'Password: ' YS_PASS
|
||||||
xpar -Jdc "$PARFILE" | openssl aes-256-cbc -d -pbkdf2 -pass "pass:$YS_PASS" | tar --use-compress-program='zstd' -xf -
|
xpar -Jdc "$PARFILE" | openssl aes-256-cbc -d -pbkdf2 -pass "pass:$YS_PASS" \
|
||||||
|
| tar --use-compress-program='zstd -T0' -xf -
|
||||||
rm -f "$PARFILE"
|
rm -f "$PARFILE"
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user