Compare commits

...

4 Commits

6 changed files with 125 additions and 86 deletions

View File

@@ -24,7 +24,7 @@ Configuration is done through environment variables.
By default, this project will build a static `ffmpeg` binary in `./gitignore/sysroot/bin/ffmpeg`. By default, this project will build a static `ffmpeg` binary in `./gitignore/sysroot/bin/ffmpeg`.
The user-overridable compile options are: The user-overridable compile options are:
- `ENABLE`: configure what ffmpeg enables (default: libaom libass libvpx libxml2 libvmaf libx264 libx265 libwebp libopus librav1e libdav1d libvorbis libmp3lame libfribidi libfreetype libharfbuzz libopenjpeg libsvtav1_psy libfontconfig ) - `ENABLE`: configure what ffmpeg enables (default: libaom libass libvpx libxml2 libvmaf libx264 libx265 libwebp libopus librav1e libdav1d libvorbis libmp3lame libfribidi libfreetype libharfbuzz libopenjpeg libsvtav1_hdr libfontconfig )
- `PREFIX`: prefix to install to, default is local install in ./gitignore/sysroot (default: local) - `PREFIX`: prefix to install to, default is local install in ./gitignore/sysroot (default: local)
- `STATIC`: static or shared build (default: ON) - `STATIC`: static or shared build (default: ON)
- `LTO`: enable link time optimization (default: ON) - `LTO`: enable link time optimization (default: ON)

View File

