From d2f97fa70bd0f8ca6b0bcf16106204a2a771c8fb Mon Sep 17 00:00:00 2001 From: rootless Date: Sat, 12 Aug 2023 23:20:50 +0300 Subject: [PATCH] initial --- random-screenshots.sh | 28 +++++++++++++++ strip-video-metadata.sh | 23 ++++++++++++ to-frames.sh | 10 ++++++ total-duration.sh | 35 ++++++++++++++++++ webdlrip.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100755 random-screenshots.sh create mode 100755 strip-video-metadata.sh create mode 100755 to-frames.sh create mode 100755 total-duration.sh create mode 100755 webdlrip.sh diff --git a/random-screenshots.sh b/random-screenshots.sh new file mode 100755 index 0000000..097084e --- /dev/null +++ b/random-screenshots.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +PROGNAME="$0" + +set -e +#set -x + +usage() { + echo "usage: $PROGNAME FILENAME NUMBER" + exit +} + +get_duration() { + ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1" | awk '{print int($1+0.5)}' +} + +[ $# -lt 2 ] && usage + +file="$1" +left="$2" + +duration=$(get_duration "$file") +#echo "duration: $duration" + +for n in $(seq 1 $left); do + time=$(shuf -i 1-$duration -n 1) + ffmpeg -y -nostats -loglevel error -ss $time -i "$file" -frames:v 1 -q:v 2 "${file}_$n.jpg" &2 echo "error: $1: no such file" + exit 1 + fi + shift +done + +echo "$total seconds" + +days=$(( total / 86400 )) +if [ $days -gt 0 ]; then + echo -n "${days}d " +fi + +human="$(date -d@$total -u +%H:%M:%S)" +echo "$human" diff --git a/webdlrip.sh b/webdlrip.sh new file mode 100755 index 0000000..7561a41 --- /dev/null +++ b/webdlrip.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +set -e +#set -x + +die() { + >&2 echo "error: $@" + exit 1 +} + +usage() { + >&2 echo "usage: $0 [OPTIONS] FILENAME" + >&2 echo + >&2 echo "options:" + >&2 echo " -h|--height set video height, default is 720" + >&2 echo " -265 encode with H.265" + >&2 echo + exit 1 +} + +do_webdlrip() { + filename="$(basename -- "$FILE")" + filename="${filename%.*}" + + newname="$filename.mp4" + + audio_params="-c:a aac -b:a 128k" + if [ "$HEVC" = "1" ]; then + video_params="-c:v libx265 -crf 27 -preset slow -vtag hvc1 -x265-params no-info=1" + else + video_params="-c:v libx264 -preset slow -crf 23 -bsf:v 'filter_units=remove_types=6'" + fi + + ffmpeg -i "$FILE" -vf scale=-1:$HEIGHT,format=yuv420p \ + -map_metadata -1 -map_chapters -1 \ + -fflags +bitexact -flags:v +bitexact -flags:a +bitexact \ + -metadata:s handler_name='' \ + -metadata:s DURATION='' \ + -metadata:s VENDOR_ID='' \ + -metadata:s encoder='' \ + -empty_hdlr_name 1 \ + $video_params $audio_params \ + -vf sidedata=delete,metadata=delete \ + "webdlrip_$newname" + rm "$FILE" + mv "webdlrip_$newname" "$FILE" +} + +[ -z "$1" ] && usage + +FILE= +HEIGHT=720 + +while [ $# -gt 0 ]; do + case $1 in + -h|--height) + HEIGHT="$2" + shift + ;; + -265) + HEVC=1 + ;; + *) + [ -n "$FILE" ] && die "unexpected argument: $1" + FILE="$1" + ;; + esac + shift +done + +[ -z "$FILE" ] && usage +[ -f "$FILE" ] || die "$FILE: file not found" + +echo "filename: $FILE" +echo " height: $HEIGHT" +echo + +do_webdlrip