diff --git a/lib/encode.sh b/lib/encode.sh index 05ee000..1ed1b38 100644 --- a/lib/encode.sh +++ b/lib/encode.sh @@ -236,8 +236,19 @@ setup_pgs_mkv() { IFS=x read -r supWidth supHeight <<<"${supRes}" local left top right bottom - # CROP_VALUE gets priority - if [[ ${CROP_VALUE} != '' ]]; then + # determine crop values + # 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 local res w h x y # extract ffmpeg crop value ("crop=w:h:x:y") @@ -246,23 +257,14 @@ setup_pgs_mkv() { # ffmpeg crop value # is different than supmover crop inputs - left=${x} top=${y} right=$((supWidth - w - left)) bottom=$((supHeight - h - top)) + # fallback to just the video resolution else - # determine supmover crop based off video stream - 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}")" - else - left=$(((supWidth - vidWidth) / 2)) - top=$(((supHeight - vidHeight) / 2)) - fi + left=$(((supWidth - vidWidth) / 2)) + top=$(((supHeight - vidHeight) / 2)) right=${left} bottom=${top} fi diff --git a/lib/ffmpeg.sh b/lib/ffmpeg.sh index ba1ff83..be1855a 100644 --- a/lib/ffmpeg.sh +++ b/lib/ffmpeg.sh @@ -75,12 +75,8 @@ get_crop() { # output '1920x1080' get_resolution() { local file="$1" - _ffprobe_wrapper \ - -v error \ - -select_streams v:0 \ - -show_entries stream=width,height \ - -of csv=s=x:p=0 \ - "${file}" + get_stream_json "${file}" 0 | + jq -r '.streams[0] | "\(.width)x\(.height)"' } # same as get_resolution