@@ -324,6 +324,7 @@ fi' >"${compilerDir}/which"
get_build_conf() { get_build_conf() {
local getBuild="${1}" local getBuild="${1}"
local getBuildValue="${2:-}"
local longestBuild=0 local longestBuild=0
local longestVer=0 local longestVer=0
@@ -335,12 +336,13 @@ get_build_conf() {
local BUILDS_CONF=' local BUILDS_CONF='
ffmpeg 8.0.1 tar.gz https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n${ver}.${ext} ffmpeg 8.0.1 tar.gz https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n${ver}.${ext}
libsvtav1_hdr 4.0.1 tar.gz https://github.com/juliobbv-p/svt-av1-hdr/archive/refs/tags/v${ver}.${ext} dovi_tool,hdr10plus_tool,cpuinfo
libsvtav1_psy 3.0.2-B tar.gz https://github.com/BlueSwordM/svt-av1-psyex/archive/refs/tags/v${ver}.${ext} dovi_tool,hdr10plus_tool,cpuinfo libsvtav1_psy 3.0.2-B tar.gz https://github.com/BlueSwordM/svt-av1-psyex/archive/refs/tags/v${ver}.${ext} dovi_tool,hdr10plus_tool,cpuinfo
hdr10plus_tool 1.7.2 tar.gz https://github.com/quietvoid/hdr10plus_tool/archive/refs/tags/${ver}.${ext} hdr10plus_tool 1.7.2 tar.gz https://github.com/quietvoid/hdr10plus_tool/archive/refs/tags/${ver}.${ext}
dovi_tool 2.3.1 tar.gz https://github.com/quietvoid/dovi_tool/archive/refs/tags/${ver}.${ext} dovi_tool 2.3.1 tar.gz https://github.com/quietvoid/dovi_tool/archive/refs/tags/${ver}.${ext}
cpuinfo latest git https://github.com/pytorch/cpuinfo/ cpuinfo latest git https://github.com/pytorch/cpuinfo/
libsvtav1 3.1.2 tar.gz https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v${ver}/SVT-AV1-v${ver}.${ext} libsvtav1 4.0.1 tar.gz https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v${ver}/SVT-AV1-v${ver}.${ext}
librav1e 0.8.1 tar.gz https://github.com/xiph/rav1e/archive/refs/tags/v${ver}.${ext} librav1e 0.8.1 tar.gz https://github.com/xiph/rav1e/archive/refs/tags/v${ver}.${ext}
libaom 3.13.1 tar.gz https://storage.googleapis.com/aom-releases/libaom-${ver}.${ext} libaom 3.13.1 tar.gz https://storage.googleapis.com/aom-releases/libaom-${ver}.${ext}
libvmaf 3.0.0 tar.gz https://github.com/Netflix/vmaf/archive/refs/tags/v${ver}.${ext} libvmaf 3.0.0 tar.gz https://github.com/Netflix/vmaf/archive/refs/tags/v${ver}.${ext}
@@ -454,6 +456,11 @@ supmover 2.4.3 tar.gz https://github.com/MonoS/SupMover/archi
extractedDir="${BUILD_DIR}/${build}-v${ver}" extractedDir="${BUILD_DIR}/${build}-v${ver}"
fi fi
if [[ -n ${getBuildValue} ]]; then
declare -n value=${getBuildValue}
echo "${value}"
fi
return 0 return 0
} }
@@ -514,7 +521,7 @@ download_release() {
else else
# for git downloads # for git downloads
test -d "${download}" || test -d "${download}" ||
git clone --recursive "${url}" "${download}" || return 1 git clone --depth 1 --recursive "${url}" "${download}" || return 1
( (
cd "${download}" || exit 1 cd "${download}" || exit 1
local localHEAD remoteHEAD local localHEAD remoteHEAD
@@ -605,7 +612,7 @@ do_build() {
echo "LOCAL_PREFIX: ${LOCAL_PREFIX}" echo "LOCAL_PREFIX: ${LOCAL_PREFIX}"
for patch in "${PATCHES_DIR}/${build}"/*.patch; do for patch in "${PATCHES_DIR}/${build}"/*.patch; do
test -f "${patch}" || continue test -f "${patch}" || continue
echo -e "patch:${patch}\n$(<"${patch}")" >>"${newMetadataFile}" echo -e "patch:${patch}\n$(<"${patch}")"
done done
COLOR=OFF SHOW_SINGLE=true dump_arr "${BUILD_ENV_NAMES[@]}" COLOR=OFF SHOW_SINGLE=true dump_arr "${BUILD_ENV_NAMES[@]}"
} >"${newMetadataFile}" } >"${newMetadataFile}"
@@ -839,19 +846,21 @@ build_cpuinfo() {
sanitize_sysroot_libs libcpuinfo || return 1 sanitize_sysroot_libs libcpuinfo || return 1
} }
build_libsvtav1() { build_libsvtav1_hdr() {
meta_cmake_build \ build_libsvtav1_psy
-DENABLE_AVX512=ON \
-DCOVERAGE=OFF || return 1
sanitize_sysroot_libs libSvtAv1Enc || return 1
} }
build_libsvtav1_psy() { build_libsvtav1_psy() {
meta_cmake_build \ build_libsvtav1 \
-DENABLE_AVX512=ON \
-DCOVERAGE=OFF \
-DLIBDOVI_FOUND=1 \ -DLIBDOVI_FOUND=1 \
-DLIBHDR10PLUS_RS_FOUND=1 || return 1 -DLIBHDR10PLUS_RS_FOUND=1
}
build_libsvtav1() {
meta_cmake_build \
-DSVT_AV1_LTO=OFF \
-DENABLE_AVX512=ON \
-DCOVERAGE=OFF "$@" || return 1
sanitize_sysroot_libs libSvtAv1Enc || return 1 sanitize_sysroot_libs libSvtAv1Enc || return 1
} }
@@ -985,6 +994,13 @@ build_cmake3() (
return 0 return 0
fi fi
if is_android; then
CMAKE_FLAGS+=(
"-DCMAKE_USE_SYSTEM_LIBUV=ON"
"-DCMAKE_USE_SYSTEM_LIBARCHIVE=ON"
)
fi
CMAKE_FLAGS+=( CMAKE_FLAGS+=(
"-DCMAKE_PREFIX_PATH=${LOCAL_PREFIX}" "-DCMAKE_PREFIX_PATH=${LOCAL_PREFIX}"
"-DCMAKE_INSTALL_PREFIX=${LOCAL_PREFIX}" "-DCMAKE_INSTALL_PREFIX=${LOCAL_PREFIX}"
@@ -1261,14 +1277,11 @@ add_project_versioning_to_ffmpeg() {
'' # pad with empty line '' # pad with empty line
"ffmpeg-builder=$(git -C "${REPO_DIR}" rev-parse HEAD)" "ffmpeg-builder=$(git -C "${REPO_DIR}" rev-parse HEAD)"
) )
for build in ${ENABLE}; do for build in ${ENABLE} ffmpeg; do
get_build_conf "${build}" || return 1 get_build_conf "${build}" || return 1
# add build configuration info # add build configuration info
FFMPEG_BUILDER_INFO+=("${build}=${ver}") FFMPEG_BUILDER_INFO+=("${build}=${ver}")
done done
# and finally for ffmpeg itself
get_build_conf ffmpeg || return 1
FFMPEG_BUILDER_INFO+=("${build}=${ver}")
local fname='opt_common.c' local fname='opt_common.c'
local optFile="fftools/${fname}" local optFile="fftools/${fname}"
@@ -1286,9 +1299,18 @@ add_project_versioning_to_ffmpeg() {
build_ffmpeg() { build_ffmpeg() {
add_project_versioning_to_ffmpeg || return 1 add_project_versioning_to_ffmpeg || return 1
# libsvtav1_psy real name is libsvtav1 # libsvtav1_* patch and enable name change
for enable in ${ENABLE}; do for enable in ${ENABLE}; do
test "${enable}" == 'libsvtav1_psy' && enable='libsvtav1' if line_starts_with "${enable}" libsvtav1; then
# libsvtav1 v4 is breaking API
if [[ "$(get_build_conf "${enable}" ver)" == '4'* ]]; then
replace_line \
libavcodec/libsvtav1.c \
'param->enable_adaptive_quantization = 0;' \
'param->aq_mode = 0;' || return 1
fi
enable=libsvtav1
fi
CONFIGURE_FLAGS+=("--enable-${enable}") CONFIGURE_FLAGS+=("--enable-${enable}")
done done

View File

@@ -48,7 +48,7 @@ libfribidi \
libfreetype \ libfreetype \
libharfbuzz \ libharfbuzz \
libopenjpeg \ libopenjpeg \
libsvtav1_psy \ libsvtav1_hdr \
libfontconfig \ libfontconfig \
" "

View File

@@ -198,6 +198,46 @@ replace_mkv_sup() {
"${mergeCmd[@]}" "${mergeCmd[@]}"
} }
crop_sup() {
local inSup="$1"
local outSup="$2"
local left="$3"
local top="$4"
local right="$5"
local bottom="$6"
local warnMsg='Window is outside new screen area'
local maxAcceptableWarn=5
local offset=5
# skip cropping if not needed
if [[ "${left}${top}${right}${bottom}" == "0000" ]]; then
cp "${inSup}" "${outSup}" || return 1
return 0
fi
for ((try = 0; try < 30; try++)); do
echo_info "cropping sup with ${left} ${top} ${right} ${bottom}"
"${SUPMOVER}" \
"${inSup}" \
"${outSup}" \
--crop \
"${left}" "${top}" "${right}" "${bottom}" &>"${outSup}.out" || return 1
# supmover does not error for out-of-bounds subtitles
# so adjust crop value until there is most certainly no issue
if [[ "$(grep -c "${warnMsg}" "${cropSup}.out")" -gt ${maxAcceptableWarn} ]]; then
echo_warn "${warnMsg}, retrying... (try ${try})"
test "${left}" -gt ${offset} && left=$((left - offset))
test "${top}" -gt ${offset} && top=$((top - offset))
test "${right}" -gt ${offset} && right=$((right - offset))
test "${bottom}" -gt ${offset} && bottom=$((bottom - offset))
else
return 0
fi
done
# if we got here, all tries were had, so indicate failure
return 1
}
# extract PGS_SUB_STREAMS from INPUT # extract PGS_SUB_STREAMS from INPUT
# and crop using CROP_VALUE # and crop using CROP_VALUE
setup_pgs_mkv() { setup_pgs_mkv() {
@@ -226,68 +266,48 @@ setup_pgs_mkv() {
cropMkv="${tmpdir}/${stream}.mkv" cropMkv="${tmpdir}/${stream}.mkv"
mkvextract "${INPUT}" tracks "${stream}:${ogSup}" || return 1 mkvextract "${INPUT}" tracks "${stream}:${ogSup}" || return 1
# check if PGS was uncropped # check sup resolution
local supRes local supRes
supRes="$(get_sup_resolution "${ogSup}")" || return 1 supRes="$(get_sup_resolution "${ogSup}")" || return 1
# crop PGS if either initially cropping or "fixing" local supWidth supHeight
# previously uncropped (relative to video) PGS subs IFS=x read -r supWidth supHeight <<<"${supRes}"
if [[ ${CROP_VALUE} != '' || ${supRes} != "${vidRes}" ]]; then local left top right bottom
local supWidth supHeight # determine crop values
IFS=x read -r supWidth supHeight <<<"${supRes}" # if the supfile is smaller than the video stream
local left top right bottom # crop using aspect ratio instead of resolution
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")
IFS='=' read -r _ res <<<"${CROP_VALUE}"
IFS=':' read -r w h x y <<<"${res}"
# CROP_VALUE gets priority # ffmpeg crop value
if [[ ${CROP_VALUE} != '' ]]; then # is different than supmover crop inputs
# determine supmover crop based off of crop left=${x}
local res w h x y top=${y}
# extract ffmpeg crop value ("crop=w:h:x:y") right=$((supWidth - w - left))
IFS='=' read -r _ res <<<"${CROP_VALUE}" bottom=$((supHeight - h - top))
IFS=':' read -r w h x y <<<"${res}" # fallback to just the video resolution
# ffmpeg crop value
# is different than supmover crop inputs
left=${x}
top=${y}
right=$((supWidth - w - left))
bottom=$((supHeight - h - top))
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
right=${left}
bottom=${top}
fi
# crop sup
(
set -x
"${SUPMOVER}" \
"${ogSup}" \
"${cropSup}" \
--crop \
"${left}" "${top}" "${right}" "${bottom}" &>"${cropSup}.out" || return 1
)
local cropRet=$?
# supmover does not error for out-of-bounds subtitles
if grep 'Window is outside new screen area' "${cropSup}.out"; then
echo_fail "check ${cropSup}.out for complete logs"
cropRet=1
fi
if [[ ${cropRet} -ne 0 ]]; then
rm -r "${tmpdir}" || return 1
return 1
fi
else else
# create placeholder copy for replacement left=$(((supWidth - vidWidth) / 2))
cp "${ogSup}" "${cropSup}" || return 1 top=$(((supHeight - vidHeight) / 2))
right=${left}
bottom=${top}
fi
if ! crop_sup "${ogSup}" "${cropSup}" "${left}" "${top}" "${right}" "${bottom}"; then
rm -r "${tmpdir}" || return 1
return 1
fi fi
if ! replace_mkv_sup "${INPUT}" "${cropSup}" "${cropMkv}" "${stream}"; then if ! replace_mkv_sup "${INPUT}" "${cropSup}" "${cropMkv}" "${stream}"; then
@@ -397,7 +417,7 @@ set_encode_opts() {
encode_usage encode_usage
return 1 return 1
fi fi
GRAIN="film-grain=${OPTARG}:film-grain-denoise=1:" GRAIN="film-grain=${OPTARG}:film-grain-denoise=1:adaptive-film-grain=1:"
optsUsed=$((optsUsed + 2)) optsUsed=$((optsUsed + 2))
;; ;;
P) P)
@@ -531,7 +551,7 @@ gen_encode_script() {
local "${arrays[@]}" local "${arrays[@]}"
local videoParams=( local videoParams=(
"-crf" '${CRF}' "-preset" '${PRESET}' "-g" "240" "-crf" '${CRF}' "-preset" '${PRESET}'
) )
local ffmpegParams=( local ffmpegParams=(
'-hide_banner' '-hide_banner'

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

View File

@@ -98,6 +98,7 @@ print_req_pkgs() {
libandroid-posix-semaphore-static libandroid-posix-semaphore-static
libandroid-shmem libandroid-shmem
libandroid-shmem-static libandroid-shmem-static
cargo-c
) )
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local msys_ucrt_pkgs=( local msys_ucrt_pkgs=(