fix when crop + smaller pgs

This commit is contained in:
2026-03-05 15:15:57 -06:00
parent c2be0112fb
commit 5261b67a18
2 changed files with 18 additions and 20 deletions

View File

@@ -236,8 +236,19 @@ setup_pgs_mkv() {
IFS=x read -r supWidth supHeight <<<"${supRes}" IFS=x read -r supWidth supHeight <<<"${supRes}"
local left top right bottom local left top right bottom
# CROP_VALUE gets priority # determine crop values
if [[ ${CROP_VALUE} != '' ]]; then # if the supfile is smaller than the video stream
# crop using aspect ratio
if [[ ${vidWidth} -gt ${supWidth} || ${vidHeight} -gt ${supHeight} ]]; then
echo_warn "PGS sup (stream=${stream}) is somehow smaller than initial video stream"
echo_warn "cropping based off of aspect ratio instead of resolution"
left=0
# (supHeight - ((vidHeight/vidWidth) * supWidth)) / 2
top="$(awk '{ print int(($1 - ($2 / $3 * $4)) / 2) }' <<<"${supHeight} ${vidHeight} ${vidWidth} ${supWidth}")"
right=${left}
bottom=${top}
# otherwise crop using the crop value
elif [[ ${CROP_VALUE} != '' ]]; then
# determine supmover crop based off of crop # determine supmover crop based off of crop
local res w h x y local res w h x y
# extract ffmpeg crop value ("crop=w:h:x:y") # extract ffmpeg crop value ("crop=w:h:x:y")
@@ -246,23 +257,14 @@ setup_pgs_mkv() {
# ffmpeg crop value # ffmpeg crop value
# is different than supmover crop inputs # is different than supmover crop inputs
left=${x} left=${x}
top=${y} top=${y}
right=$((supWidth - w - left)) right=$((supWidth - w - left))
bottom=$((supHeight - h - top)) bottom=$((supHeight - h - top))
# fallback to just the video resolution
else else
# determine supmover crop based off video stream left=$(((supWidth - vidWidth) / 2))
if [[ ${vidWidth} -gt ${supWidth} || ${vidHeight} -gt ${supHeight} ]]; then top=$(((supHeight - vidHeight) / 2))
echo_warn "PGS sup (stream=${stream}) is somehow smaller than initial video stream"
echo_warn "cropping based off of aspect ratio instead of resolution"
left=0
# (supHeight - ((vidHeight/vidWidth) * supWidth)) / 2
top="$(awk '{ print int(($1 - ($2 / $3 * $4)) / 2) }' <<<"${supHeight} ${vidHeight} ${vidWidth} ${supWidth}")"
else
left=$(((supWidth - vidWidth) / 2))
top=$(((supHeight - vidHeight) / 2))
fi
right=${left} right=${left}
bottom=${top} bottom=${top}
fi fi

View File

@@ -75,12 +75,8 @@ get_crop() {
# output '1920x1080' # output '1920x1080'
get_resolution() { get_resolution() {
local file="$1" local file="$1"
_ffprobe_wrapper \ get_stream_json "${file}" 0 |
-v error \ jq -r '.streams[0] | "\(.width)x\(.height)"'
-select_streams v:0 \
-show_entries stream=width,height \
-of csv=s=x:p=0 \
"${file}"
} }
# same as get_resolution # same as get_resolution