aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtranscode.sh80
1 files changed, 37 insertions, 43 deletions
diff --git a/transcode.sh b/transcode.sh
index 6b0bb22..436c89f 100755
--- a/transcode.sh
+++ b/transcode.sh
@@ -632,25 +632,31 @@ encode_one() {
return $EXIT_RUNTIME_FAILURE
}
- local input_codec
- input_codec=$(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nk=1:nw=1 "file:$file" 2>/dev/null)
+ # Probe codec and pixel format in a single ffprobe invocation to halve
+ # the startup overhead on large batches.
+ local probe_out
+ probe_out=$(ffprobe -v error -select_streams v:0 \
+ -show_entries stream=codec_name,pix_fmt \
+ -of default=nk=1:nw=1 "file:$file" 2>/dev/null)
+
+ local input_codec input_pixel_format
+ input_codec=$(printf '%s\n' "$probe_out" | sed -n '1p')
+ input_pixel_format=$(printf '%s\n' "$probe_out" | sed -n '2p')
+
if [[ -z "$input_codec" ]]; then
- error "Could not determine input video codec"
+ error "Could not determine input video codec:" "$file"
+ return $EXIT_RUNTIME_FAILURE
+ fi
+ if [[ -z "$input_pixel_format" ]]; then
+ error "Could not determine input pixel format:" "$file"
return $EXIT_RUNTIME_FAILURE
fi
if [[ -v SKIP_CODECS["$input_codec"] ]]; then
- msg "Skip because of input codec:" "$input_codec"
+ msg "Skipping (codec excluded):" "$input_codec"
return $EXIT_OK
fi
- local input_pixel_format
- input_pixel_format=$(ffprobe -v error -select_streams v:0 -show_entries stream=pix_fmt -of default=nk=1:nw=1 "file:$file" 2>/dev/null)
- if [[ -z "$input_pixel_format" ]]; then
- error "Could not determine input pixel format"
- return $EXIT_RUNTIME_FAILURE
- fi
-
# Some files report "yuvj*" formats (full-range JPEG-style). For encoding
# purposes we normalize to the equivalent "yuv*" formats.
input_pixel_format="${input_pixel_format/yuvj/yuv}"
@@ -660,38 +666,26 @@ encode_one() {
# to avoid unintended quality loss or incompatible output.
# Known limitation: exotic formats not matching these patterns (e.g. gbrp,
# yuva*, gray*) fall through to yuv420p. Extend the logic below if needed.
- local output_pixel_format
- if [[ "$input_pixel_format" == *"444"* ]]; then
- if [[ "$input_pixel_format" == *"16"* ]]; then
- output_pixel_format="yuv444p16le"
- elif [[ "$input_pixel_format" == *"12"* ]]; then
- output_pixel_format="yuv444p12le"
- elif [[ "$input_pixel_format" == *"10"* ]]; then
- output_pixel_format="yuv444p10le"
- else
- output_pixel_format="yuv444p"
- fi
- elif [[ "$input_pixel_format" == *"422"* ]]; then
- if [[ "$input_pixel_format" == *"16"* ]]; then
- output_pixel_format="yuv422p16le"
- elif [[ "$input_pixel_format" == *"12"* ]]; then
- output_pixel_format="yuv422p12le"
- elif [[ "$input_pixel_format" == *"10"* ]]; then
- output_pixel_format="yuv422p10le"
- else
- output_pixel_format="yuv422p"
- fi
- else
- if [[ "$input_pixel_format" == *"16"* ]]; then
- output_pixel_format="yuv420p16le"
- elif [[ "$input_pixel_format" == *"12"* ]]; then
- output_pixel_format="yuv420p12le"
- elif [[ "$input_pixel_format" == *"10"* ]]; then
- output_pixel_format="yuv420p10le"
- else
- output_pixel_format="yuv420p"
- fi
- fi
+ local subsampling depth output_pixel_format
+
+ case "$input_pixel_format" in
+ *444*) subsampling="444" ;;
+ *422*) subsampling="422" ;;
+ *)
+ subsampling="420"
+ [[ "$input_pixel_format" != *420* ]] &&
+ verbose "Unrecognised chroma subsampling in '$input_pixel_format', falling back to yuv420p"
+ ;;
+ esac
+
+ case "$input_pixel_format" in
+ *16*) depth="p16le" ;;
+ *12*) depth="p12le" ;;
+ *10*) depth="p10le" ;;
+ *) depth="p" ;;
+ esac
+
+ output_pixel_format="yuv${subsampling}${depth}"
debug "Selected output pixel format:" "$output_pixel_format"
# Load preset early so a missing/invalid preset fails before we create a