mirror of
https://github.com/levogevo/ffmpeg-builder.git
synced 2026-03-16 19:20:11 +00:00
Compare commits
4 Commits
f1b2a0d534
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 852d7e3795 | |||
| 18815854f5 | |||
| 5261b67a18 | |||
| c2be0112fb |
@@ -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`.
|
||||
|
||||
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)
|
||||
- `STATIC`: static or shared build (default: ON)
|
||||
- `LTO`: enable link time optimization (default: ON)
|
||||
|
||||
58
lib/build.sh
58
lib/build.sh
@@ -324,6 +324,7 @@ fi' >"${compilerDir}/which"
|
||||
|
||||
get_build_conf() {
|
||||
local getBuild="${1}"
|
||||
local getBuildValue="${2:-}"
|
||||
|
||||
local longestBuild=0
|
||||
local longestVer=0
|
||||
@@ -335,12 +336,13 @@ get_build_conf() {
|
||||
local BUILDS_CONF='
|
||||
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
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
@@ -454,6 +456,11 @@ supmover 2.4.3 tar.gz https://github.com/MonoS/SupMover/archi
|
||||
extractedDir="${BUILD_DIR}/${build}-v${ver}"
|
||||
fi
|
||||
|
||||
if [[ -n ${getBuildValue} ]]; then
|
||||
declare -n value=${getBuildValue}
|
||||
echo "${value}"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -514,7 +521,7 @@ download_release() {
|
||||
else
|
||||
# for git downloads
|
||||
test -d "${download}" ||
|
||||
git clone --recursive "${url}" "${download}" || return 1
|
||||
git clone --depth 1 --recursive "${url}" "${download}" || return 1
|
||||
(
|
||||
cd "${download}" || exit 1
|
||||
local localHEAD remoteHEAD
|
||||
@@ -605,7 +612,7 @@ do_build() {
|
||||
echo "LOCAL_PREFIX: ${LOCAL_PREFIX}"
|
||||
for patch in "${PATCHES_DIR}/${build}"/*.patch; do
|
||||
test -f "${patch}" || continue
|
||||
echo -e "patch:${patch}\n$(<"${patch}")" >>"${newMetadataFile}"
|
||||
echo -e "patch:${patch}\n$(<"${patch}")"
|
||||
done
|
||||
COLOR=OFF SHOW_SINGLE=true dump_arr "${BUILD_ENV_NAMES[@]}"
|
||||
} >"${newMetadataFile}"
|
||||
@@ -839,19 +846,21 @@ build_cpuinfo() {
|
||||
sanitize_sysroot_libs libcpuinfo || return 1
|
||||
}
|
||||
|
||||
build_libsvtav1() {
|
||||
meta_cmake_build \
|
||||
-DENABLE_AVX512=ON \
|
||||
-DCOVERAGE=OFF || return 1
|
||||
sanitize_sysroot_libs libSvtAv1Enc || return 1
|
||||
build_libsvtav1_hdr() {
|
||||
build_libsvtav1_psy
|
||||
}
|
||||
|
||||
build_libsvtav1_psy() {
|
||||
meta_cmake_build \
|
||||
-DENABLE_AVX512=ON \
|
||||
-DCOVERAGE=OFF \
|
||||
build_libsvtav1 \
|
||||
-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
|
||||
}
|
||||
|
||||
@@ -985,6 +994,13 @@ build_cmake3() (
|
||||
return 0
|
||||
fi
|
||||
|
||||
if is_android; then
|
||||
CMAKE_FLAGS+=(
|
||||
"-DCMAKE_USE_SYSTEM_LIBUV=ON"
|
||||
"-DCMAKE_USE_SYSTEM_LIBARCHIVE=ON"
|
||||
)
|
||||
fi
|
||||
|
||||
CMAKE_FLAGS+=(
|
||||
"-DCMAKE_PREFIX_PATH=${LOCAL_PREFIX}"
|
||||
"-DCMAKE_INSTALL_PREFIX=${LOCAL_PREFIX}"
|
||||
@@ -1261,14 +1277,11 @@ add_project_versioning_to_ffmpeg() {
|
||||
'' # pad with empty line
|
||||
"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
|
||||
# add build configuration info
|
||||
FFMPEG_BUILDER_INFO+=("${build}=${ver}")
|
||||
done
|
||||
# and finally for ffmpeg itself
|
||||
get_build_conf ffmpeg || return 1
|
||||
FFMPEG_BUILDER_INFO+=("${build}=${ver}")
|
||||
|
||||
local fname='opt_common.c'
|
||||
local optFile="fftools/${fname}"
|
||||
@@ -1286,9 +1299,18 @@ add_project_versioning_to_ffmpeg() {
|
||||
build_ffmpeg() {
|
||||
add_project_versioning_to_ffmpeg || return 1
|
||||
|
||||
# libsvtav1_psy real name is libsvtav1
|
||||
# libsvtav1_* patch and enable name change
|
||||
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}")
|
||||
done
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ libfribidi \
|
||||
libfreetype \
|
||||
libharfbuzz \
|
||||
libopenjpeg \
|
||||
libsvtav1_psy \
|
||||
libsvtav1_hdr \
|
||||
libfontconfig \
|
||||
"
|
||||
|
||||
|
||||
140
lib/encode.sh
140
lib/encode.sh
@@ -198,6 +198,46 @@ replace_mkv_sup() {
|
||||
"${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
|
||||
# and crop using CROP_VALUE
|
||||
setup_pgs_mkv() {
|
||||
@@ -226,68 +266,48 @@ setup_pgs_mkv() {
|
||||
cropMkv="${tmpdir}/${stream}.mkv"
|
||||
mkvextract "${INPUT}" tracks "${stream}:${ogSup}" || return 1
|
||||
|
||||
# check if PGS was uncropped
|
||||
# check sup resolution
|
||||
local supRes
|
||||
supRes="$(get_sup_resolution "${ogSup}")" || return 1
|
||||
# crop PGS if either initially cropping or "fixing"
|
||||
# previously uncropped (relative to video) PGS subs
|
||||
if [[ ${CROP_VALUE} != '' || ${supRes} != "${vidRes}" ]]; then
|
||||
local supWidth supHeight
|
||||
IFS=x read -r supWidth supHeight <<<"${supRes}"
|
||||
local left top right bottom
|
||||
local supWidth supHeight
|
||||
IFS=x read -r supWidth supHeight <<<"${supRes}"
|
||||
local left top right bottom
|
||||
# determine crop values
|
||||
# if the supfile is smaller than the video stream
|
||||
# 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
|
||||
if [[ ${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}"
|
||||
|
||||
# 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
|
||||
# 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
|
||||
# create placeholder copy for replacement
|
||||
cp "${ogSup}" "${cropSup}" || return 1
|
||||
left=$(((supWidth - vidWidth) / 2))
|
||||
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
|
||||
|
||||
if ! replace_mkv_sup "${INPUT}" "${cropSup}" "${cropMkv}" "${stream}"; then
|
||||
@@ -397,7 +417,7 @@ set_encode_opts() {
|
||||
encode_usage
|
||||
return 1
|
||||
fi
|
||||
GRAIN="film-grain=${OPTARG}:film-grain-denoise=1:"
|
||||
GRAIN="film-grain=${OPTARG}:film-grain-denoise=1:adaptive-film-grain=1:"
|
||||
optsUsed=$((optsUsed + 2))
|
||||
;;
|
||||
P)
|
||||
@@ -531,7 +551,7 @@ gen_encode_script() {
|
||||
local "${arrays[@]}"
|
||||
|
||||
local videoParams=(
|
||||
"-crf" '${CRF}' "-preset" '${PRESET}' "-g" "240"
|
||||
"-crf" '${CRF}' "-preset" '${PRESET}'
|
||||
)
|
||||
local ffmpegParams=(
|
||||
'-hide_banner'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -98,6 +98,7 @@ print_req_pkgs() {
|
||||
libandroid-posix-semaphore-static
|
||||
libandroid-shmem
|
||||
libandroid-shmem-static
|
||||
cargo-c
|
||||
)
|
||||
# shellcheck disable=SC2034
|
||||
local msys_ucrt_pkgs=(
|
||||
|
||||
Reference in New Issue
Block a user