mirror of
https://github.com/levogevo/ffmpeg-builder.git
synced 2026-01-15 19:06:17 +00:00
only rebuild when metadata is different
This commit is contained in:
58
README.md
58
README.md
@@ -12,34 +12,36 @@ Tested on:
|
|||||||
```bash
|
```bash
|
||||||
~~~ Usable Commands ~~~
|
~~~ Usable Commands ~~~
|
||||||
|
|
||||||
print_cmds:
|
print_cmds:
|
||||||
print usable commands
|
print usable commands
|
||||||
do_build:
|
do_build:
|
||||||
build a specific project
|
build a specific project
|
||||||
build:
|
build:
|
||||||
build ffmpeg with desired configuration
|
build ffmpeg with desired configuration
|
||||||
docker_build_image:
|
docker_build_image:
|
||||||
build docker image with required dependencies pre-installed
|
build docker image with required dependencies pre-installed
|
||||||
docker_save_image:
|
docker_save_image:
|
||||||
save docker image into tar.zst
|
save docker image into tar.zst
|
||||||
docker_load_image:
|
docker_load_image:
|
||||||
load docker image from tar.zst
|
load docker image from tar.zst
|
||||||
docker_run_image:
|
docker_run_image:
|
||||||
run docker image with given flags
|
run docker image with given flags
|
||||||
build_with_docker:
|
build_with_docker:
|
||||||
run docker image with given flags
|
run docker image with given flags
|
||||||
docker_build_multiarch_image:
|
docker_build_multiarch_image:
|
||||||
build multiarch docker image
|
build multiarch docker image
|
||||||
efg:
|
efg:
|
||||||
estimate the film grain of a given file
|
estimate the film grain of a given file
|
||||||
encode:
|
encode:
|
||||||
encode a file using libsvtav1_psy and libopus
|
encode a file using libsvtav1_psy and libopus
|
||||||
print_pkg_mgr:
|
print_pkg_mgr:
|
||||||
print out evaluated package manager commands and required packages
|
print out evaluated package manager commands and required packages
|
||||||
install_deps:
|
install_deps:
|
||||||
install required dependencies
|
install required dependencies
|
||||||
gen_readme:
|
package:
|
||||||
generate project README.md
|
package ffmpeg build
|
||||||
|
gen_readme:
|
||||||
|
generate project README.md
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
104
lib/build.sh
104
lib/build.sh
@@ -3,13 +3,23 @@
|
|||||||
set_compile_opts() {
|
set_compile_opts() {
|
||||||
test "$FB_COMPILE_OPTS_SET" == 1 && return 0
|
test "$FB_COMPILE_OPTS_SET" == 1 && return 0
|
||||||
|
|
||||||
unset LDFLAGS C_FLAGS CXX_FLAGS CPP_FLAGS \
|
EXPORTED_ENV_NAMES=(
|
||||||
CONFIGURE_FLAGS MESON_FLAGS \
|
LDFLAGS
|
||||||
RUSTFLAGS CMAKE_FLAGS \
|
C_FLAGS
|
||||||
FFMPEG_EXTRA_FLAGS \
|
CXX_FLAGS
|
||||||
|
CPP_FLAGS
|
||||||
|
RUSTFLAGS
|
||||||
|
)
|
||||||
|
BUILD_ENV_NAMES=(
|
||||||
|
"${EXPORTED_ENV_NAMES[@]}"
|
||||||
|
CONFIGURE_FLAGS
|
||||||
|
MESON_FLAGS
|
||||||
|
CMAKE_FLAGS
|
||||||
|
FFMPEG_EXTRA_FLAGS
|
||||||
CARGO_CINSTALL_FLAGS
|
CARGO_CINSTALL_FLAGS
|
||||||
export LDFLAGS C_FLAGS CXX_FLAGS CPP_FLAGS \
|
)
|
||||||
RUSTFLAGS PATH
|
unset "${BUILD_ENV_NAMES[@]}"
|
||||||
|
export "${EXPORTED_ENV_NAMES[@]}"
|
||||||
|
|
||||||
# set job count for all builds
|
# set job count for all builds
|
||||||
JOBS="$(nproc)"
|
JOBS="$(nproc)"
|
||||||
@@ -373,27 +383,64 @@ do_build() {
|
|||||||
get_build_conf "${build}" || return 1
|
get_build_conf "${build}" || return 1
|
||||||
download_release || return 1
|
download_release || return 1
|
||||||
|
|
||||||
# start build
|
# save the metadata for a build to skip re-building identical builds
|
||||||
echo_info -n "building ${build} "
|
local oldMetadataFile="${TMP_DIR}/${build}-old-metadata"
|
||||||
|
local newMetadataFile="${TMP_DIR}/${build}-new-metadata"
|
||||||
|
|
||||||
|
# add build function, version, url, and top-level env to metadata
|
||||||
|
type "build_${build}" >"${oldMetadataFile}"
|
||||||
|
echo "ver: ${ver}" >>"${oldMetadataFile}"
|
||||||
|
echo "url: ${url}" >>"${oldMetadataFile}"
|
||||||
|
for envName in "${BUILD_ENV_NAMES[@]}"; do
|
||||||
|
COLOR=OFF dump_arr "${envName}" >>"${oldMetadataFile}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# only ffmpeg cares about ENABLE and has special function
|
||||||
|
if [[ ${build} == 'ffmpeg' ]]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
echo "ENABLE=${ENABLE}" >>"${oldMetadataFile}"
|
||||||
|
type add_project_versioning_to_ffmpeg >>"${oldMetadataFile}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# prepare build
|
||||||
pushd "$extracted_dir" >/dev/null || return 1
|
pushd "$extracted_dir" >/dev/null || return 1
|
||||||
# check for any patches
|
# check for any patches
|
||||||
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_if_fail patch -p1 -i "${patch}" || return 1
|
echo_if_fail patch -p1 -i "${patch}" || return 1
|
||||||
|
echo "patch:${patch}" >>"${oldMetadataFile}"
|
||||||
done
|
done
|
||||||
export LOGNAME="${build}"
|
|
||||||
local timeBefore=${EPOCHSECONDS}
|
# rebuild if metadata is different
|
||||||
echo_if_fail build_"${build}" &
|
local oldMetadata="$(<"${oldMetadataFile}")"
|
||||||
local buildPid=$!
|
local newMetadata=''
|
||||||
spinner &
|
test -f "${newMetadataFile}" && newMetadata="$(<"${newMetadataFile}")"
|
||||||
local spinPid=$!
|
if [[ ${oldMetadata} != "${newMetadata}" ]]; then
|
||||||
wait ${buildPid}
|
echo_info -n "building ${build} "
|
||||||
retval=$?
|
# build in background
|
||||||
kill ${spinPid}
|
local timeBefore=${EPOCHSECONDS}
|
||||||
spinner reset
|
LOGNAME="${build}" echo_if_fail "build_${build}" &
|
||||||
popd >/dev/null || return 1
|
local buildPid=$!
|
||||||
test ${retval} -eq 0 || return ${retval}
|
# start spinner
|
||||||
echo_pass "built ${build} in $((EPOCHSECONDS - timeBefore)) seconds"
|
spinner &
|
||||||
|
local spinPid=$!
|
||||||
|
# get build return code
|
||||||
|
wait ${buildPid}
|
||||||
|
local retval=$?
|
||||||
|
# stop spinner
|
||||||
|
kill ${spinPid}
|
||||||
|
spinner reset
|
||||||
|
|
||||||
|
popd >/dev/null || return 1
|
||||||
|
test ${retval} -eq 0 || return ${retval}
|
||||||
|
echo_pass "built ${build} in $((EPOCHSECONDS - timeBefore)) seconds"
|
||||||
|
else
|
||||||
|
popd >/dev/null || return 1
|
||||||
|
echo_info "re-using identical previous build for ${build}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# update build metadata
|
||||||
|
cp "${oldMetadataFile}" "${newMetadataFile}"
|
||||||
}
|
}
|
||||||
|
|
||||||
FB_FUNC_NAMES+=('build')
|
FB_FUNC_NAMES+=('build')
|
||||||
@@ -421,16 +468,17 @@ build() {
|
|||||||
for build in ${ENABLE}; do
|
for build in ${ENABLE}; do
|
||||||
do_build "${build}" || return 1
|
do_build "${build}" || return 1
|
||||||
done
|
done
|
||||||
do_build "ffmpeg" || return 1
|
do_build ffmpeg || return 1
|
||||||
|
local ffmpegBin="${PREFIX}/bin/ffmpeg"
|
||||||
# run ffmpeg to show completion
|
# run ffmpeg to show completion
|
||||||
"${PREFIX}/bin/ffmpeg"
|
"${ffmpegBin}" -version
|
||||||
|
|
||||||
# suggestion for path
|
# suggestion for path
|
||||||
hash -r
|
hash -r
|
||||||
local ffmpeg="$(command -v ffmpeg 2>/dev/null)"
|
local ffmpeg="$(command -v ffmpeg 2>/dev/null)"
|
||||||
if [[ ${ffmpeg} != "${PREFIX}/bin/ffmpeg" ]]; then
|
if [[ ${ffmpeg} != "${ffmpegBin}" ]]; then
|
||||||
echo
|
echo
|
||||||
echo_warn "ffmpeg in path (${ffmpeg}) is not the built one (${PREFIX}/bin/ffmpeg)"
|
echo_warn "ffmpeg in path (${ffmpeg}) is not the built one (${ffmpegBin})"
|
||||||
echo_info "consider adding ${PREFIX}/bin to \$PATH"
|
echo_info "consider adding ${PREFIX}/bin to \$PATH"
|
||||||
echo "echo 'export PATH=\"${PREFIX}/bin:\$PATH\"' >> ~/.bashrc"
|
echo "echo 'export PATH=\"${PREFIX}/bin:\$PATH\"' >> ~/.bashrc"
|
||||||
fi
|
fi
|
||||||
@@ -840,12 +888,13 @@ add_project_versioning_to_ffmpeg() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
build_ffmpeg() {
|
build_ffmpeg() {
|
||||||
|
add_project_versioning_to_ffmpeg || return 1
|
||||||
|
|
||||||
|
# libsvtav1_psy real name is libsvtav1
|
||||||
for enable in ${ENABLE}; do
|
for enable in ${ENABLE}; do
|
||||||
test "${enable}" == 'libsvtav1_psy' && enable='libsvtav1'
|
test "${enable}" == 'libsvtav1_psy' && enable='libsvtav1'
|
||||||
CONFIGURE_FLAGS+=("--enable-${enable}")
|
CONFIGURE_FLAGS+=("--enable-${enable}")
|
||||||
done
|
done
|
||||||
add_project_versioning_to_ffmpeg || return 1
|
|
||||||
|
|
||||||
# lto is broken on darwin for ffmpeg only
|
# lto is broken on darwin for ffmpeg only
|
||||||
# https://trac.ffmpeg.org/ticket/11479
|
# https://trac.ffmpeg.org/ticket/11479
|
||||||
local ffmpegFlags=()
|
local ffmpegFlags=()
|
||||||
@@ -870,6 +919,7 @@ build_ffmpeg() {
|
|||||||
--disable-txtpages \
|
--disable-txtpages \
|
||||||
--disable-ffplay \
|
--disable-ffplay \
|
||||||
--disable-autodetect \
|
--disable-autodetect \
|
||||||
|
--extra-version="${ver}" \
|
||||||
--enable-runtime-cpudetect || return 1
|
--enable-runtime-cpudetect || return 1
|
||||||
ccache make -j"${JOBS}" || return 1
|
ccache make -j"${JOBS}" || return 1
|
||||||
${SUDO_MODIFY} make -j"${JOBS}" install || return 1
|
${SUDO_MODIFY} make -j"${JOBS}" install || return 1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ $(printf ' - %s\n' "${VALID_DOCKER_IMAGES[@]}")
|
|||||||
- darwin aarch64
|
- darwin aarch64
|
||||||
|
|
||||||
\`\`\`bash
|
\`\`\`bash
|
||||||
$(print_cmds false)
|
$(COLOR=OFF print_cmds)
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
" >"${readme}"
|
" >"${readme}"
|
||||||
|
|||||||
17
lib/utils.sh
17
lib/utils.sh
@@ -16,7 +16,16 @@ echo_wrapper() {
|
|||||||
args=("$1")
|
args=("$1")
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
echo -e "${args[@]}" "${color}${word}${NC}" "$@"
|
# COLOR is override for using ${color}
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
if [[ ${COLOR} == 'OFF' ]]; then
|
||||||
|
color=''
|
||||||
|
endColor=''
|
||||||
|
else
|
||||||
|
endColor="${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${args[@]}" "${color}${word:-''}${endColor}" "$@"
|
||||||
}
|
}
|
||||||
echo_fail() { color="${RED}" word="FAIL" echo_wrapper "$@"; }
|
echo_fail() { color="${RED}" word="FAIL" echo_wrapper "$@"; }
|
||||||
echo_info() { color="${CYAN}" word="INFO" echo_wrapper "$@"; }
|
echo_info() { color="${CYAN}" word="INFO" echo_wrapper "$@"; }
|
||||||
@@ -31,11 +40,11 @@ void() { echo "$@" >/dev/null; }
|
|||||||
echo_if_fail() {
|
echo_if_fail() {
|
||||||
local cmd=("$@")
|
local cmd=("$@")
|
||||||
local logName="${LOGNAME:-${RANDOM}}-"
|
local logName="${LOGNAME:-${RANDOM}}-"
|
||||||
local out="${TMP_DIR}/.${logName}stdout"
|
local out="${TMP_DIR}/${logName}stdout"
|
||||||
local err="${TMP_DIR}/.${logName}stderr"
|
local err="${TMP_DIR}/${logName}stderr"
|
||||||
|
|
||||||
# set trace to the cmdEvalTrace and open file descriptor
|
# set trace to the cmdEvalTrace and open file descriptor
|
||||||
local cmdEvalTrace="${TMP_DIR}/.${logName}cmdEvalTrace"
|
local cmdEvalTrace="${TMP_DIR}/${logName}cmdEvalTrace"
|
||||||
test -d "${TMP_DIR}" || mkdir -p "${TMP_DIR}"
|
test -d "${TMP_DIR}" || mkdir -p "${TMP_DIR}"
|
||||||
exec 5>"${cmdEvalTrace}"
|
exec 5>"${cmdEvalTrace}"
|
||||||
export BASH_XTRACEFD=5
|
export BASH_XTRACEFD=5
|
||||||
|
|||||||
10
main.sh
10
main.sh
@@ -55,17 +55,9 @@ $cmd "$@"' >"${ENTRY_SCRIPT}"
|
|||||||
FB_FUNC_NAMES+=('print_cmds')
|
FB_FUNC_NAMES+=('print_cmds')
|
||||||
FB_FUNC_DESCS['print_cmds']='print usable commands'
|
FB_FUNC_DESCS['print_cmds']='print usable commands'
|
||||||
print_cmds() {
|
print_cmds() {
|
||||||
local color="${1:-true}"
|
|
||||||
local uncolor=''
|
|
||||||
if [[ ${color} == true ]]; then
|
|
||||||
color="${CYAN}"
|
|
||||||
uncolor="${NC}"
|
|
||||||
else
|
|
||||||
color=''
|
|
||||||
fi
|
|
||||||
echo -e "~~~ Usable Commands ~~~\n"
|
echo -e "~~~ Usable Commands ~~~\n"
|
||||||
for funcname in "${FB_FUNC_NAMES[@]}"; do
|
for funcname in "${FB_FUNC_NAMES[@]}"; do
|
||||||
echo -e "${color}${funcname}${uncolor}:\n\t" "${FB_FUNC_DESCS[${funcname}]}"
|
color="${CYAN}" word="${funcname}:" echo_wrapper "\n\t${FB_FUNC_DESCS[${funcname}]}"
|
||||||
if [[ $FB_RUNNING_AS_SCRIPT -eq 0 ]]; then
|
if [[ $FB_RUNNING_AS_SCRIPT -eq 0 ]]; then
|
||||||
(cd "$SCRIPT_DIR" && ln -sf entry.sh "${funcname}.sh")
|
(cd "$SCRIPT_DIR" && ln -sf entry.sh "${funcname}.sh")
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user