mirror of
https://gitlab.com/dabruh/dotfiles.git
synced 2025-12-09 19:56:26 +01:00
Compare commits
2 commits
b87863f375
...
b1b8ce749b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1b8ce749b | ||
|
|
530c9307d4 |
1 changed files with 189 additions and 135 deletions
|
|
@ -44,6 +44,7 @@ OVERWRITE_DIFFERENT=false
|
||||||
IS_BATCH=false
|
IS_BATCH=false
|
||||||
INPUT_DIR=""
|
INPUT_DIR=""
|
||||||
INPUT_FILES=()
|
INPUT_FILES=()
|
||||||
|
AUDIO_MODE="transcode"
|
||||||
|
|
||||||
# Prints usage information to stdout.
|
# Prints usage information to stdout.
|
||||||
usage() {
|
usage() {
|
||||||
|
|
@ -62,6 +63,7 @@ Usage: $(basename "$0") -i input.mp4 [options]
|
||||||
--max-h Maximum height in pixels (default: ${DEFAULT_MAX_H})
|
--max-h Maximum height in pixels (default: ${DEFAULT_MAX_H})
|
||||||
--overwrite-same Overwrite output even if duration matches input
|
--overwrite-same Overwrite output even if duration matches input
|
||||||
--overwrite-different Overwrite output even if duration differs from input
|
--overwrite-different Overwrite output even if duration differs from input
|
||||||
|
--audio-mode Audio mode: transcode (default) or copy
|
||||||
-h, --help Show this help
|
-h, --help Show this help
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
@ -75,20 +77,67 @@ parse_args() {
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-i|--input) INFILE="$2"; shift 2 ;;
|
-i | --input)
|
||||||
-o|--output) OUTFILE="$2"; shift 2 ;;
|
INFILE="$2"
|
||||||
-c|--crf) CRF="$2"; shift 2 ;;
|
shift 2
|
||||||
-p|--preset) PRESET="$2"; shift 2 ;;
|
;;
|
||||||
-m|--maxrate) MAXRATE="$2"; shift 2 ;;
|
-o | --output)
|
||||||
-b|--bufsize) BUFSIZE="$2"; shift 2 ;;
|
OUTFILE="$2"
|
||||||
--extra) EXTRA_ARGS+=("$2"); shift 2 ;;
|
shift 2
|
||||||
--max-w) MAX_W="$2"; shift 2 ;;
|
;;
|
||||||
--max-h) MAX_H="$2"; shift 2 ;;
|
-c | --crf)
|
||||||
--overwrite-same) OVERWRITE_SAME=true; shift ;;
|
CRF="$2"
|
||||||
--overwrite-different) OVERWRITE_DIFFERENT=true; shift ;;
|
shift 2
|
||||||
-h|--help) usage; exit 0 ;;
|
;;
|
||||||
--) shift; break ;;
|
-p | --preset)
|
||||||
*) echo "Unknown argument: $1" >&2; usage; exit 1 ;;
|
PRESET="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-m | --maxrate)
|
||||||
|
MAXRATE="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-b | --bufsize)
|
||||||
|
BUFSIZE="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--extra)
|
||||||
|
EXTRA_ARGS+=("$2")
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--max-w)
|
||||||
|
MAX_W="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--max-h)
|
||||||
|
MAX_H="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--overwrite-same)
|
||||||
|
OVERWRITE_SAME=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--overwrite-different)
|
||||||
|
OVERWRITE_DIFFERENT=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--audio-mode)
|
||||||
|
AUDIO_MODE="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-h | --help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown argument: $1" >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
@ -148,8 +197,13 @@ validate_input_single() {
|
||||||
|
|
||||||
# Assembles the full ffmpeg command array with all configured options.
|
# Assembles the full ffmpeg command array with all configured options.
|
||||||
build_ffmpeg_cmd() {
|
build_ffmpeg_cmd() {
|
||||||
# Sets audio flags to copy streams unchanged for fidelity.
|
# Sets audio flags to transcode to Opus or copy streams unchanged.
|
||||||
local audio_flags=("-c:a" "copy")
|
local audio_flags
|
||||||
|
if [[ "$AUDIO_MODE" == "transcode" ]]; then
|
||||||
|
audio_flags=("-c:a" "libopus")
|
||||||
|
else
|
||||||
|
audio_flags=("-c:a" "copy")
|
||||||
|
fi
|
||||||
|
|
||||||
# Constructs the ffmpeg video scaling filter to fit within max dimensions while preserving aspect ratio.
|
# Constructs the ffmpeg video scaling filter to fit within max dimensions while preserving aspect ratio.
|
||||||
# Scale logic: for landscape (w>h), constrain width to MAX_W and height to MAX_H;
|
# Scale logic: for landscape (w>h), constrain width to MAX_W and height to MAX_H;
|
||||||
|
|
@ -162,7 +216,7 @@ build_ffmpeg_cmd() {
|
||||||
# Safely append user-provided extra arguments by splitting on whitespace.
|
# Safely append user-provided extra arguments by splitting on whitespace.
|
||||||
if [[ ${#EXTRA_ARGS[@]} -gt 0 ]]; then
|
if [[ ${#EXTRA_ARGS[@]} -gt 0 ]]; then
|
||||||
for ea in "${EXTRA_ARGS[@]}"; do
|
for ea in "${EXTRA_ARGS[@]}"; do
|
||||||
read -r -a split <<< "$ea"
|
read -r -a split <<<"$ea"
|
||||||
CMD+=("${split[@]}")
|
CMD+=("${split[@]}")
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue