aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtranscode.sh42
1 files changed, 31 insertions, 11 deletions
diff --git a/transcode.sh b/transcode.sh
index 436c89f..ae53b5f 100755
--- a/transcode.sh
+++ b/transcode.sh
@@ -607,22 +607,30 @@ trap cleanup EXIT
# Encode a single media file according to PRESET_NAME.
#
+# Arguments:
+# $1 - path to the file to encode
+# $2 - current index (1-based, for progress display)
+# $3 - total file count (for progress display)
+#
# Steps:
-# 1) Probe input codec and pixel format (v:0).
+# 1) Probe input codec and pixel format (v:0) in a single ffprobe call.
# 2) Optionally skip based on codec.
# 3) Normalize pixel formats (handle yuvj* forms).
-# 4) Select an output pixel format that preserverse chroma subsampling/bit depth.
-# 5) Load preset ffargs and run ffmpeg into a temp file in the same directory.
-# 6) Optionally keep only-if-smaller; optionally log savings; then replace.
+# 4) Select an output pixel format that preserves chroma subsampling/bit depth.
+# 5) Load preset ffargs.
+# 6) Run ffmpeg into a temp file in the same directory.
+# 7) Optionally keep only-if-smaller; optionally log savings; then replace.
#
# Return:
# EXIT_OK on success or if skipped; EXIT_RUNTIME_FAILURE on failure.
encode_one() {
local file="$1"
+ local idx="$2"
+ local total="$3"
[[ -z "$file" ]] && return $EXIT_OK
- msg "Processing:" "$file"
+ msg "Processing [$idx/$total]:" "$file"
[[ ! -f "$file" ]] && {
error "Not found:" "$file"
return $EXIT_RUNTIME_FAILURE
@@ -693,7 +701,11 @@ encode_one() {
local ffargs=()
load_preset "$PRESET_NAME" ffargs
- local extension filename directory tmp base stem
+ local extension directory tmp base stem
+ # filename (path without extension) is used only for the savings log.
+ # Note: only the last extension is stripped, so multi-dot names like
+ # "my.show.s01e01.mkv" are logged as "my.show.s01e01".
+ local filename
base="${file##*/}"
if [[ "$base" == *.* ]]; then
@@ -791,12 +803,20 @@ if [[ -n $ENCODE_FILE ]]; then
error "Encode file not found:" "$ENCODE_FILE"
exit $EXIT_USAGE_ERROR
}
- while IFS= read -r file || [[ -n "$file" ]]; do
- encode_one "$file" || STATUS=$EXIT_RUNTIME_FAILURE
- done <"$ENCODE_FILE"
+ # Build the file list into an array first so we know the total count.
+ mapfile -t FILES_TO_ENCODE < <(
+ while IFS= read -r file || [[ -n "$file" ]]; do
+ [[ -n "$file" ]] && printf '%s\n' "$file"
+ done <"$ENCODE_FILE"
+ )
+ total=${#FILES_TO_ENCODE[@]}
+ for ((i = 0; i < total; i++)); do
+ encode_one "${FILES_TO_ENCODE[i]}" "$((i + 1))" "$total" || STATUS=$EXIT_RUNTIME_FAILURE
+ done
else
- for file in "${REMAINING_ARGS[@]}"; do
- encode_one "$file" || STATUS=$EXIT_RUNTIME_FAILURE
+ total=${#REMAINING_ARGS[@]}
+ for ((i = 0; i < total; i++)); do
+ encode_one "${REMAINING_ARGS[i]}" "$((i + 1))" "$total" || STATUS=$EXIT_RUNTIME_FAILURE
done
fi