mirror of
https://github.com/levogevo/ffmpeg-builder.git
synced 2026-01-16 11:26:17 +00:00
Compare commits
56 Commits
7cd3f03417
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 38c160e2bd | |||
| 47e287ef7f | |||
| 691d0f857a | |||
| 3c3fc6164c | |||
| 1adcaa15a4 | |||
| 108561a002 | |||
| ff1b0c2304 | |||
| ff656d477f | |||
| 7ce42985e2 | |||
| 8feeccc46a | |||
| 87f65e48f4 | |||
| 200d4c4a6c | |||
| 71c7266661 | |||
| 69ada12884 | |||
| 30ddc39ed5 | |||
| 25093463af | |||
| 2356e05ad5 | |||
| 7419027a80 | |||
| 71a35d1320 | |||
| cf27104939 | |||
| fac5951fc9 | |||
| ff7921c45d | |||
| 65fb35877e | |||
| ad5b8e4482 | |||
| e6ab74c351 | |||
| 1b8c411458 | |||
| 5c9e97e0a2 | |||
| 687a8473b5 | |||
| c07b52f5c2 | |||
| e1d5595b06 | |||
| c7c855a35a | |||
| 1b03235761 | |||
| 0b35c8b94a | |||
| c038798d2c | |||
| 23d05a8c3a | |||
| c399c008ba | |||
| dd07038ab7 | |||
| 675fdec278 | |||
| 9f018d9036 | |||
| 2c675e70be | |||
| 31ae0e49ae | |||
| de86c8c27f | |||
| 9596f68a9e | |||
| aa4d7e61f1 | |||
| 609ddea197 | |||
| 5ed906017a | |||
| 8d10c5f94b | |||
| 96ec4b6566 | |||
| 636c6a0ff8 | |||
| 000bdb24a0 | |||
| afc4ca05cb | |||
| 4065cff08c | |||
| 2550ba56d9 | |||
| 81a2cde5c7 | |||
| 8a5ed69f86 | |||
| 014448ac55 |
20
Jenkinsfile
vendored
20
Jenkinsfile
vendored
@@ -13,7 +13,9 @@ def withDockerCreds(body) {
|
|||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent none
|
agent none
|
||||||
environment { DEBUG = "1" }
|
environment {
|
||||||
|
DEBUG = "1"
|
||||||
|
}
|
||||||
options { buildDiscarder logRotator(numToKeepStr: '4') }
|
options { buildDiscarder logRotator(numToKeepStr: '4') }
|
||||||
stages {
|
stages {
|
||||||
stage('build docker image') {
|
stage('build docker image') {
|
||||||
@@ -36,14 +38,16 @@ pipeline {
|
|||||||
stage('build ffmpeg on darwin') {
|
stage('build ffmpeg on darwin') {
|
||||||
matrix {
|
matrix {
|
||||||
axes {
|
axes {
|
||||||
axis { name 'OPT_LTO'; values 'OPT=0 LTO=OFF', 'OPT=3 LTO=ON' }
|
axis {
|
||||||
axis { name 'STATIC'; values 'ON', 'OFF' }
|
name 'COMP_OPTS';
|
||||||
|
values 'OPT=0 LTO=OFF STATIC=OFF', 'OPT=2 LTO=OFF STATIC=ON', 'OPT=3 LTO=ON STATIC=ON PGO=ON'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('build on darwin ') {
|
stage('build on darwin ') {
|
||||||
agent { label "darwin" }
|
agent { label "darwin" }
|
||||||
steps {
|
steps {
|
||||||
sh "${OPT_LTO} ./scripts/build.sh"
|
sh "${COMP_OPTS} ./scripts/build.sh"
|
||||||
archiveArtifacts allowEmptyArchive: true, artifacts: 'gitignore/package/*.tar.xz', defaultExcludes: false
|
archiveArtifacts allowEmptyArchive: true, artifacts: 'gitignore/package/*.tar.xz', defaultExcludes: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,15 +59,17 @@ pipeline {
|
|||||||
axes {
|
axes {
|
||||||
axis { name 'ARCH'; values 'armv8-a', 'x86-64-v3' }
|
axis { name 'ARCH'; values 'armv8-a', 'x86-64-v3' }
|
||||||
axis { name 'DISTRO'; values 'ubuntu', 'fedora', 'debian', 'archlinux' }
|
axis { name 'DISTRO'; values 'ubuntu', 'fedora', 'debian', 'archlinux' }
|
||||||
axis { name 'OPT_LTO'; values 'OPT=0 LTO=OFF', 'OPT=3 LTO=ON' }
|
axis {
|
||||||
axis { name 'STATIC'; values 'ON', 'OFF' }
|
name 'COMP_OPTS';
|
||||||
|
values 'OPT=0 LTO=OFF STATIC=OFF', 'OPT=2 LTO=OFF STATIC=ON', 'OPT=3 LTO=ON STATIC=ON PGO=ON'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('build ffmpeg on linux using docker') {
|
stage('build ffmpeg on linux using docker') {
|
||||||
agent { label "linux && ${ARCH}" }
|
agent { label "linux && ${ARCH}" }
|
||||||
steps {
|
steps {
|
||||||
withDockerCreds {
|
withDockerCreds {
|
||||||
sh "${OPT_LTO} ./scripts/build_with_docker.sh ${DISTRO}"
|
sh "${COMP_OPTS} ./scripts/build_with_docker.sh ${DISTRO}"
|
||||||
archiveArtifacts allowEmptyArchive: true, artifacts: 'gitignore/package/*.tar.xz', defaultExcludes: false
|
archiveArtifacts allowEmptyArchive: true, artifacts: 'gitignore/package/*.tar.xz', defaultExcludes: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
184
README.md
184
README.md
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
A collection of scripts for building ffmpeg and encoding content with the built ffmpeg
|
# ffmpeg-builder
|
||||||
|
A collection of scripts for building `ffmpeg` and encoding content with the built `ffmpeg`.
|
||||||
|
|
||||||
Tested on:
|
Tested on:
|
||||||
- linux x86_64/aarch64 on:
|
- linux x86_64/aarch64 on:
|
||||||
@@ -9,39 +10,156 @@ Tested on:
|
|||||||
- archlinux
|
- archlinux
|
||||||
- darwin aarch64
|
- darwin aarch64
|
||||||
|
|
||||||
```bash
|
With these scripts you can:
|
||||||
~~~ Usable Commands ~~~
|
1. install required dependencies using `./scripts/install_deps.sh`
|
||||||
|
2. build ffmpeg with the desired configuration using `./scripts/build.sh`
|
||||||
|
3. encode a file using libsvtav1_psy and libopus using `./scripts/encode.sh`
|
||||||
|
4. estimate the film grain of a given file using `./scripts/efg.sh`
|
||||||
|
|
||||||
print_cmds:
|
# Building
|
||||||
print usable commands
|
This project supports multiple ways to build.
|
||||||
do_build:
|
|
||||||
build a specific project
|
## Configuration
|
||||||
build:
|
Configuration is done through environment variables.
|
||||||
build ffmpeg with desired configuration
|
By default, this project will build a static `ffmpeg` binary in `./gitignore/sysroot/bin/ffmpeg`.
|
||||||
docker_build_image:
|
The default enabled libraries included in the `ffmpeg` build are:
|
||||||
build docker image with required dependencies pre-installed
|
- libsvtav1_psy
|
||||||
docker_save_image:
|
- libopus
|
||||||
save docker image into tar.zst
|
- libdav1d
|
||||||
docker_load_image:
|
- libaom
|
||||||
load docker image from tar.zst
|
- librav1e
|
||||||
docker_run_image:
|
- libvmaf
|
||||||
run docker image with given flags
|
- libx264
|
||||||
build_with_docker:
|
- libx265
|
||||||
run docker image with given flags
|
- libwebp
|
||||||
docker_build_multiarch_image:
|
- libvpx
|
||||||
build multiarch docker image
|
- libass
|
||||||
efg:
|
- libvorbis
|
||||||
estimate the film grain of a given file
|
- libmp3lame
|
||||||
encode:
|
|
||||||
encode a file using libsvtav1_psy and libopus
|
The user-overridable compile options are:
|
||||||
print_pkg_mgr:
|
- `ENABLE`: configure what ffmpeg enables (default: libsvtav1_psy libopus libdav1d libaom librav1e libvmaf libx264 libx265 libwebp libvpx libass libvorbis libmp3lame)
|
||||||
print out evaluated package manager commands and required packages
|
- `PREFIX`: prefix to install to, default is local install in ./gitignore/sysroot (default: local)
|
||||||
install_deps:
|
- `STATIC`: static or shared build (default: ON)
|
||||||
install required dependencies
|
- `LTO`: enable link time optimization (default: ON)
|
||||||
package:
|
- `CLEAN`: clean build directories before building (default: ON)
|
||||||
package ffmpeg build
|
- `PGO`: enable profile guided optimization (default: OFF)
|
||||||
gen_readme:
|
- `ARCH`: architecture type (x86-64-v{1,2,3,4}, armv8-a, etc) (default: native)
|
||||||
generate project README.md
|
- `OPT`: optimization level (0-3) (default: 3)
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
- only build libsvtav1_psy and libopus: `ENABLE='libsvtav1_psy libopus' ./scripts/build.sh`
|
||||||
|
- build shared libraries in custom path: `PREFIX=/usr/local STATIC=OFF ./scripts/build.sh`
|
||||||
|
- build without LTO at O1: `LTO=OFF OPT=1 ./scripts/build.sh`
|
||||||
|
|
||||||
|
### Native build
|
||||||
|
Make sure to install required dependencies using `./scripts/install_deps.sh`. Then build ffmpeg with the desired configuration using `./scripts/build.sh`.
|
||||||
|
|
||||||
|
### Docker build
|
||||||
|
1. choose a given distro from: `ubuntu fedora debian archlinux`.
|
||||||
|
2. build a docker image with the required dependencies pre-installed using `./scripts/docker_build_image.sh` `<distro>`.
|
||||||
|
3. run a docker image with the given arguments using `./scripts/docker_run_image.sh` `<distro>` `./scripts/build.sh`
|
||||||
|
|
||||||
|
Docker builds support the same configuration options as native builds. For example to build `ffmpeg` on ubuntu with only `libdav1d` enabled:
|
||||||
|
```bash
|
||||||
|
./scripts/docker_build_image.sh ubuntu
|
||||||
|
ENABLE='libdav1d' ./scripts/docker_run_image.sh ubuntu ./scripts/build.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Encoding scripts
|
||||||
|
The encoding scripts are designed to be installed to system paths for re-use via symbolic links back to this repo using the `-I` flag.
|
||||||
|
|
||||||
|
## Encoding with svtav1-psy and opus
|
||||||
|
```bash
|
||||||
|
encode -i input [options] output
|
||||||
|
[-P NUM] set preset (default: 3)
|
||||||
|
[-C NUM] set CRF (default: 25)
|
||||||
|
[-g NUM] set film grain for encode
|
||||||
|
[-p] print the command instead of executing it (default: false)
|
||||||
|
[-c] use cropdetect (default: false)
|
||||||
|
[-d] enable dolby vision (default: false)
|
||||||
|
[-v] print relevant version info
|
||||||
|
[-s] use same container as input, default is convert to mkv
|
||||||
|
|
||||||
|
[output] if unset, defaults to ${PWD}/av1-input-file-name.mkv
|
||||||
|
|
||||||
|
[-u] update script (git pull ffmpeg-builder)
|
||||||
|
[-I] system install at /usr/local/bin/encode
|
||||||
|
[-U] uninstall from /usr/local/bin/encode
|
||||||
|
```
|
||||||
|
- Uses svtav1-psy for the video encoder.
|
||||||
|
- Uses libopus for the audio encoder.
|
||||||
|
- Skips re-encoding av1/opus streams.
|
||||||
|
- Only maps audio streams that match the video stream language if the video stream has a defined language.
|
||||||
|
- Only maps english subtitle streams.
|
||||||
|
- Adds track statistics to the output mkv file and embeds the encoder versions to the output metadata. For example:
|
||||||
|
```
|
||||||
|
ENCODE : aa4d7e6
|
||||||
|
FFMPEG : 8.0
|
||||||
|
LIBOPUS : 1.5.2
|
||||||
|
LIBSVTAV1_PSY : 3.0.2-B
|
||||||
|
SVTAV1_PARAMS : film-grain=8:film-grain-denoise=1:tune=0:...
|
||||||
|
VIDEO_PARAMS : -crf 25 -preset 3 -g 240
|
||||||
|
```
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
- standard usage: `encode -i input.mkv output.mkv`
|
||||||
|
- print out what will be executed without starting encoding: `encode -i input.mkv -p`
|
||||||
|
- encode with film-grain synthesis value of 20 with denoising: `encode -g 20 -i input.mkv`
|
||||||
|
|
||||||
|
## Estimate film-grain
|
||||||
|
```bash
|
||||||
|
efg -i input [options]
|
||||||
|
[-P NUM] set preset (default: 10)
|
||||||
|
[-l NUM] low value (default: 0)
|
||||||
|
[-s NUM] step value (default: 1)
|
||||||
|
[-h NUM] high value (default: 30)
|
||||||
|
[-p] plot bitrates using gnuplot
|
||||||
|
|
||||||
|
[-I] system install at /usr/local/bin/efg
|
||||||
|
[-U] uninstall from /usr/local/bin/efg
|
||||||
|
```
|
||||||
|
- Provides a way to estimate the ideal film-grain amount by encoding from low-high given values and the step amount.
|
||||||
|
- Observing the point of diminishing returns, one can make an informed decision for a given film-grain value to choose.
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
- `efg -i input.mkv -p`
|
||||||
|
```
|
||||||
|
10000 +------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
| **G* + + + + + |
|
||||||
|
| ** /Volumes/External/ffmpeg-builder/gitignore/tmp/efg-matrix-reloaded.mkv/plot.dat ***G*** |
|
||||||
|
| *G** |
|
||||||
|
| **G |
|
||||||
|
9000 |-+ ** +-|
|
||||||
|
| *G** |
|
||||||
|
| **G |
|
||||||
|
| ** |
|
||||||
|
| *G* |
|
||||||
|
8000 |-+ ** +-|
|
||||||
|
| *G** |
|
||||||
|
| **G |
|
||||||
|
| ** |
|
||||||
|
| *G** |
|
||||||
|
7000 |-+ **G* +-|
|
||||||
|
| ** |
|
||||||
|
| *G* |
|
||||||
|
| **G** |
|
||||||
|
6000 |-+ **G* +-|
|
||||||
|
| ** |
|
||||||
|
| *G* |
|
||||||
|
| **G** |
|
||||||
|
| **G* |
|
||||||
|
5000 |-+ **G** +-|
|
||||||
|
| **G****G* |
|
||||||
|
| **G** |
|
||||||
|
| **G****G* |
|
||||||
|
| **G****G* |
|
||||||
|
4000 |-+ **G****G****G* +-|
|
||||||
|
| **G****|
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
| + + + + + |
|
||||||
|
3000 +------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
0 5 10 15 20 25 30
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
419
lib/0-utils.sh
Normal file
419
lib/0-utils.sh
Normal file
@@ -0,0 +1,419 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
|
# ANSI colors
|
||||||
|
RED='\e[0;31m'
|
||||||
|
CYAN='\e[0;36m'
|
||||||
|
GREEN='\e[0;32m'
|
||||||
|
YELLOW='\e[0;33m'
|
||||||
|
NC='\e[0m'
|
||||||
|
|
||||||
|
# echo wrappers
|
||||||
|
echo_wrapper() {
|
||||||
|
local args
|
||||||
|
if [[ $1 == '-n' ]]; then
|
||||||
|
args=("$1")
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
# 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_info() { color="${CYAN}" word="INFO" echo_wrapper "$@"; }
|
||||||
|
echo_pass() { color="${GREEN}" word="PASS" echo_wrapper "$@"; }
|
||||||
|
echo_warn() { color="${YELLOW}" word="WARN" echo_wrapper "$@"; }
|
||||||
|
echo_exit() {
|
||||||
|
echo_fail "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
void() { echo "$@" >/dev/null; }
|
||||||
|
|
||||||
|
echo_if_fail() {
|
||||||
|
local cmd=("$@")
|
||||||
|
local logName="${LOGNAME:-${RANDOM}}-"
|
||||||
|
local out="${TMP_DIR}/${logName}stdout"
|
||||||
|
local err="${TMP_DIR}/${logName}stderr"
|
||||||
|
|
||||||
|
# set trace to the cmdEvalTrace and open file descriptor
|
||||||
|
local cmdEvalTrace="${TMP_DIR}/${logName}cmdEvalTrace"
|
||||||
|
exec 5>"${cmdEvalTrace}"
|
||||||
|
export BASH_XTRACEFD=5
|
||||||
|
|
||||||
|
set -x
|
||||||
|
"${cmd[@]}" >"${out}" 2>"${err}"
|
||||||
|
local retval=$?
|
||||||
|
|
||||||
|
# unset and close file descriptor
|
||||||
|
set +x
|
||||||
|
exec 5>&-
|
||||||
|
|
||||||
|
# parse out relevant part of the trace
|
||||||
|
local cmdEvalLines=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
line="${line/${PS4}/}"
|
||||||
|
test "${line}" == 'set +x' && continue
|
||||||
|
test "${line}" == '' && continue
|
||||||
|
cmdEvalLines+=("${line}")
|
||||||
|
done <"${cmdEvalTrace}"
|
||||||
|
|
||||||
|
if ! test ${retval} -eq 0; then
|
||||||
|
echo
|
||||||
|
echo_fail "command failed with ${retval}:"
|
||||||
|
printf "%s\n" "${cmdEvalLines[@]}"
|
||||||
|
echo_warn "command stdout:"
|
||||||
|
tail -n 32 "${out}"
|
||||||
|
echo_warn "command stderr:"
|
||||||
|
tail -n 32 "${err}"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
if [[ -z ${LOGNAME} ]]; then
|
||||||
|
rm "${out}" "${err}" "${cmdEvalTrace}"
|
||||||
|
fi
|
||||||
|
return ${retval}
|
||||||
|
}
|
||||||
|
|
||||||
|
is_root_owned() {
|
||||||
|
local path=$1
|
||||||
|
local uid
|
||||||
|
|
||||||
|
if stat --version >/dev/null 2>&1; then
|
||||||
|
# GNU coreutils (Linux)
|
||||||
|
uid=$(stat -c '%u' "$path")
|
||||||
|
else
|
||||||
|
# BSD/macOS
|
||||||
|
uid=$(stat -f '%u' "$path")
|
||||||
|
fi
|
||||||
|
|
||||||
|
test "$uid" -eq 0
|
||||||
|
}
|
||||||
|
|
||||||
|
dump_arr() {
|
||||||
|
local arrayNames=("$@")
|
||||||
|
for arrayName in "${arrayNames[@]}"; do
|
||||||
|
declare -n array="${arrayName}"
|
||||||
|
arrayExpanded=("${array[@]}")
|
||||||
|
|
||||||
|
# skip showing single element arrays by default
|
||||||
|
if [[ ! ${#arrayExpanded[@]} -gt 1 ]]; then
|
||||||
|
if [[ ${SHOW_SINGLE} == true ]]; then
|
||||||
|
echo_info "${arrayName}='${arrayExpanded[*]}'"
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
# don't care that the variable has "ARR"
|
||||||
|
echo_info "${arrayName//"_ARR"/}"
|
||||||
|
printf "\t%s\n" "${arrayExpanded[@]}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
has_cmd() {
|
||||||
|
local cmds=("$@")
|
||||||
|
local rv=0
|
||||||
|
for cmd in "${cmds[@]}"; do
|
||||||
|
command -v "${cmd}" >/dev/null 2>&1 || rv=1
|
||||||
|
done
|
||||||
|
|
||||||
|
return ${rv}
|
||||||
|
}
|
||||||
|
|
||||||
|
missing_cmd() {
|
||||||
|
local cmds=("$@")
|
||||||
|
local rv=1
|
||||||
|
for cmd in "${cmds[@]}"; do
|
||||||
|
if ! has_cmd "${cmd}"; then
|
||||||
|
echo_warn "missing ${cmd}"
|
||||||
|
rv=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return ${rv}
|
||||||
|
}
|
||||||
|
|
||||||
|
bash_dirname() {
|
||||||
|
local tmp=${1:-.}
|
||||||
|
|
||||||
|
[[ $tmp != *[!/]* ]] && {
|
||||||
|
printf '/\n'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp=${tmp%%"${tmp##*[!/]}"}
|
||||||
|
|
||||||
|
[[ $tmp != */* ]] && {
|
||||||
|
printf '.\n'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp=${tmp%/*}
|
||||||
|
tmp=${tmp%%"${tmp##*[!/]}"}
|
||||||
|
|
||||||
|
printf '%s\n' "${tmp:-/}"
|
||||||
|
}
|
||||||
|
|
||||||
|
bash_basename() {
|
||||||
|
local tmp
|
||||||
|
path="$1"
|
||||||
|
suffix="${2:-''}"
|
||||||
|
|
||||||
|
tmp=${path%"${path##*[!/]}"}
|
||||||
|
tmp=${tmp##*/}
|
||||||
|
tmp=${tmp%"${suffix/"$tmp"/}"}
|
||||||
|
|
||||||
|
printf '%s\n' "${tmp:-/}"
|
||||||
|
}
|
||||||
|
|
||||||
|
bash_realpath() {
|
||||||
|
local file=$1
|
||||||
|
local dir
|
||||||
|
|
||||||
|
# If the file is already absolute
|
||||||
|
[[ $file == /* ]] && {
|
||||||
|
printf '%s\n' "$file"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Otherwise: split into directory + basename
|
||||||
|
dir="$(bash_dirname "${file}")"
|
||||||
|
file="$(bash_basename "${file}")"
|
||||||
|
|
||||||
|
# If no directory component, use current directory
|
||||||
|
if [[ $dir == "$file" ]]; then
|
||||||
|
dir="$PWD"
|
||||||
|
else
|
||||||
|
# Save current dir, move into target dir, capture $PWD, then return
|
||||||
|
local oldpwd="$PWD"
|
||||||
|
cd "$dir" || return 1
|
||||||
|
dir="$PWD"
|
||||||
|
cd "$oldpwd" || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%s/%s\n' "$dir" "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
line_contains() {
|
||||||
|
local line="$1"
|
||||||
|
local substr="$2"
|
||||||
|
if [[ $line == *"${substr}"* ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
line_starts_with() {
|
||||||
|
local line="$1"
|
||||||
|
local substr="$2"
|
||||||
|
if [[ $line == "${substr}"* ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_linux() {
|
||||||
|
line_contains "${OSTYPE}" 'linux'
|
||||||
|
}
|
||||||
|
|
||||||
|
is_darwin() {
|
||||||
|
line_contains "$(print_os)" darwin
|
||||||
|
}
|
||||||
|
|
||||||
|
is_windows() {
|
||||||
|
line_contains "$(print_os)" windows
|
||||||
|
}
|
||||||
|
|
||||||
|
is_android() {
|
||||||
|
line_contains "$(print_os)" android
|
||||||
|
}
|
||||||
|
|
||||||
|
print_os() {
|
||||||
|
# cached response
|
||||||
|
if [[ -n ${FB_OS} ]]; then
|
||||||
|
echo "${FB_OS}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset FB_OS
|
||||||
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
source /etc/os-release
|
||||||
|
FB_OS="${ID}"
|
||||||
|
if [[ ${VERSION_ID} != '' ]]; then
|
||||||
|
FB_OS+="-${VERSION_ID}"
|
||||||
|
fi
|
||||||
|
if line_starts_with "${FB_OS}" 'arch'; then
|
||||||
|
FB_OS='archlinux'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
FB_OS="$(uname -o)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# lowercase
|
||||||
|
FB_OS="${FB_OS,,}"
|
||||||
|
|
||||||
|
# special treatment for windows
|
||||||
|
if line_contains "${FB_OS}" 'windows' || line_contains "${FB_OS}" 'msys'; then
|
||||||
|
FB_OS='windows'
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${FB_OS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_positive_integer() {
|
||||||
|
local input="$1"
|
||||||
|
if [[ ${input} != ?(-)+([[:digit:]]) || ${input} -lt 0 ]]; then
|
||||||
|
echo_fail "${input} is not a positive integer"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
print_line_indent() {
|
||||||
|
local line="$1"
|
||||||
|
if [[ ${line} =~ ^( +) ]]; then
|
||||||
|
echo -n "${BASH_REMATCH[1]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_line() {
|
||||||
|
local file="$1"
|
||||||
|
local search="$2"
|
||||||
|
local newLine="$3"
|
||||||
|
local newFile="${TMP_DIR}/$(bash_basename "${file}")"
|
||||||
|
|
||||||
|
test -f "${newFile}" && rm "${newFile}"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
if line_contains "${line}" "${search}"; then
|
||||||
|
print_line_indent "${line}" >>"${newFile}"
|
||||||
|
echo -en "${newLine}" >>"${newFile}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "${line}" >>"${newFile}"
|
||||||
|
done <"${file}"
|
||||||
|
|
||||||
|
cp "${newFile}" "${file}"
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_line() {
|
||||||
|
local file="$1"
|
||||||
|
local search="$2"
|
||||||
|
replace_line "${file}" "${search}" ''
|
||||||
|
}
|
||||||
|
|
||||||
|
bash_sort() {
|
||||||
|
local arr=("$@")
|
||||||
|
local n=${#arr[@]}
|
||||||
|
local i j val1 val2
|
||||||
|
|
||||||
|
# Bubble sort, numeric comparison
|
||||||
|
for ((i = 0; i < n; i++)); do
|
||||||
|
for ((j = 0; j < n - i - 1; j++)); do
|
||||||
|
read -r val1 _ <<<"${arr[j]}"
|
||||||
|
read -r val2 _ <<<"${arr[j + 1]}"
|
||||||
|
if (("${val1}" > "${val2}")); then
|
||||||
|
local tmp=${arr[j]}
|
||||||
|
arr[j]=${arr[j + 1]}
|
||||||
|
arr[j + 1]=$tmp
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
printf '%s\n' "${arr[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
_start_spinner() {
|
||||||
|
local spinChars=(
|
||||||
|
"-"
|
||||||
|
'\'
|
||||||
|
"|"
|
||||||
|
"/"
|
||||||
|
)
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
for ((ind = 0; ind < "${#spinChars[@]}"; ind++)); do
|
||||||
|
echo -ne "${spinChars[${ind}]}" '\b\b'
|
||||||
|
sleep .25
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
spinner() {
|
||||||
|
local action="$1"
|
||||||
|
local spinPidFile="${TMP_DIR}/.spinner-pid"
|
||||||
|
case "${action}" in
|
||||||
|
start)
|
||||||
|
test -f "${spinPidFile}" && rm "${spinPidFile}"
|
||||||
|
|
||||||
|
_start_spinner &
|
||||||
|
echo $! >"${spinPidFile}"
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
test -f "${spinPidFile}" && kill "$(<"${spinPidFile}")"
|
||||||
|
echo -ne ' \n'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
get_pkgconfig_version() {
|
||||||
|
local pkg="$1"
|
||||||
|
pkg-config --modversion "${pkg}"
|
||||||
|
}
|
||||||
|
|
||||||
|
using_cmake_4() {
|
||||||
|
local cmakeVersion
|
||||||
|
IFS=$' \t' read -r _ _ cmakeVersion <<<"$(command cmake --version)"
|
||||||
|
line_starts_with "${cmakeVersion}" 4
|
||||||
|
}
|
||||||
|
|
||||||
|
recreate_dir() {
|
||||||
|
local dirs=("$@")
|
||||||
|
for dir in "${dirs[@]}"; do
|
||||||
|
test -d "${dir}" && rm -rf "${dir}"
|
||||||
|
mkdir -p "${dir}" || return 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_dir() {
|
||||||
|
local dirs=("$@")
|
||||||
|
for dir in "${dirs[@]}"; do
|
||||||
|
test -d "${dir}" || mkdir -p "${dir}" || return 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
get_remote_head() {
|
||||||
|
local url="$1"
|
||||||
|
local remoteHEAD=''
|
||||||
|
IFS=$' \t' read -r remoteHEAD _ <<< \
|
||||||
|
"$(git ls-remote "${url}" HEAD)"
|
||||||
|
echo "${remoteHEAD}"
|
||||||
|
}
|
||||||
|
|
||||||
|
fb_max() {
|
||||||
|
local a="$1"
|
||||||
|
local b="$2"
|
||||||
|
test "${a}" -gt "${b}" &&
|
||||||
|
echo "${a}" ||
|
||||||
|
echo "${b}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_padded() {
|
||||||
|
local str="$1"
|
||||||
|
local padding="$2"
|
||||||
|
echo -n "${str}"
|
||||||
|
for ((i = 0; i < padding - ${#str}; i++)); do
|
||||||
|
echo -n ' '
|
||||||
|
done
|
||||||
|
}
|
||||||
908
lib/build.sh
908
lib/build.sh
File diff suppressed because it is too large
Load Diff
@@ -3,21 +3,33 @@
|
|||||||
# variables used externally
|
# variables used externally
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
# default compile options
|
# compile option descriptions
|
||||||
|
unset FB_COMP_OPTS_DESC
|
||||||
|
declare -Ag FB_COMP_OPTS_DESC
|
||||||
|
|
||||||
# clean build directories before building
|
# default compile options
|
||||||
DEFAULT_CLEAN=true
|
FB_COMP_OPTS_DESC['CLEAN']='clean build directories before building'
|
||||||
# enable link time optimization
|
DEFAULT_CLEAN=ON
|
||||||
|
|
||||||
|
FB_COMP_OPTS_DESC['LTO']='enable link time optimization'
|
||||||
DEFAULT_LTO=ON
|
DEFAULT_LTO=ON
|
||||||
# optimization level (0-3)
|
|
||||||
|
FB_COMP_OPTS_DESC['PGO']='enable profile guided optimization'
|
||||||
|
DEFAULT_PGO=OFF
|
||||||
|
|
||||||
|
FB_COMP_OPTS_DESC['OPT']='optimization level (0-3)'
|
||||||
DEFAULT_OPT=3
|
DEFAULT_OPT=3
|
||||||
# static or shared build
|
|
||||||
|
FB_COMP_OPTS_DESC['STATIC']='static or shared build'
|
||||||
DEFAULT_STATIC=ON
|
DEFAULT_STATIC=ON
|
||||||
# architecture type (x86-64-v{1,2,3,4}, armv8-a, etc)
|
|
||||||
|
FB_COMP_OPTS_DESC['ARCH']='architecture type (x86-64-v{1,2,3,4}, armv8-a, etc)'
|
||||||
DEFAULT_ARCH=native
|
DEFAULT_ARCH=native
|
||||||
# prefix to install to, default is local install
|
|
||||||
|
FB_COMP_OPTS_DESC['PREFIX']='prefix to install to, default is local install in ./gitignore/sysroot'
|
||||||
DEFAULT_PREFIX='local'
|
DEFAULT_PREFIX='local'
|
||||||
# configure what ffmpeg enables
|
|
||||||
|
FB_COMP_OPTS_DESC['ENABLE']='configure what ffmpeg enables'
|
||||||
DEFAULT_ENABLE="\
|
DEFAULT_ENABLE="\
|
||||||
libsvtav1_psy \
|
libsvtav1_psy \
|
||||||
libopus \
|
libopus \
|
||||||
@@ -28,13 +40,14 @@ libvmaf \
|
|||||||
libx264 \
|
libx264 \
|
||||||
libx265 \
|
libx265 \
|
||||||
libwebp \
|
libwebp \
|
||||||
|
libvpx \
|
||||||
|
libass \
|
||||||
|
libvorbis \
|
||||||
libmp3lame\
|
libmp3lame\
|
||||||
"
|
"
|
||||||
|
|
||||||
# user-overridable compile option variable names
|
# user-overridable compile option variable names
|
||||||
FB_COMP_OPTS=(
|
FB_COMP_OPTS=("${!FB_COMP_OPTS_DESC[@]}")
|
||||||
CLEAN LTO OPT STATIC ARCH PREFIX ENABLE
|
|
||||||
)
|
|
||||||
|
|
||||||
# sets FB_COMP_OPTS to allow for user-overriding
|
# sets FB_COMP_OPTS to allow for user-overriding
|
||||||
check_compile_opts_override() {
|
check_compile_opts_override() {
|
||||||
|
|||||||
135
lib/docker.sh
135
lib/docker.sh
@@ -11,8 +11,7 @@ DOCKER_WORKDIR='/workdir'
|
|||||||
set_docker_run_flags() {
|
set_docker_run_flags() {
|
||||||
local cargo_git="${IGN_DIR}/cargo/git"
|
local cargo_git="${IGN_DIR}/cargo/git"
|
||||||
local cargo_registry="${IGN_DIR}/cargo/registry"
|
local cargo_registry="${IGN_DIR}/cargo/registry"
|
||||||
test -d "${cargo_git}" || mkdir -p "${cargo_git}"
|
ensure_dir "${cargo_git}" "${cargo_registry}"
|
||||||
test -d "${cargo_registry}" || mkdir -p "${cargo_registry}"
|
|
||||||
DOCKER_RUN_FLAGS=(
|
DOCKER_RUN_FLAGS=(
|
||||||
--rm
|
--rm
|
||||||
-v "${cargo_git}:/root/.cargo/git"
|
-v "${cargo_git}:/root/.cargo/git"
|
||||||
@@ -20,6 +19,7 @@ set_docker_run_flags() {
|
|||||||
-v "${REPO_DIR}:${REPO_DIR}"
|
-v "${REPO_DIR}:${REPO_DIR}"
|
||||||
-w "${REPO_DIR}"
|
-w "${REPO_DIR}"
|
||||||
-e "DEBUG=${DEBUG}"
|
-e "DEBUG=${DEBUG}"
|
||||||
|
-t
|
||||||
)
|
)
|
||||||
for opt in "${FB_COMP_OPTS[@]}"; do
|
for opt in "${FB_COMP_OPTS[@]}"; do
|
||||||
declare -n defOptVal="DEFAULT_${opt}"
|
declare -n defOptVal="DEFAULT_${opt}"
|
||||||
@@ -43,10 +43,10 @@ get_docker_image_tag() {
|
|||||||
local image="$1"
|
local image="$1"
|
||||||
local tag=''
|
local tag=''
|
||||||
case "${image}" in
|
case "${image}" in
|
||||||
ubuntu) tag='ubuntu:24.04@sha256:9cbed754112939e914291337b5e554b07ad7c392491dba6daf25eef1332a22e8' ;;
|
ubuntu) tag='ubuntu:24.04@sha256:c35e29c9450151419d9448b0fd75374fec4fff364a27f176fb458d472dfc9e54' ;;
|
||||||
debian) tag='debian:13@sha256:833c135acfe9521d7a0035a296076f98c182c542a2b6b5a0fd7063d355d696be' ;;
|
debian) tag='debian:13@sha256:0d01188e8dd0ac63bf155900fad49279131a876a1ea7fac917c62e87ccb2732d' ;;
|
||||||
fedora) tag='fedora:42@sha256:6af051ad0a294182c3a957961df6203d91f643880aa41c2ffe3d1302e7505890' ;;
|
fedora) tag='fedora:42@sha256:b3d16134560afa00d7cc2a9e4967eb5b954512805f3fe27d8e70bbed078e22ea' ;;
|
||||||
archlinux) tag='ogarcia/archlinux:latest@sha256:b93f426b23cd0ea0e1befd7d58a26eaf3e6eda3c154c0e8dd75145d11c21304c' ;;
|
archlinux) tag='ogarcia/archlinux:latest@sha256:1d70273180e43b1f51b41514bdaa73c61f647891a53a9c301100d5c4807bf628' ;;
|
||||||
esac
|
esac
|
||||||
echo "${tag}"
|
echo "${tag}"
|
||||||
}
|
}
|
||||||
@@ -100,19 +100,18 @@ docker_login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FB_FUNC_NAMES+=('docker_build_image')
|
FB_FUNC_NAMES+=('docker_build_image')
|
||||||
FB_FUNC_DESCS['docker_build_image']='build docker image with required dependencies pre-installed'
|
FB_FUNC_DESCS['docker_build_image']='build a docker image with the required dependencies pre-installed'
|
||||||
FB_FUNC_COMPLETION['docker_build_image']="${VALID_DOCKER_IMAGES[*]}"
|
FB_FUNC_COMPLETION['docker_build_image']="${VALID_DOCKER_IMAGES[*]}"
|
||||||
docker_build_image() {
|
docker_build_image() {
|
||||||
local image="$1"
|
local image="$1"
|
||||||
validate_selected_image "${image}" || return 1
|
validate_selected_image "${image}" || return 1
|
||||||
check_docker || return 1
|
check_docker || return 1
|
||||||
test -d "${DOCKER_DIR}" || mkdir -p "${DOCKER_DIR}"
|
|
||||||
PLATFORM="${PLATFORM:-$(echo_platform)}"
|
PLATFORM="${PLATFORM:-$(echo_platform)}"
|
||||||
|
|
||||||
echo_info "sourcing package manager for ${image}"
|
echo_info "sourcing package manager for ${image}"
|
||||||
local dockerDistro="$(get_docker_image_tag "${image}")"
|
local dockerDistro="$(get_docker_image_tag "${image}")"
|
||||||
# specific file for evaluated package manager info
|
# specific file for evaluated package manager info
|
||||||
distroPkgMgr="${DOCKER_DIR}/$(bash_basename "${image}")-pkg_mgr"
|
local distroPkgMgr="${DOCKER_DIR}/$(bash_basename "${image}")-pkg_mgr"
|
||||||
# get package manager info
|
# get package manager info
|
||||||
docker run \
|
docker run \
|
||||||
"${DOCKER_RUN_FLAGS[@]}" \
|
"${DOCKER_RUN_FLAGS[@]}" \
|
||||||
@@ -123,54 +122,84 @@ docker_build_image() {
|
|||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "${distroPkgMgr}"
|
source "${distroPkgMgr}"
|
||||||
|
|
||||||
dockerfile="${DOCKER_DIR}/Dockerfile_$(bash_basename "${image}")"
|
local dockerfile="${DOCKER_DIR}/Dockerfile_$(bash_basename "${image}")"
|
||||||
|
local embedPath='/Dockerfile'
|
||||||
{
|
{
|
||||||
echo "FROM ${dockerDistro}"
|
echo "FROM ${dockerDistro}"
|
||||||
echo 'SHELL ["/bin/bash", "-c"]'
|
echo 'SHELL ["/bin/bash", "-c"]'
|
||||||
echo 'RUN ln -sf /bin/bash /bin/sh'
|
echo 'RUN ln -sf /bin/bash /bin/sh'
|
||||||
echo 'ENV DEBIAN_FRONTEND=noninteractive'
|
echo 'ENV DEBIAN_FRONTEND=noninteractive'
|
||||||
# arch is rolling release, so highly likely
|
echo "RUN ${pkg_mgr_update} && ${pkg_mgr_upgrade} && ${pkg_install} ${req_pkgs[*]}"
|
||||||
# an updated is required between pkg changes
|
|
||||||
if line_contains "${dockerDistro}" 'arch'; then
|
# ENV for pipx/rust
|
||||||
local archRuns=''
|
echo 'ENV PIPX_HOME=/root/.local'
|
||||||
archRuns+="${pkg_mgr_update}"
|
echo 'ENV PIPX_BIN_DIR=/root/.local/bin'
|
||||||
archRuns+=" && ${pkg_mgr_upgrade}"
|
echo 'ENV PATH="/root/.local/bin:$PATH"'
|
||||||
archRuns+=" && ${pkg_install} ${req_pkgs[*]}"
|
|
||||||
echo "RUN ${archRuns}"
|
|
||||||
else
|
|
||||||
echo "RUN ${pkg_mgr_update}"
|
|
||||||
echo "RUN ${pkg_mgr_upgrade}"
|
|
||||||
printf "RUN ${pkg_install} %s\n" "${req_pkgs[@]}"
|
|
||||||
fi
|
|
||||||
# pipx
|
|
||||||
echo 'RUN pipx install virtualenv'
|
|
||||||
echo 'RUN pipx ensurepath'
|
|
||||||
# rust
|
|
||||||
echo 'ENV CARGO_HOME="/root/.cargo"'
|
echo 'ENV CARGO_HOME="/root/.cargo"'
|
||||||
echo 'ENV RUSTUP_HOME="/root/.rustup"'
|
echo 'ENV RUSTUP_HOME="/root/.rustup"'
|
||||||
echo 'ENV PATH="/root/.cargo/bin:$PATH"'
|
echo 'ENV PATH="/root/.cargo/bin:$PATH"'
|
||||||
|
# add to profile
|
||||||
|
echo 'RUN export PIPX_HOME=${PIPX_HOME} >> /etc/profile'
|
||||||
|
echo 'RUN export PIPX_BIN_DIR=${PIPX_BIN_DIR} >> /etc/profile'
|
||||||
|
echo 'RUN export CARGO_HOME=${CARGO_HOME} >> /etc/profile'
|
||||||
|
echo 'RUN export RUSTUP_HOME=${RUSTUP_HOME} >> /etc/profile'
|
||||||
|
echo 'RUN export PATH=${PATH} >> /etc/profile'
|
||||||
|
|
||||||
|
# make nobody:nogroup usable
|
||||||
|
echo 'RUN sed -i '/nobody/d' /etc/passwd || true'
|
||||||
|
echo 'RUN echo "nobody:x:65534:65534:nobody:/root:/bin/bash" >> /etc/passwd'
|
||||||
|
echo 'RUN sed -i '/nogroup/d' /etc/group || true'
|
||||||
|
echo 'RUN echo "nogroup:x:65534:" >> /etc/group'
|
||||||
|
# open up permissions before switching user
|
||||||
|
echo 'RUN chmod 777 -R /root/'
|
||||||
|
# run as nobody:nogroup for rest of install
|
||||||
|
echo 'USER 65534:65534'
|
||||||
|
# pipx
|
||||||
|
echo "RUN pipx install virtualenv"
|
||||||
|
# rust
|
||||||
local rustupVersion='1.28.2'
|
local rustupVersion='1.28.2'
|
||||||
local rustcVersion='1.88.0'
|
local rustcVersion='1.90.0'
|
||||||
local rustupTarball="${DOCKER_DIR}/rustup.tar.gz"
|
local rustupTarball="rustup-${rustupVersion}.tar.gz"
|
||||||
if [[ ! -f ${rustupTarball} ]]; then
|
local rustupTarballPath="${DOCKER_DIR}/${rustupTarball}"
|
||||||
wget https://github.com/rust-lang/rustup/archive/refs/tags/${rustupVersion}.tar.gz -O "${rustupTarball}"
|
if [[ ! -f ${rustupTarballPath} ]]; then
|
||||||
|
wget https://github.com/rust-lang/rustup/archive/refs/tags/${rustupVersion}.tar.gz -O "${rustupTarballPath}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "ADD ./rustup.tar.gz /tmp/"
|
echo "ADD ${rustupTarball} /tmp/"
|
||||||
local cargoInst=''
|
echo "RUN cd /tmp/rustup-${rustupVersion} && bash rustup-init.sh -y --default-toolchain=${rustcVersion}"
|
||||||
cargoInst+="cd /tmp/rustup-${rustupVersion}"
|
# install cargo-binstall
|
||||||
cargoInst+=" && bash rustup-init.sh -y --default-toolchain=${rustcVersion}"
|
echo "RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash"
|
||||||
cargoInst+=" && rm -rf /tmp/*"
|
# install cargo-c
|
||||||
echo "RUN ${cargoInst}"
|
echo "RUN cargo-binstall -y cargo-c"
|
||||||
echo "RUN cargo install cargo-c"
|
|
||||||
# since any user may run this image,
|
# final mods for PS1
|
||||||
# open up root tools to everyone
|
echo
|
||||||
echo 'ENV PATH="/root/.local/bin:$PATH"'
|
echo 'USER root'
|
||||||
echo 'RUN chmod 777 -R /root/'
|
echo "RUN echo \"PS1='id=\\\$(id -u)@${image}:\w\\$ '\" >> /etc/bash.bashrc"
|
||||||
|
echo 'USER 65534:65534'
|
||||||
|
echo
|
||||||
|
|
||||||
|
# embed dockerfile into docker image itself
|
||||||
|
# shellcheck disable=SC2094
|
||||||
|
echo "COPY $(bash_basename "${dockerfile}") ${embedPath}"
|
||||||
|
|
||||||
echo "WORKDIR ${DOCKER_WORKDIR}"
|
echo "WORKDIR ${DOCKER_WORKDIR}"
|
||||||
|
|
||||||
} >"${dockerfile}"
|
} >"${dockerfile}"
|
||||||
|
|
||||||
|
# docker buildx is too aggressive with invalidating
|
||||||
|
# build layer caches. Instead of relying on docker
|
||||||
|
# to check for when to rebuild, compare the to-build
|
||||||
|
# dockerfile with the embedded dockerfile
|
||||||
|
local oldDockerfile="${dockerfile}.old"
|
||||||
|
docker_run_image "${image}" cp "${embedPath}" "${oldDockerfile}"
|
||||||
|
if diff "${dockerfile}" "${oldDockerfile}"; then
|
||||||
|
echo_pass "no dockerfile changes detected, skipping rebuild"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo_warn "dockerfile changes detected, proceeding with build"
|
||||||
|
fi
|
||||||
|
|
||||||
image_tag="$(set_distro_image_tag "${image}")"
|
image_tag="$(set_distro_image_tag "${image}")"
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform "${PLATFORM}" \
|
--platform "${PLATFORM}" \
|
||||||
@@ -186,11 +215,8 @@ docker_build_image() {
|
|||||||
--platform "${PLATFORM}" \
|
--platform "${PLATFORM}" \
|
||||||
-t "${DOCKER_REGISTRY}/${image_tag}" \
|
-t "${DOCKER_REGISTRY}/${image_tag}" \
|
||||||
-f "${dockerfile}" \
|
-f "${dockerfile}" \
|
||||||
. || return 1
|
"${DOCKER_DIR}" || return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# FIXME uncomment
|
|
||||||
# docker system prune -f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FB_FUNC_NAMES+=('docker_save_image')
|
FB_FUNC_NAMES+=('docker_save_image')
|
||||||
@@ -218,13 +244,12 @@ docker_load_image() {
|
|||||||
echo_info "loading docker image for ${image_tag}"
|
echo_info "loading docker image for ${image_tag}"
|
||||||
local archive="${DOCKER_DIR}/$(docker_image_archive_name "${image_tag}")"
|
local archive="${DOCKER_DIR}/$(docker_image_archive_name "${image_tag}")"
|
||||||
test -f "$archive" || return 1
|
test -f "$archive" || return 1
|
||||||
zstdcat -T0 "$archive" |
|
zstdcat -T0 "$archive" | docker load || return 1
|
||||||
docker load || return 1
|
|
||||||
docker system prune -f
|
docker system prune -f
|
||||||
}
|
}
|
||||||
|
|
||||||
FB_FUNC_NAMES+=('docker_run_image')
|
FB_FUNC_NAMES+=('docker_run_image')
|
||||||
FB_FUNC_DESCS['docker_run_image']='run docker image with given flags'
|
FB_FUNC_DESCS['docker_run_image']='run a docker image with the given arguments'
|
||||||
FB_FUNC_COMPLETION['docker_run_image']="${VALID_DOCKER_IMAGES[*]}"
|
FB_FUNC_COMPLETION['docker_run_image']="${VALID_DOCKER_IMAGES[*]}"
|
||||||
docker_run_image() {
|
docker_run_image() {
|
||||||
local image="$1"
|
local image="$1"
|
||||||
@@ -240,7 +265,7 @@ docker_run_image() {
|
|||||||
runCmd+=("${cmd[@]}")
|
runCmd+=("${cmd[@]}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
image_tag="$(set_distro_image_tag "${image}")"
|
local image_tag="$(set_distro_image_tag "${image}")"
|
||||||
|
|
||||||
# if a docker registry is defined, pull from it
|
# if a docker registry is defined, pull from it
|
||||||
if [[ ${DOCKER_REGISTRY} != '' ]]; then
|
if [[ ${DOCKER_REGISTRY} != '' ]]; then
|
||||||
@@ -250,16 +275,16 @@ docker_run_image() {
|
|||||||
docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}"
|
docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo_info "running ffmpeg build with ${image_tag}"
|
echo_info "running docker image ${image_tag}"
|
||||||
docker run \
|
docker run \
|
||||||
"${DOCKER_RUN_FLAGS[@]}" \
|
"${DOCKER_RUN_FLAGS[@]}" \
|
||||||
-u "$(id -u):$(id -g)" \
|
-u "$(id -u):$(id -g)" \
|
||||||
"${image_tag}" \
|
"${image_tag}" \
|
||||||
"${runCmd[@]}" || return 1
|
"${runCmd[@]}"
|
||||||
|
|
||||||
docker system prune -f
|
local rv=$?
|
||||||
|
docker image prune -f
|
||||||
return 0
|
return ${rv}
|
||||||
}
|
}
|
||||||
|
|
||||||
FB_FUNC_NAMES+=('build_with_docker')
|
FB_FUNC_NAMES+=('build_with_docker')
|
||||||
|
|||||||
50
lib/efg.sh
50
lib/efg.sh
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
efg_usage() {
|
efg_usage() {
|
||||||
echo "efg -i input [options]"
|
echo "efg -i input [options]"
|
||||||
|
echo -e "\t[-P NUM] set preset (default: ${PRESET})"
|
||||||
echo -e "\t[-l NUM] low value (default: ${LOW})"
|
echo -e "\t[-l NUM] low value (default: ${LOW})"
|
||||||
echo -e "\t[-s NUM] step value (default: ${STEP})"
|
echo -e "\t[-s NUM] step value (default: ${STEP})"
|
||||||
echo -e "\t[-h NUM] high value (default: ${HIGH})"
|
echo -e "\t[-h NUM] high value (default: ${HIGH})"
|
||||||
@@ -12,10 +13,11 @@ efg_usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_efg_opts() {
|
set_efg_opts() {
|
||||||
local opts='pl:s:h:i:IU'
|
local opts='P:pl:s:h:i:IU'
|
||||||
local numOpts=${#opts}
|
local numOpts=${#opts}
|
||||||
# default values
|
# default values
|
||||||
unset INPUT
|
unset INPUT
|
||||||
|
PRESET=10
|
||||||
LOW=0
|
LOW=0
|
||||||
STEP=1
|
STEP=1
|
||||||
HIGH=30
|
HIGH=30
|
||||||
@@ -25,23 +27,30 @@ set_efg_opts() {
|
|||||||
local minOpt=1
|
local minOpt=1
|
||||||
# using all
|
# using all
|
||||||
local maxOpt=${numOpts}
|
local maxOpt=${numOpts}
|
||||||
test $# -lt ${minOpt} && echo_fail "not enough arguments" && efg_usage && return 1
|
test $# -lt ${minOpt} && efg_usage && return 1
|
||||||
test $# -gt ${maxOpt} && echo_fail "too many arguments" && efg_usage && return 1
|
test $# -gt ${maxOpt} && efg_usage && return 1
|
||||||
local OPTARG OPTIND
|
local OPTARG OPTIND
|
||||||
while getopts "${opts}" flag; do
|
while getopts "${opts}" flag; do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
|
P)
|
||||||
|
if ! is_positive_integer "${OPTARG}"; then
|
||||||
|
efg_usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
PRESET="${OPTARG}"
|
||||||
|
;;
|
||||||
I)
|
I)
|
||||||
echo_warn "attempting install"
|
echo_warn "attempting install"
|
||||||
sudo ln -sf "${SCRIPT_DIR}/efg.sh" \
|
sudo ln -sf "${SCRIPT_DIR}/efg.sh" \
|
||||||
"${EFG_INSTALL_PATH}" || return 1
|
"${EFG_INSTALL_PATH}" || return 1
|
||||||
echo_pass "succesfull install"
|
echo_pass "succesfull install"
|
||||||
exit 0
|
return ${FUNC_EXIT_SUCCESS}
|
||||||
;;
|
;;
|
||||||
U)
|
U)
|
||||||
echo_warn "attempting uninstall"
|
echo_warn "attempting uninstall"
|
||||||
sudo rm "${EFG_INSTALL_PATH}" || return 1
|
sudo rm "${EFG_INSTALL_PATH}" || return 1
|
||||||
echo_pass "succesfull uninstall"
|
echo_pass "succesfull uninstall"
|
||||||
exit 0
|
return ${FUNC_EXIT_SUCCESS}
|
||||||
;;
|
;;
|
||||||
i)
|
i)
|
||||||
if [[ $# -lt 2 ]]; then
|
if [[ $# -lt 2 ]]; then
|
||||||
@@ -126,8 +135,7 @@ efg_segment() {
|
|||||||
local segmentBitrates=()
|
local segmentBitrates=()
|
||||||
|
|
||||||
# clean workspace
|
# clean workspace
|
||||||
test -d "${EFG_DIR}" && rm -rf "${EFG_DIR}"
|
recreate_dir "${EFG_DIR}" || return 1
|
||||||
mkdir -p "${EFG_DIR}"
|
|
||||||
|
|
||||||
# split up video into segments based on start times
|
# split up video into segments based on start times
|
||||||
for ((time = 0; time < duration; time += timeBetweenSegments)); do
|
for ((time = 0; time < duration; time += timeBetweenSegments)); do
|
||||||
@@ -170,20 +178,26 @@ efg_segment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
efg_encode() {
|
efg_encode() {
|
||||||
echo -n >"${GRAIN_LOG}"
|
local grainLogWIP="${GRAIN_LOG}.wip"
|
||||||
|
echo -n >"${grainLogWIP}"
|
||||||
for vid in "${EFG_DIR}/"*.mkv; do
|
for vid in "${EFG_DIR}/"*.mkv; do
|
||||||
echo "file: ${vid}" >>"${GRAIN_LOG}"
|
echo "file: ${vid}" >>"${grainLogWIP}"
|
||||||
for ((grain = LOW; grain <= HIGH; grain += STEP)); do
|
for ((grain = LOW; grain <= HIGH; grain += STEP)); do
|
||||||
local file="$(bash_basename "${vid}")"
|
local file="$(bash_basename "${vid}")"
|
||||||
local out="${EFG_DIR}/grain-${grain}-${file}"
|
local out="${EFG_DIR}/grain-${grain}-${file}"
|
||||||
echo_info "encoding ${file} with grain ${grain}"
|
echo_info "encoding ${file} with grain ${grain}"
|
||||||
echo_if_fail encode -P 10 -g ${grain} -i "${vid}" "${out}"
|
echo_if_fail encode -P "${PRESET}" -g ${grain} -i "${vid}" "${out}" || return 1
|
||||||
echo -e "\tgrain: ${grain}, bitrate: $(get_avg_bitrate "${out}")" >>"${GRAIN_LOG}"
|
echo -e "\tgrain: ${grain}, bitrate: $(get_avg_bitrate "${out}")" >>"${grainLogWIP}"
|
||||||
rm "${out}"
|
rm "${out}" || return 1
|
||||||
done
|
done
|
||||||
|
# remove segment once complete
|
||||||
|
rm "${vid}" || return 1
|
||||||
done
|
done
|
||||||
|
|
||||||
less "${GRAIN_LOG}"
|
# atomic move of grain log
|
||||||
|
mv "${grainLogWIP}" "${GRAIN_LOG}" || return 1
|
||||||
|
|
||||||
|
echo "$(<"${GRAIN_LOG}")"
|
||||||
}
|
}
|
||||||
|
|
||||||
efg_plot() {
|
efg_plot() {
|
||||||
@@ -245,8 +259,14 @@ efg() {
|
|||||||
# encode N highest-bitrate segments
|
# encode N highest-bitrate segments
|
||||||
ENCODE_SEGMENTS=5
|
ENCODE_SEGMENTS=5
|
||||||
|
|
||||||
set_efg_opts "$@" || return 1
|
set_efg_opts "$@"
|
||||||
test -d "${EFG_DIR}" || mkdir "${EFG_DIR}"
|
local ret=$?
|
||||||
|
if [[ ${ret} -eq ${FUNC_EXIT_SUCCESS} ]]; then
|
||||||
|
return 0
|
||||||
|
elif [[ ${ret} -ne 0 ]]; then
|
||||||
|
return ${ret}
|
||||||
|
fi
|
||||||
|
ensure_dir "${EFG_DIR}"
|
||||||
|
|
||||||
GRAIN_LOG="${EFG_DIR}/${LOW}-${STEP}-${HIGH}-grains.txt"
|
GRAIN_LOG="${EFG_DIR}/${LOW}-${STEP}-${HIGH}-grains.txt"
|
||||||
|
|
||||||
|
|||||||
158
lib/encode.sh
158
lib/encode.sh
@@ -1,28 +1,33 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
unmap_streams() {
|
# sets unmapStreams
|
||||||
|
set_unmap_streams() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local unmapFilter='bin_data|jpeg|png'
|
local unmapFilter='bin_data|jpeg|png'
|
||||||
local unmap=()
|
|
||||||
local streamsStr
|
local streamsStr
|
||||||
|
unmapStreams=()
|
||||||
streamsStr="$(get_num_streams "${file}")" || return 1
|
streamsStr="$(get_num_streams "${file}")" || return 1
|
||||||
mapfile -t streams <<<"${streamsStr}" || return 1
|
mapfile -t streams <<<"${streamsStr}" || return 1
|
||||||
for stream in "${streams[@]}"; do
|
for stream in "${streams[@]}"; do
|
||||||
if [[ "$(get_stream_codec "${file}" "${stream}")" =~ ${unmapFilter} ]]; then
|
if [[ "$(get_stream_codec "${file}" "${stream}")" =~ ${unmapFilter} ]]; then
|
||||||
unmap+=("-map" "-0:${stream}")
|
unmapStreams+=("-map" "-0:${stream}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "${unmap[@]}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# sets audioParams
|
||||||
set_audio_params() {
|
set_audio_params() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local audioParams=()
|
|
||||||
local videoLang
|
local videoLang
|
||||||
|
audioParams=()
|
||||||
videoLang="$(get_stream_lang "${file}" 'v:0')" || return 1
|
videoLang="$(get_stream_lang "${file}" 'v:0')" || return 1
|
||||||
for stream in $(get_num_streams "${file}" 'a'); do
|
for stream in $(get_num_streams "${file}" 'a'); do
|
||||||
local numChannels codec lang
|
local numChannels codec lang
|
||||||
numChannels="$(get_num_audio_channels "${file}" "a:${stream}")" || return 1
|
numChannels="$(get_num_audio_channels "${file}" "${stream}")" || return 1
|
||||||
|
if [[ ${numChannels} == '' ]]; then
|
||||||
|
echo_fail "could not obtain channel count for stream ${stream}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
local channelBitrate=$((numChannels * 64))
|
local channelBitrate=$((numChannels * 64))
|
||||||
codec="$(get_stream_codec "${file}" "${stream}")" || return 1
|
codec="$(get_stream_codec "${file}" "${stream}")" || return 1
|
||||||
lang="$(get_stream_lang "${file}" "${stream}")" || return 1
|
lang="$(get_stream_lang "${file}" "${stream}")" || return 1
|
||||||
@@ -33,28 +38,40 @@ set_audio_params() {
|
|||||||
)
|
)
|
||||||
elif [[ ${codec} == 'opus' ]]; then
|
elif [[ ${codec} == 'opus' ]]; then
|
||||||
audioParams+=(
|
audioParams+=(
|
||||||
"-c:${stream}"
|
"-c:${OUTPUT_INDEX}"
|
||||||
"copy"
|
"copy"
|
||||||
)
|
)
|
||||||
|
OUTPUT_INDEX=$((OUTPUT_INDEX + 1))
|
||||||
else
|
else
|
||||||
audioParams+=(
|
audioParams+=(
|
||||||
"-filter:${stream}"
|
"-filter:${OUTPUT_INDEX}"
|
||||||
"aformat=channel_layouts=7.1|5.1|stereo|mono"
|
"aformat=channel_layouts=7.1|5.1|stereo|mono"
|
||||||
"-c:${stream}"
|
"-c:${OUTPUT_INDEX}"
|
||||||
"libopus"
|
"libopus"
|
||||||
"-b:${stream}"
|
"-b:${OUTPUT_INDEX}"
|
||||||
"${channelBitrate}k"
|
"${channelBitrate}k"
|
||||||
)
|
)
|
||||||
|
OUTPUT_INDEX=$((OUTPUT_INDEX + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "${audioParams[@]}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# sets subtitleParams
|
||||||
set_subtitle_params() {
|
set_subtitle_params() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local convertCodec='eia_608'
|
local convertCodec='eia_608'
|
||||||
local keepLang='eng'
|
local keepLang='eng'
|
||||||
local subtitleParams=()
|
|
||||||
|
local defaultTextCodec
|
||||||
|
if [[ ${SAME_CONTAINER} == false && ${FILE_EXT} == 'mkv' ]]; then
|
||||||
|
defaultTextCodec='srt'
|
||||||
|
convertCodec+='|mov_text'
|
||||||
|
else
|
||||||
|
defaultTextCodec='mov_text'
|
||||||
|
convertCodec+='|srt'
|
||||||
|
fi
|
||||||
|
|
||||||
|
subtitleParams=()
|
||||||
for stream in $(get_num_streams "${file}" 's'); do
|
for stream in $(get_num_streams "${file}" 's'); do
|
||||||
local codec lang
|
local codec lang
|
||||||
codec="$(get_stream_codec "${file}" "${stream}")" || return 1
|
codec="$(get_stream_codec "${file}" "${stream}")" || return 1
|
||||||
@@ -64,11 +81,11 @@ set_subtitle_params() {
|
|||||||
'-map'
|
'-map'
|
||||||
"-0:${stream}"
|
"-0:${stream}"
|
||||||
)
|
)
|
||||||
elif [[ ${codec} == "${convertCodec}" ]]; then
|
elif [[ ${codec} =~ ${convertCodec} ]]; then
|
||||||
subtitleParams+=("-c:${stream}" "srt")
|
subtitleParams+=("-c:${OUTPUT_INDEX}" "${defaultTextCodec}")
|
||||||
|
OUTPUT_INDEX=$((OUTPUT_INDEX + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "${subtitleParams[@]}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_encode_versions() {
|
get_encode_versions() {
|
||||||
@@ -82,11 +99,11 @@ get_encode_versions() {
|
|||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
local output="$(ffmpeg -version 2>&1)"
|
local output="$(ffmpeg -version 2>&1)"
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
if line_contains "${line}" 'ffmpeg='; then
|
if line_starts_with "${line}" 'ffmpeg='; then
|
||||||
ffmpegVersion="${line}"
|
ffmpegVersion="${line}"
|
||||||
elif line_contains "${line}" 'libsvtav1_psy=' || line_contains "${line}" 'libsvtav1='; then
|
elif line_starts_with "${line}" 'libsvtav1'; then
|
||||||
videoEncVersion="${line}"
|
videoEncVersion="${line}"
|
||||||
elif line_contains "${line}" 'libopus='; then
|
elif line_starts_with "${line}" 'libopus='; then
|
||||||
audioEncVersion="${line}"
|
audioEncVersion="${line}"
|
||||||
fi
|
fi
|
||||||
done <<<"${output}"
|
done <<<"${output}"
|
||||||
@@ -135,10 +152,10 @@ encode_usage() {
|
|||||||
echo -e "\t[-p] print the command instead of executing it (default: ${PRINT_OUT})"
|
echo -e "\t[-p] print the command instead of executing it (default: ${PRINT_OUT})"
|
||||||
echo -e "\t[-c] use cropdetect (default: ${CROP})"
|
echo -e "\t[-c] use cropdetect (default: ${CROP})"
|
||||||
echo -e "\t[-d] enable dolby vision (default: ${DV_TOGGLE})"
|
echo -e "\t[-d] enable dolby vision (default: ${DV_TOGGLE})"
|
||||||
echo -e "\t[-v] Print relevant version info"
|
echo -e "\t[-v] print relevant version info"
|
||||||
echo -e "\t[-s] use same container as input, default is mkv"
|
echo -e "\t[-s] use same container as input, default is convert to mkv"
|
||||||
echo -e "\n\t[output] if unset, defaults to ${HOME}/"
|
echo -e "\n\t[output] if unset, defaults to \${PWD}/av1-input-file-name.mkv"
|
||||||
echo -e "\n\t[-u] update script (git pull at ${REPO_DIR})"
|
echo -e "\n\t[-u] update script (git pull ffmpeg-builder)"
|
||||||
echo -e "\t[-I] system install at ${ENCODE_INSTALL_PATH}"
|
echo -e "\t[-I] system install at ${ENCODE_INSTALL_PATH}"
|
||||||
echo -e "\t[-U] uninstall from ${ENCODE_INSTALL_PATH}"
|
echo -e "\t[-U] uninstall from ${ENCODE_INSTALL_PATH}"
|
||||||
return 0
|
return 0
|
||||||
@@ -159,37 +176,37 @@ set_encode_opts() {
|
|||||||
PRINT_OUT=false
|
PRINT_OUT=false
|
||||||
DV_TOGGLE=false
|
DV_TOGGLE=false
|
||||||
ENCODE_INSTALL_PATH='/usr/local/bin/encode'
|
ENCODE_INSTALL_PATH='/usr/local/bin/encode'
|
||||||
local sameContainer="false"
|
SAME_CONTAINER="false"
|
||||||
# only using -I/U
|
# only using -I/U
|
||||||
local minOpt=1
|
local minOpt=1
|
||||||
# using all + output name
|
# using all + output name
|
||||||
local maxOpt=$((numOpts + 1))
|
local maxOpt=$((numOpts + 1))
|
||||||
test $# -lt ${minOpt} && echo_fail "not enough arguments" && encode_usage && return 1
|
test $# -lt ${minOpt} && encode_usage && return 1
|
||||||
test $# -gt ${maxOpt} && echo_fail "too many arguments" && encode_usage && return 1
|
test $# -gt ${maxOpt} && encode_usage && return 1
|
||||||
local optsUsed=0
|
local optsUsed=0
|
||||||
local OPTARG OPTIND
|
local OPTARG OPTIND
|
||||||
while getopts "${opts}" flag; do
|
while getopts "${opts}" flag; do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
u)
|
u)
|
||||||
encode_update
|
encode_update || return 1
|
||||||
exit $?
|
return ${FUNC_EXIT_SUCCESS}
|
||||||
;;
|
;;
|
||||||
I)
|
I)
|
||||||
echo_warn "attempting install"
|
echo_warn "attempting install"
|
||||||
sudo ln -sf "${SCRIPT_DIR}/encode.sh" \
|
sudo ln -sf "${SCRIPT_DIR}/encode.sh" \
|
||||||
"${ENCODE_INSTALL_PATH}" || return 1
|
"${ENCODE_INSTALL_PATH}" || return 1
|
||||||
echo_pass "succesfull install"
|
echo_pass "succesfull install"
|
||||||
exit 0
|
return ${FUNC_EXIT_SUCCESS}
|
||||||
;;
|
;;
|
||||||
U)
|
U)
|
||||||
echo_warn "attempting uninstall"
|
echo_warn "attempting uninstall"
|
||||||
sudo rm "${ENCODE_INSTALL_PATH}" || return 1
|
sudo rm "${ENCODE_INSTALL_PATH}" || return 1
|
||||||
echo_pass "succesfull uninstall"
|
echo_pass "succesfull uninstall"
|
||||||
exit 0
|
return ${FUNC_EXIT_SUCCESS}
|
||||||
;;
|
;;
|
||||||
v)
|
v)
|
||||||
get_encode_versions print
|
get_encode_versions print || return 1
|
||||||
exit $?
|
return ${FUNC_EXIT_SUCCESS}
|
||||||
;;
|
;;
|
||||||
i)
|
i)
|
||||||
if [[ $# -lt 2 ]]; then
|
if [[ $# -lt 2 ]]; then
|
||||||
@@ -213,7 +230,7 @@ set_encode_opts() {
|
|||||||
optsUsed=$((optsUsed + 1))
|
optsUsed=$((optsUsed + 1))
|
||||||
;;
|
;;
|
||||||
s)
|
s)
|
||||||
sameContainer=true
|
SAME_CONTAINER=true
|
||||||
optsUsed=$((optsUsed + 1))
|
optsUsed=$((optsUsed + 1))
|
||||||
;;
|
;;
|
||||||
g)
|
g)
|
||||||
@@ -221,7 +238,7 @@ set_encode_opts() {
|
|||||||
encode_usage
|
encode_usage
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
GRAIN="film-grain=${OPTARG}:film-grain-denoise=1:adaptive-film-grain=1:"
|
GRAIN="film-grain=${OPTARG}:film-grain-denoise=1:"
|
||||||
optsUsed=$((optsUsed + 2))
|
optsUsed=$((optsUsed + 2))
|
||||||
;;
|
;;
|
||||||
P)
|
P)
|
||||||
@@ -236,7 +253,7 @@ set_encode_opts() {
|
|||||||
if ! is_positive_integer "${OPTARG}" || test ${OPTARG} -gt 63; then
|
if ! is_positive_integer "${OPTARG}" || test ${OPTARG} -gt 63; then
|
||||||
echo_fail "${OPTARG} is not a valid CRF value (0-63)"
|
echo_fail "${OPTARG} is not a valid CRF value (0-63)"
|
||||||
encode_usage
|
encode_usage
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
CRF="${OPTARG}"
|
CRF="${OPTARG}"
|
||||||
OPTS_USED=$((OPTS_USED + 2))
|
OPTS_USED=$((OPTS_USED + 2))
|
||||||
@@ -254,11 +271,11 @@ set_encode_opts() {
|
|||||||
OUTPUT="${*: -1}"
|
OUTPUT="${*: -1}"
|
||||||
else
|
else
|
||||||
local basename="$(bash_basename "${INPUT}")"
|
local basename="$(bash_basename "${INPUT}")"
|
||||||
OUTPUT="${HOME}/av1-${basename}"
|
OUTPUT="${PWD}/av1-${basename}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# use same container for output
|
# use same container for output
|
||||||
if [[ $sameContainer == "true" ]]; then
|
if [[ $SAME_CONTAINER == "true" ]]; then
|
||||||
local fileFormat
|
local fileFormat
|
||||||
fileFormat="$(get_file_format "${INPUT}")" || return 1
|
fileFormat="$(get_file_format "${INPUT}")" || return 1
|
||||||
FILE_EXT=''
|
FILE_EXT=''
|
||||||
@@ -293,9 +310,11 @@ set_encode_opts() {
|
|||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
gen_encode_script() {
|
gen_encode_script() {
|
||||||
test -d "${TMP_DIR}" || mkdir -p "${TMP_DIR}"
|
|
||||||
local genScript="${TMP_DIR}/$(bash_basename "${OUTPUT}").sh"
|
local genScript="${TMP_DIR}/$(bash_basename "${OUTPUT}").sh"
|
||||||
|
|
||||||
|
# global output index number to increment
|
||||||
|
OUTPUT_INDEX=0
|
||||||
|
|
||||||
# single string params
|
# single string params
|
||||||
local params=(
|
local params=(
|
||||||
INPUT
|
INPUT
|
||||||
@@ -320,11 +339,13 @@ gen_encode_script() {
|
|||||||
"spy-rd=1"
|
"spy-rd=1"
|
||||||
"psy-rd=1"
|
"psy-rd=1"
|
||||||
"sharpness=3"
|
"sharpness=3"
|
||||||
"enable-overlays=1"
|
"enable-overlays=0"
|
||||||
|
"hbd-mds=1"
|
||||||
"scd=1"
|
"scd=1"
|
||||||
"fast-decode=1"
|
"fast-decode=1"
|
||||||
"enable-variance-boost=1"
|
"enable-variance-boost=1"
|
||||||
"enable-qm=1"
|
"enable-qm=1"
|
||||||
|
"chroma-qm-min-10"
|
||||||
"qm-min=4"
|
"qm-min=4"
|
||||||
"qm-max=15"
|
"qm-max=15"
|
||||||
)
|
)
|
||||||
@@ -334,7 +355,7 @@ gen_encode_script() {
|
|||||||
|
|
||||||
# arrays
|
# arrays
|
||||||
local arrays=(
|
local arrays=(
|
||||||
unmap
|
unmapStreams
|
||||||
audioParams
|
audioParams
|
||||||
videoParams
|
videoParams
|
||||||
metadata
|
metadata
|
||||||
@@ -345,28 +366,42 @@ gen_encode_script() {
|
|||||||
"-crf" '${CRF}' "-preset" '${PRESET}' "-g" "240"
|
"-crf" '${CRF}' "-preset" '${PRESET}' "-g" "240"
|
||||||
)
|
)
|
||||||
local ffmpegParams=(
|
local ffmpegParams=(
|
||||||
|
'-hide_banner'
|
||||||
'-i' '${INPUT}'
|
'-i' '${INPUT}'
|
||||||
'-y' '-map' '0'
|
'-y'
|
||||||
|
'-map' '0'
|
||||||
'-c:s' 'copy'
|
'-c:s' 'copy'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# set video params
|
||||||
|
local inputVideoCodec="$(get_stream_codec "${INPUT}" 'v:0')"
|
||||||
|
if [[ ${inputVideoCodec} == 'av1' ]]; then
|
||||||
|
ffmpegParams+=(
|
||||||
|
"-c:v:${OUTPUT_INDEX}" 'copy'
|
||||||
|
)
|
||||||
|
else
|
||||||
|
ffmpegParams+=(
|
||||||
|
'-pix_fmt' 'yuv420p10le'
|
||||||
|
"-c:v:${OUTPUT_INDEX}" 'libsvtav1' '${videoParams[@]}'
|
||||||
|
'-svtav1-params' '${svtAv1Params}'
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
OUTPUT_INDEX=$((OUTPUT_INDEX + 1))
|
||||||
|
|
||||||
# these values may be empty
|
# these values may be empty
|
||||||
local unmapStr audioParamsStr subtitleParamsStr
|
local unmapStr audioParamsStr subtitleParamsStr
|
||||||
unmapStr="$(unmap_streams "${INPUT}")" || return 1
|
set_unmap_streams "${INPUT}" || return 1
|
||||||
audioParamsStr="$(set_audio_params "${INPUT}")" || return 1
|
set_audio_params "${INPUT}" || return 1
|
||||||
subtitleParamsStr="$(set_subtitle_params "${INPUT}")" || return 1
|
set_subtitle_params "${INPUT}" || return 1
|
||||||
|
|
||||||
unmap=(${unmapStr})
|
if [[ ${unmapStreams[*]} != '' ]]; then
|
||||||
if [[ ${unmap[*]} != '' ]]; then
|
ffmpegParams+=('${unmapStreams[@]}')
|
||||||
ffmpegParams+=('${unmap[@]}')
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
audioParams=(${audioParamsStr})
|
|
||||||
if [[ ${audioParams[*]} != '' ]]; then
|
if [[ ${audioParams[*]} != '' ]]; then
|
||||||
ffmpegParams+=('${audioParams[@]}')
|
ffmpegParams+=('${audioParams[@]}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
subtitleParams=(${subtitleParamsStr})
|
|
||||||
if [[ ${subtitleParams[*]} != '' ]]; then
|
if [[ ${subtitleParams[*]} != '' ]]; then
|
||||||
ffmpegParams+=('${subtitleParams[@]}')
|
ffmpegParams+=('${subtitleParams[@]}')
|
||||||
fi
|
fi
|
||||||
@@ -375,19 +410,6 @@ gen_encode_script() {
|
|||||||
ffmpegParams+=('-vf' '${crop}')
|
ffmpegParams+=('-vf' '${crop}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local inputVideoCodec="$(get_stream_codec "${INPUT}" 'v:0')"
|
|
||||||
if [[ ${inputVideoCodec} == 'av1' ]]; then
|
|
||||||
ffmpegParams+=(
|
|
||||||
'-c:v' 'copy'
|
|
||||||
)
|
|
||||||
else
|
|
||||||
ffmpegParams+=(
|
|
||||||
'-pix_fmt' 'yuv420p10le'
|
|
||||||
'-c:v' 'libsvtav1' '${videoParams[@]}'
|
|
||||||
'-svtav1-params' '${svtAv1Params}'
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
get_encode_versions || return 1
|
get_encode_versions || return 1
|
||||||
local metadata=(
|
local metadata=(
|
||||||
'-metadata' '${encodeVersion}'
|
'-metadata' '${encodeVersion}'
|
||||||
@@ -427,11 +449,11 @@ gen_encode_script() {
|
|||||||
echo 'ffmpeg "${ffmpegParams[@]}" -dolbyvision 0 "${OUTPUT}" || exit 1'
|
echo 'ffmpeg "${ffmpegParams[@]}" -dolbyvision 0 "${OUTPUT}" || exit 1'
|
||||||
|
|
||||||
# track-stats and clear title
|
# track-stats and clear title
|
||||||
if [[ ${FILE_EXT} == 'mkv' ]]; then
|
if [[ ${FILE_EXT} == 'mkv' ]] && has_cmd mkvpropedit; then
|
||||||
{
|
{
|
||||||
echo
|
echo
|
||||||
echo "mkvpropedit \"${OUTPUT}\" --add-track-statistics-tags"
|
echo 'mkvpropedit "${OUTPUT}" --add-track-statistics-tags'
|
||||||
echo "mkvpropedit \"${OUTPUT}\" --edit info --set \"title=\""
|
echo 'mkvpropedit "${OUTPUT}" --edit info --set "title="'
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -451,6 +473,12 @@ FB_FUNC_NAMES+=('encode')
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
FB_FUNC_DESCS['encode']='encode a file using libsvtav1_psy and libopus'
|
FB_FUNC_DESCS['encode']='encode a file using libsvtav1_psy and libopus'
|
||||||
encode() {
|
encode() {
|
||||||
set_encode_opts "$@" || return 1
|
set_encode_opts "$@"
|
||||||
|
local ret=$?
|
||||||
|
if [[ ${ret} -eq ${FUNC_EXIT_SUCCESS} ]]; then
|
||||||
|
return 0
|
||||||
|
elif [[ ${ret} -ne 0 ]]; then
|
||||||
|
return ${ret}
|
||||||
|
fi
|
||||||
gen_encode_script || return 1
|
gen_encode_script || return 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,3 +126,44 @@ get_stream_lang() {
|
|||||||
-of default=noprint_wrappers=1:nokey=1 \
|
-of default=noprint_wrappers=1:nokey=1 \
|
||||||
"${file}"
|
"${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gen_video() {
|
||||||
|
local outFile="$1"
|
||||||
|
local addFlags=()
|
||||||
|
shift
|
||||||
|
|
||||||
|
local vf="format=yuv420p10le"
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "${arg}" in
|
||||||
|
'1080p') resolution='1920x1080' ;;
|
||||||
|
'2160p') resolution='3840x2160' ;;
|
||||||
|
'grain=yes') vf+=",noise=alls=15:allf=t+u" ;;
|
||||||
|
'hdr=yes')
|
||||||
|
local colorPrimaries='bt2020'
|
||||||
|
local colorTrc='smpte2084'
|
||||||
|
local colorspace='bt2020nc'
|
||||||
|
vf+=",setparams=color_primaries=${colorPrimaries}:color_trc=${colorTrc}:colorspace=${colorspace}"
|
||||||
|
addFlags+=(
|
||||||
|
-color_primaries "${colorPrimaries}"
|
||||||
|
-color_trc "${colorTrc}"
|
||||||
|
-colorspace "${colorspace}"
|
||||||
|
-metadata:s:v:0 "mastering_display_metadata=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)"
|
||||||
|
-metadata:s:v:0 "content_light_level=1000,400"
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
*) echo_fail "bad arg ${arg}" && return 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo_if_fail ffmpeg -y \
|
||||||
|
-hide_banner \
|
||||||
|
-f lavfi \
|
||||||
|
-i "testsrc2=size=${resolution}:rate=24:duration=5" \
|
||||||
|
-vf "${vf}" \
|
||||||
|
-c:v ffv1 \
|
||||||
|
-level 3 \
|
||||||
|
-g 1 \
|
||||||
|
-color_range tv \
|
||||||
|
"${addFlags[@]}" \
|
||||||
|
"${outFile}"
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,11 +4,16 @@
|
|||||||
determine_pkg_mgr() {
|
determine_pkg_mgr() {
|
||||||
# sudo used externally
|
# sudo used externally
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
test "$(id -u)" -eq 0 && SUDO='' || SUDO='sudo '
|
if is_windows || test "$(id -u)" -eq 0; then
|
||||||
|
SUDO=''
|
||||||
|
else
|
||||||
|
SUDO='sudo '
|
||||||
|
fi
|
||||||
|
|
||||||
# pkg-mgr update-cmd upgrade-cmd install-cmd check-cmd
|
# pkg-mgr update-cmd upgrade-cmd install-cmd check-cmd
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
local PKG_MGR_MAP='
|
local PKG_MGR_MAP='
|
||||||
|
pkg:pkg update:pkg upgrade:pkg install -y:dpkg -l ${pkg}
|
||||||
brew:brew update:brew upgrade:brew install:brew list --formula ${pkg}
|
brew:brew update:brew upgrade:brew install:brew list --formula ${pkg}
|
||||||
apt-get:${SUDO}apt-get update:${SUDO}apt-get upgrade -y:${SUDO}apt-get install -y:dpkg -l ${pkg}
|
apt-get:${SUDO}apt-get update:${SUDO}apt-get upgrade -y:${SUDO}apt-get install -y:dpkg -l ${pkg}
|
||||||
pacman:${SUDO}pacman -Syy:${SUDO}pacman -Syu --noconfirm:${SUDO}pacman -S --noconfirm --needed:pacman -Qi ${pkg}
|
pacman:${SUDO}pacman -Syy:${SUDO}pacman -Syu --noconfirm:${SUDO}pacman -S --noconfirm --needed:pacman -Qi ${pkg}
|
||||||
@@ -51,47 +56,75 @@ print_req_pkgs() {
|
|||||||
local brew_pkgs=(
|
local brew_pkgs=(
|
||||||
"${common_pkgs[@]}" pkgconf
|
"${common_pkgs[@]}" pkgconf
|
||||||
mkvtoolnix pipx uutils-coreutils
|
mkvtoolnix pipx uutils-coreutils
|
||||||
|
llvm lld
|
||||||
)
|
)
|
||||||
local common_linux_pkgs=(
|
local common_linux_pkgs=(
|
||||||
"${common_pkgs[@]}" clang valgrind
|
"${common_pkgs[@]}" clang valgrind
|
||||||
curl bc lshw xxd pkgconf sudo
|
curl bc lshw xxd pkgconf sudo llvm
|
||||||
)
|
)
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local apt_get_pkgs=(
|
local apt_get_pkgs=(
|
||||||
"${common_linux_pkgs[@]}" build-essential
|
"${common_linux_pkgs[@]}" pipx
|
||||||
git-core libass-dev libfreetype6-dev
|
build-essential libssl-dev gobjc++
|
||||||
libsdl2-dev libva-dev libvdpau-dev
|
mawk libc6-dev mediainfo ninja-build
|
||||||
libvorbis-dev libxcb1-dev pipx
|
mkvtoolnix libgtest-dev lld
|
||||||
libxcb-shm0-dev libxcb-xfixes0-dev
|
libfontconfig-dev libglib2.0-dev
|
||||||
zlib1g-dev libssl-dev ninja-build
|
|
||||||
gobjc++ mawk libnuma-dev libc6-dev
|
|
||||||
mediainfo mkvtoolnix libgtest-dev
|
|
||||||
)
|
)
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local pacman_pkgs=(
|
local pacman_pkgs=(
|
||||||
"${common_linux_pkgs[@]}" base-devel
|
"${common_linux_pkgs[@]}" base-devel
|
||||||
python-pipx ninja numactl
|
python-pipx ninja lld mkvtoolnix-cli
|
||||||
|
glib2-devel
|
||||||
)
|
)
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local dnf_pkgs=(
|
local dnf_pkgs=(
|
||||||
"${common_linux_pkgs[@]}" openssl-devel
|
"${common_linux_pkgs[@]}" openssl-devel
|
||||||
pipx ninja-build fontconfig-devel wget2
|
pipx ninja-build fontconfig-devel wget2
|
||||||
cpuinfo-devel glibc-static glibc-devel
|
glibc-static glibc-devel patch
|
||||||
libstdc++-static libstdc++-devel patch
|
libstdc++-static libstdc++-devel
|
||||||
numactl-devel
|
llvm-cmake-utils llvm-devel
|
||||||
|
llvm-static compiler-rt lld
|
||||||
|
mkvtoolnix glib2-static
|
||||||
)
|
)
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local android_pkgs=(
|
local pkg_pkgs=(
|
||||||
autoconf automake cmake libtool
|
autoconf automake cmake libtool
|
||||||
texinfo nasm yasm python3 wget
|
texinfo nasm yasm python3 wget
|
||||||
doxygen jq ccache gawk rust
|
doxygen jq ccache gawk rust
|
||||||
git gnuplot bison rsync ragel
|
git gnuplot bison rsync ragel
|
||||||
zip unzip gperf build-essential
|
zip unzip gperf build-essential
|
||||||
binutils
|
binutils ninja ndk-multilib-native-static
|
||||||
|
libandroid-posix-semaphore
|
||||||
|
libandroid-posix-semaphore-static
|
||||||
|
libandroid-shmem
|
||||||
|
libandroid-shmem-static
|
||||||
|
)
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
local msys_ucrt_pkgs=(
|
||||||
|
mingw-w64-ucrt-x86_64-toolchain
|
||||||
|
mingw-w64-ucrt-x86_64-autotools
|
||||||
|
mingw-w64-ucrt-x86_64-clang
|
||||||
|
mingw-w64-ucrt-x86_64-clang-libs
|
||||||
|
mingw-w64-ucrt-x86_64-cmake
|
||||||
|
mingw-w64-ucrt-x86_64-compiler-rt
|
||||||
|
mingw-w64-ucrt-x86_64-doxygen
|
||||||
|
mingw-w64-ucrt-x86_64-gcc-libs
|
||||||
|
mingw-w64-ucrt-x86_64-gperf
|
||||||
|
mingw-w64-ucrt-x86_64-itstool
|
||||||
|
mingw-w64-ucrt-x86_64-meson
|
||||||
|
mingw-w64-ucrt-x86_64-bc
|
||||||
|
mingw-w64-ucrt-x86_64-nasm
|
||||||
|
mingw-w64-ucrt-x86_64-yasm
|
||||||
|
mingw-w64-ucrt-x86_64-ccache
|
||||||
|
mingw-w64-ucrt-x86_64-rustup
|
||||||
|
mingw-w64-ucrt-x86_64-cargo-c
|
||||||
|
mingw-w64-ucrt-x86_64-perl
|
||||||
|
mingw-w64-ucrt-x86_64-perl-modules
|
||||||
)
|
)
|
||||||
# pip install pipx
|
|
||||||
# pipx install virtualenv
|
|
||||||
|
|
||||||
|
if is_windows; then
|
||||||
|
local pkg_mgr='msys_ucrt'
|
||||||
|
fi
|
||||||
local req_pkgs_env_name="${pkg_mgr/-/_}_pkgs"
|
local req_pkgs_env_name="${pkg_mgr/-/_}_pkgs"
|
||||||
declare -n req_pkgs="${req_pkgs_env_name}"
|
declare -n req_pkgs="${req_pkgs_env_name}"
|
||||||
local sorted_req_pkgs=($(printf '%s\n' "${req_pkgs[@]}" | sort -u))
|
local sorted_req_pkgs=($(printf '%s\n' "${req_pkgs[@]}" | sort -u))
|
||||||
@@ -130,8 +163,11 @@ check_for_req_pkgs() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo_pass "packages from ${pkg_mgr} installed"
|
echo_pass "packages from ${pkg_mgr} installed"
|
||||||
|
has_cmd pipx || echo_if_fail python3 -m pip install --user pipx || return 1
|
||||||
|
has_cmd pipx || echo_if_fail python3 -m pipx ensurepath && source ~/.bashrc || return 1
|
||||||
echo_if_fail pipx install virtualenv || return 1
|
echo_if_fail pipx install virtualenv || return 1
|
||||||
echo_if_fail pipx ensurepath || return 1
|
echo_if_fail pipx ensurepath || return 1
|
||||||
|
has_cmd meson || echo_if_fail pipx install meson || return 1
|
||||||
echo_pass "pipx is installed"
|
echo_pass "pipx is installed"
|
||||||
|
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
@@ -140,7 +176,7 @@ check_for_req_pkgs() {
|
|||||||
if missing_cmd cargo; then
|
if missing_cmd cargo; then
|
||||||
if missing_cmd rustup; then
|
if missing_cmd rustup; then
|
||||||
echo_warn "installing rustup"
|
echo_warn "installing rustup"
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
grep -q 'source "${HOME}/.cargo/env"' "${HOME}/.bashrc" ||
|
grep -q 'source "${HOME}/.cargo/env"' "${HOME}/.bashrc" ||
|
||||||
echo 'source "${HOME}/.cargo/env"' >>"${HOME}/.bashrc"
|
echo 'source "${HOME}/.cargo/env"' >>"${HOME}/.bashrc"
|
||||||
@@ -149,10 +185,7 @@ check_for_req_pkgs() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo_if_fail rustup default stable || return 1
|
has_cmd cargo-cbuild || echo_if_fail cargo install cargo-c || return 1
|
||||||
echo_if_fail rustup update stable || return 1
|
|
||||||
echo_pass "rustup is installed"
|
|
||||||
echo_if_fail cargo install cargo-c || return 1
|
|
||||||
echo_pass "cargo-c is installed"
|
echo_pass "cargo-c is installed"
|
||||||
echo_pass "all required packages installed"
|
echo_pass "all required packages installed"
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
check_for_package_cfg() {
|
check_for_package_cfg() {
|
||||||
local requiredCfg='ON:ON:3'
|
local requiredCfg='ON:ON:ON:3'
|
||||||
local currentCfg="${STATIC}:${LTO}:${OPT}"
|
local currentCfg="${STATIC}:${LTO}:${PGO}:${OPT}"
|
||||||
if [[ ${currentCfg} == "${requiredCfg}" ]]; then
|
if [[ ${currentCfg} == "${requiredCfg}" ]]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@@ -14,12 +14,10 @@ FB_FUNC_NAMES+=('package')
|
|||||||
FB_FUNC_DESCS['package']='package ffmpeg build'
|
FB_FUNC_DESCS['package']='package ffmpeg build'
|
||||||
package() {
|
package() {
|
||||||
local pkgDir="${IGN_DIR}/package"
|
local pkgDir="${IGN_DIR}/package"
|
||||||
test -d "${pkgDir}" && rm -rf "${pkgDir}"
|
recreate_dir "${pkgDir}" || return 1
|
||||||
check_for_package_cfg || return 0
|
check_for_package_cfg || return 0
|
||||||
|
|
||||||
echo_info "packaging"
|
echo_info "packaging"
|
||||||
mkdir "${pkgDir}" || return 1
|
|
||||||
|
|
||||||
set_compile_opts || return 1
|
set_compile_opts || return 1
|
||||||
cp "${PREFIX}/bin/ff"* "${pkgDir}/"
|
cp "${PREFIX}/bin/ff"* "${pkgDir}/"
|
||||||
|
|
||||||
|
|||||||
60
lib/pgo.sh
Normal file
60
lib/pgo.sh
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
PGO_DIR="${IGN_DIR}/pgo"
|
||||||
|
PGO_PROFDATA="${PGO_DIR}/prof.profdata"
|
||||||
|
gen_profdata() {
|
||||||
|
recreate_dir "${PGO_DIR}" || return 1
|
||||||
|
cd "${PGO_DIR}" || return 1
|
||||||
|
setup_pgo_clips || return 1
|
||||||
|
for vid in *.mkv; do
|
||||||
|
local args=()
|
||||||
|
# add precalculated grain amount based off of filename
|
||||||
|
line_contains "${vid}" 'grain' && args+=(-g 16)
|
||||||
|
# make fhd preset 2
|
||||||
|
line_contains "${vid}" 'fhd' && args+=(-P 2)
|
||||||
|
|
||||||
|
echo_info "encoding pgo vid: ${vid}"
|
||||||
|
LLVM_PROFILE_FILE="${PGO_DIR}/default_%p.profraw" \
|
||||||
|
echo_if_fail encode -i "${vid}" "${args[@]}" "encoded-${vid}" || return 1
|
||||||
|
done
|
||||||
|
|
||||||
|
# merge profraw into profdata
|
||||||
|
local mergeCmd=()
|
||||||
|
# darwin needs special invoke
|
||||||
|
if is_darwin; then
|
||||||
|
mergeCmd+=(xcrun)
|
||||||
|
fi
|
||||||
|
|
||||||
|
mergeCmd+=(
|
||||||
|
llvm-profdata
|
||||||
|
merge
|
||||||
|
"--output=${PGO_PROFDATA}"
|
||||||
|
)
|
||||||
|
"${mergeCmd[@]}" default*.profraw || return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_pgo_clips() {
|
||||||
|
local clips=(
|
||||||
|
"fhd-grainy.mkv 1080p,grain=yes"
|
||||||
|
"uhd.mkv 2160p"
|
||||||
|
"uhd-hdr.mkv 2160p,hdr=yes"
|
||||||
|
)
|
||||||
|
for clip in "${clips[@]}"; do
|
||||||
|
local genVid genVidArgs pgoFile genVidArgsArr
|
||||||
|
IFS=' ' read -r genVid genVidArgs <<<"${clip}"
|
||||||
|
# pgo path is separate
|
||||||
|
pgoFile="${PGO_DIR}/${genVid}"
|
||||||
|
genVid="${TMP_DIR}/${genVid}"
|
||||||
|
# create array of args split with ,
|
||||||
|
genVidArgsArr=(${genVidArgs//,/ })
|
||||||
|
# create generated vid without any profiling if needed
|
||||||
|
test -f "${genVid}" ||
|
||||||
|
LLVM_PROFILE_FILE='/dev/null' gen_video "${genVid}" "${genVidArgsArr[@]}" || return 1
|
||||||
|
# and move to the pgo directory
|
||||||
|
test -f "${pgoFile}" ||
|
||||||
|
cp "${genVid}" "${pgoFile}" || return 1
|
||||||
|
|
||||||
|
done
|
||||||
|
}
|
||||||
130
lib/readme.sh
130
lib/readme.sh
@@ -1,22 +1,148 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
make_bullet_points() {
|
||||||
|
for arg in "$@"; do
|
||||||
|
echo "- ${arg}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_function_info() {
|
||||||
|
local funcName="$1"
|
||||||
|
echo "${FB_FUNC_DESCS[${funcName}]} using \`./scripts/${funcName}.sh\`"
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_compile_opts_info() {
|
||||||
|
for opt in "${FB_COMP_OPTS[@]}"; do
|
||||||
|
declare -n defOptVal="DEFAULT_${opt}"
|
||||||
|
echo "- \`${opt}\`: ${FB_COMP_OPTS_DESC[${opt}]} (default: ${defOptVal})"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
FB_FUNC_NAMES+=('gen_readme')
|
FB_FUNC_NAMES+=('gen_readme')
|
||||||
FB_FUNC_DESCS['gen_readme']='generate project README.md'
|
FB_FUNC_DESCS['gen_readme']='generate project README.md'
|
||||||
gen_readme() {
|
gen_readme() {
|
||||||
local readme="${REPO_DIR}/README.md"
|
local readme="${REPO_DIR}/README.md"
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
A collection of scripts for building ffmpeg and encoding content with the built ffmpeg
|
# ffmpeg-builder
|
||||||
|
A collection of scripts for building \`ffmpeg\` and encoding content with the built \`ffmpeg\`.
|
||||||
|
|
||||||
Tested on:
|
Tested on:
|
||||||
- linux x86_64/aarch64 on:
|
- linux x86_64/aarch64 on:
|
||||||
$(printf ' - %s\n' "${VALID_DOCKER_IMAGES[@]}")
|
$(printf ' - %s\n' "${VALID_DOCKER_IMAGES[@]}")
|
||||||
- darwin aarch64
|
- darwin aarch64
|
||||||
|
|
||||||
|
With these scripts you can:
|
||||||
|
1. $(gen_function_info install_deps)
|
||||||
|
2. $(gen_function_info build)
|
||||||
|
3. $(gen_function_info encode)
|
||||||
|
4. $(gen_function_info efg)
|
||||||
|
|
||||||
|
# Building
|
||||||
|
This project supports multiple ways to build.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
Configuration is done through environment variables.
|
||||||
|
By default, this project will build a static \`ffmpeg\` binary in \`./gitignore/sysroot/bin/ffmpeg\`.
|
||||||
|
The default enabled libraries included in the \`ffmpeg\` build are:
|
||||||
|
$(make_bullet_points ${DEFAULT_ENABLE})
|
||||||
|
|
||||||
|
The user-overridable compile options are:
|
||||||
|
$(gen_compile_opts_info)
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
- only build libsvtav1_psy and libopus: \`ENABLE='libsvtav1_psy libopus' ./scripts/build.sh\`
|
||||||
|
- build shared libraries in custom path: \`PREFIX=/usr/local STATIC=OFF ./scripts/build.sh\`
|
||||||
|
- build without LTO at O1: \`LTO=OFF OPT=1 ./scripts/build.sh\`
|
||||||
|
|
||||||
|
### Native build
|
||||||
|
Make sure to $(gen_function_info install_deps). Then $(gen_function_info build).
|
||||||
|
|
||||||
|
### Docker build
|
||||||
|
1. choose a given distro from: \`${VALID_DOCKER_IMAGES[*]}\`.
|
||||||
|
2. $(gen_function_info docker_build_image) \`<distro>\`.
|
||||||
|
3. $(gen_function_info docker_run_image) \`<distro>\` \`./scripts/build.sh\`
|
||||||
|
|
||||||
|
Docker builds support the same configuration options as native builds. For example to build \`ffmpeg\` on ubuntu with only \`libdav1d\` enabled:
|
||||||
\`\`\`bash
|
\`\`\`bash
|
||||||
$(COLOR=OFF print_cmds)
|
./scripts/docker_build_image.sh ubuntu
|
||||||
|
ENABLE='libdav1d' ./scripts/docker_run_image.sh ubuntu ./scripts/build.sh
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
|
# Encoding scripts
|
||||||
|
The encoding scripts are designed to be installed to system paths for re-use via symbolic links back to this repo using the \`-I\` flag.
|
||||||
|
|
||||||
|
## Encoding with svtav1-psy and opus
|
||||||
|
\`\`\`bash
|
||||||
|
$(encode)
|
||||||
|
\`\`\`
|
||||||
|
- Uses svtav1-psy for the video encoder.
|
||||||
|
- Uses libopus for the audio encoder.
|
||||||
|
- Skips re-encoding av1/opus streams.
|
||||||
|
- Only maps audio streams that match the video stream language if the video stream has a defined language.
|
||||||
|
- Only maps english subtitle streams.
|
||||||
|
- Adds track statistics to the output mkv file and embeds the encoder versions to the output metadata. For example:
|
||||||
|
\`\`\`
|
||||||
|
ENCODE : aa4d7e6
|
||||||
|
FFMPEG : 8.0
|
||||||
|
LIBOPUS : 1.5.2
|
||||||
|
LIBSVTAV1_PSY : 3.0.2-B
|
||||||
|
SVTAV1_PARAMS : film-grain=8:film-grain-denoise=1:tune=0:...
|
||||||
|
VIDEO_PARAMS : -crf 25 -preset 3 -g 240
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
- standard usage: \`encode -i input.mkv output.mkv\`
|
||||||
|
- print out what will be executed without starting encoding: \`encode -i input.mkv -p\`
|
||||||
|
- encode with film-grain synthesis value of 20 with denoising: \`encode -g 20 -i input.mkv\`
|
||||||
|
|
||||||
|
## Estimate film-grain
|
||||||
|
\`\`\`bash
|
||||||
|
$(efg)
|
||||||
|
\`\`\`
|
||||||
|
- Provides a way to estimate the ideal film-grain amount by encoding from low-high given values and the step amount.
|
||||||
|
- Observing the point of diminishing returns, one can make an informed decision for a given film-grain value to choose.
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
- \`efg -i input.mkv -p\`
|
||||||
|
\`\`\`
|
||||||
|
10000 +------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
| **G* + + + + + |
|
||||||
|
| ** "/Volumes/External/ffmpeg-builder/gitignore/tmp/efg-matrix-reloaded.mkv/plot.dat" ***G*** |
|
||||||
|
| *G** |
|
||||||
|
| **G |
|
||||||
|
9000 |-+ ** +-|
|
||||||
|
| *G** |
|
||||||
|
| **G |
|
||||||
|
| ** |
|
||||||
|
| *G* |
|
||||||
|
8000 |-+ ** +-|
|
||||||
|
| *G** |
|
||||||
|
| **G |
|
||||||
|
| ** |
|
||||||
|
| *G** |
|
||||||
|
7000 |-+ **G* +-|
|
||||||
|
| ** |
|
||||||
|
| *G* |
|
||||||
|
| **G** |
|
||||||
|
6000 |-+ **G* +-|
|
||||||
|
| ** |
|
||||||
|
| *G* |
|
||||||
|
| **G** |
|
||||||
|
| **G* |
|
||||||
|
5000 |-+ **G** +-|
|
||||||
|
| **G****G* |
|
||||||
|
| **G** |
|
||||||
|
| **G****G* |
|
||||||
|
| **G****G* |
|
||||||
|
4000 |-+ **G****G****G* +-|
|
||||||
|
| **G****|
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
| + + + + + |
|
||||||
|
3000 +------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
0 5 10 15 20 25 30
|
||||||
|
\`\`\`
|
||||||
" >"${readme}"
|
" >"${readme}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
321
lib/utils.sh
321
lib/utils.sh
@@ -1,321 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
|
|
||||||
# ANSI colors
|
|
||||||
RED='\e[0;31m'
|
|
||||||
CYAN='\e[0;36m'
|
|
||||||
GREEN='\e[0;32m'
|
|
||||||
YELLOW='\e[0;33m'
|
|
||||||
NC='\e[0m'
|
|
||||||
|
|
||||||
# echo wrappers
|
|
||||||
echo_wrapper() {
|
|
||||||
local args
|
|
||||||
if [[ $1 == '-n' ]]; then
|
|
||||||
args=("$1")
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
# 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_info() { color="${CYAN}" word="INFO" echo_wrapper "$@"; }
|
|
||||||
echo_pass() { color="${GREEN}" word="PASS" echo_wrapper "$@"; }
|
|
||||||
echo_warn() { color="${YELLOW}" word="WARN" echo_wrapper "$@"; }
|
|
||||||
echo_exit() {
|
|
||||||
echo_fail "$@"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
void() { echo "$@" >/dev/null; }
|
|
||||||
|
|
||||||
echo_if_fail() {
|
|
||||||
local cmd=("$@")
|
|
||||||
local logName="${LOGNAME:-${RANDOM}}-"
|
|
||||||
local out="${TMP_DIR}/${logName}stdout"
|
|
||||||
local err="${TMP_DIR}/${logName}stderr"
|
|
||||||
|
|
||||||
# set trace to the cmdEvalTrace and open file descriptor
|
|
||||||
local cmdEvalTrace="${TMP_DIR}/${logName}cmdEvalTrace"
|
|
||||||
test -d "${TMP_DIR}" || mkdir -p "${TMP_DIR}"
|
|
||||||
exec 5>"${cmdEvalTrace}"
|
|
||||||
export BASH_XTRACEFD=5
|
|
||||||
|
|
||||||
set -x
|
|
||||||
"${cmd[@]}" >"${out}" 2>"${err}"
|
|
||||||
local retval=$?
|
|
||||||
|
|
||||||
# unset and close file descriptor
|
|
||||||
set +x
|
|
||||||
exec 5>&-
|
|
||||||
|
|
||||||
# parse out relevant part of the trace
|
|
||||||
local cmdEvalLines=()
|
|
||||||
cmd=()
|
|
||||||
while IFS= read -r line; do
|
|
||||||
cmdEvalLines+=("${line}")
|
|
||||||
done <"${cmdEvalTrace}"
|
|
||||||
local cmdEvalLineNum=${#cmdEvalLines[@]}
|
|
||||||
for ((i = 1; i < cmdEvalLineNum - 2; i++)); do
|
|
||||||
local trimmedCmd="${cmdEvalLines[${i}]}"
|
|
||||||
trimmedCmd="${trimmedCmd/+ /}"
|
|
||||||
cmd+=("${trimmedCmd}")
|
|
||||||
done
|
|
||||||
|
|
||||||
if ! test ${retval} -eq 0; then
|
|
||||||
echo
|
|
||||||
echo_fail "command failed:"
|
|
||||||
printf "%s\n" "${cmd[@]}"
|
|
||||||
echo_warn "command output:"
|
|
||||||
tail -n 10 "${out}"
|
|
||||||
tail -n 10 "${err}"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
if [[ -z ${LOGNAME} ]]; then
|
|
||||||
rm "${out}" "${err}" "${cmdEvalTrace}"
|
|
||||||
fi
|
|
||||||
return ${retval}
|
|
||||||
}
|
|
||||||
|
|
||||||
is_root_owned() {
|
|
||||||
local path=$1
|
|
||||||
local uid
|
|
||||||
|
|
||||||
if stat --version >/dev/null 2>&1; then
|
|
||||||
# GNU coreutils (Linux)
|
|
||||||
uid=$(stat -c '%u' "$path")
|
|
||||||
else
|
|
||||||
# BSD/macOS
|
|
||||||
uid=$(stat -f '%u' "$path")
|
|
||||||
fi
|
|
||||||
|
|
||||||
test "$uid" -eq 0
|
|
||||||
}
|
|
||||||
|
|
||||||
dump_arr() {
|
|
||||||
arr_name="$1"
|
|
||||||
declare -n arr
|
|
||||||
arr="${arr_name}"
|
|
||||||
arr_exp=("${arr[@]}")
|
|
||||||
test "${#arr_exp}" -gt 0 || return 0
|
|
||||||
echo
|
|
||||||
echo_info "${arr_name}"
|
|
||||||
printf "\t%s\n" "${arr_exp[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
has_cmd() {
|
|
||||||
local cmds=("$@")
|
|
||||||
local rv=0
|
|
||||||
for cmd in "${cmds[@]}"; do
|
|
||||||
command -v "${cmd}" >/dev/null 2>&1 || rv=1
|
|
||||||
done
|
|
||||||
|
|
||||||
return ${rv}
|
|
||||||
}
|
|
||||||
|
|
||||||
missing_cmd() {
|
|
||||||
local cmds=("$@")
|
|
||||||
local rv=1
|
|
||||||
for cmd in "${cmds[@]}"; do
|
|
||||||
if ! has_cmd "${cmd}"; then
|
|
||||||
echo_warn "missing ${cmd}"
|
|
||||||
rv=0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
return ${rv}
|
|
||||||
}
|
|
||||||
|
|
||||||
bash_dirname() {
|
|
||||||
local tmp=${1:-.}
|
|
||||||
|
|
||||||
[[ $tmp != *[!/]* ]] && {
|
|
||||||
printf '/\n'
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp=${tmp%%"${tmp##*[!/]}"}
|
|
||||||
|
|
||||||
[[ $tmp != */* ]] && {
|
|
||||||
printf '.\n'
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp=${tmp%/*}
|
|
||||||
tmp=${tmp%%"${tmp##*[!/]}"}
|
|
||||||
|
|
||||||
printf '%s\n' "${tmp:-/}"
|
|
||||||
}
|
|
||||||
|
|
||||||
bash_basename() {
|
|
||||||
local tmp
|
|
||||||
path="$1"
|
|
||||||
suffix="${2:-''}"
|
|
||||||
|
|
||||||
tmp=${path%"${path##*[!/]}"}
|
|
||||||
tmp=${tmp##*/}
|
|
||||||
tmp=${tmp%"${suffix/"$tmp"/}"}
|
|
||||||
|
|
||||||
printf '%s\n' "${tmp:-/}"
|
|
||||||
}
|
|
||||||
|
|
||||||
bash_realpath() {
|
|
||||||
local file=$1
|
|
||||||
local dir
|
|
||||||
|
|
||||||
# If the file is already absolute
|
|
||||||
[[ $file == /* ]] && {
|
|
||||||
printf '%s\n' "$file"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# Otherwise: split into directory + basename
|
|
||||||
dir="$(bash_dirname "${file}")"
|
|
||||||
file="$(bash_basename "${file}")"
|
|
||||||
|
|
||||||
# If no directory component, use current directory
|
|
||||||
if [[ $dir == "$file" ]]; then
|
|
||||||
dir="$PWD"
|
|
||||||
else
|
|
||||||
# Save current dir, move into target dir, capture $PWD, then return
|
|
||||||
local oldpwd="$PWD"
|
|
||||||
cd "$dir" || return 1
|
|
||||||
dir="$PWD"
|
|
||||||
cd "$oldpwd" || return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s/%s\n' "$dir" "$file"
|
|
||||||
}
|
|
||||||
|
|
||||||
line_contains() {
|
|
||||||
local line="$1"
|
|
||||||
local substr="$2"
|
|
||||||
if [[ $line == *"${substr}"* ]]; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
line_starts_with() {
|
|
||||||
local line="$1"
|
|
||||||
local substr="$2"
|
|
||||||
if [[ $line == "${substr}"* ]]; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
is_darwin() {
|
|
||||||
line_contains "$(print_os)" darwin
|
|
||||||
}
|
|
||||||
|
|
||||||
print_os() {
|
|
||||||
if [[ -n ${FB_OS} ]]; then
|
|
||||||
echo "${FB_OS}"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
FB_OS=''
|
|
||||||
if [[ -f /etc/os-release ]]; then
|
|
||||||
source /etc/os-release
|
|
||||||
FB_OS="${ID}"
|
|
||||||
if [[ ${VERSION_ID} != '' ]]; then
|
|
||||||
FB_OS+="-${VERSION_ID}"
|
|
||||||
fi
|
|
||||||
if [[ ${FB_OS} == 'arch'* ]]; then
|
|
||||||
FB_OS=archlinux
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
FB_OS="$(uname -o)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${FB_OS,,}"
|
|
||||||
}
|
|
||||||
|
|
||||||
is_positive_integer() {
|
|
||||||
local input="$1"
|
|
||||||
if [[ ${input} != ?(-)+([[:digit:]]) || ${input} -lt 0 ]]; then
|
|
||||||
echo_fail "${input} is not a positive integer"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_line() {
|
|
||||||
local file="$1"
|
|
||||||
local search="$2"
|
|
||||||
local newLine="$3"
|
|
||||||
local newFile="${TMP_DIR}/$(bash_basename "${file}")"
|
|
||||||
|
|
||||||
test -f "${newFile}" && rm "${newFile}"
|
|
||||||
while read -r line; do
|
|
||||||
if line_contains "${line}" "${search}"; then
|
|
||||||
echo -en "${newLine}" >>"${newFile}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
echo "${line}" >>"${newFile}"
|
|
||||||
done <"${file}"
|
|
||||||
|
|
||||||
cp "${newFile}" "${file}"
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_line() {
|
|
||||||
local file="$1"
|
|
||||||
local search="$2"
|
|
||||||
replace_line "${file}" "${search}" ''
|
|
||||||
}
|
|
||||||
|
|
||||||
bash_sort() {
|
|
||||||
local arr=("$@")
|
|
||||||
local n=${#arr[@]}
|
|
||||||
local i j val1 val2
|
|
||||||
|
|
||||||
# Bubble sort, numeric comparison
|
|
||||||
for ((i = 0; i < n; i++)); do
|
|
||||||
for ((j = 0; j < n - i - 1; j++)); do
|
|
||||||
read -r val1 _ <<<"${arr[j]}"
|
|
||||||
read -r val2 _ <<<"${arr[j + 1]}"
|
|
||||||
if (("${val1}" > "${val2}")); then
|
|
||||||
local tmp=${arr[j]}
|
|
||||||
arr[j]=${arr[j + 1]}
|
|
||||||
arr[j + 1]=$tmp
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
printf '%s\n' "${arr[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
spinner() {
|
|
||||||
if [[ $1 == 'reset' ]]; then
|
|
||||||
echo -ne ' \n'
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
local spinChars=(
|
|
||||||
"-"
|
|
||||||
'\'
|
|
||||||
"|"
|
|
||||||
"/"
|
|
||||||
)
|
|
||||||
while true; do
|
|
||||||
for ((ind = 0; ind < "${#spinChars[@]}"; ind++)); do
|
|
||||||
echo -ne "${spinChars[${ind}]}" '\b\b'
|
|
||||||
sleep .25
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
get_pkgconfig_version() {
|
|
||||||
local pkg="$1"
|
|
||||||
pkg-config --modversion "${pkg}"
|
|
||||||
}
|
|
||||||
38
main.sh
38
main.sh
@@ -15,6 +15,24 @@ DOCKER_DIR="${IGN_DIR}/docker"
|
|||||||
PATCHES_DIR="${REPO_DIR}/patches"
|
PATCHES_DIR="${REPO_DIR}/patches"
|
||||||
export REPO_DIR IGN_DIR TMP_DIR DL_DIR BUILD_DIR CCACHE_DIR DOCKER_DIR PATCHES_DIR
|
export REPO_DIR IGN_DIR TMP_DIR DL_DIR BUILD_DIR CCACHE_DIR DOCKER_DIR PATCHES_DIR
|
||||||
|
|
||||||
|
# some functions need a way to signal early
|
||||||
|
# returns instead of failures, so if a function
|
||||||
|
# returns ${FUNC_EXIT_SUCCESS}, stop processing
|
||||||
|
test -v FUNC_EXIT_SUCCESS || readonly FUNC_EXIT_SUCCESS=9
|
||||||
|
|
||||||
|
# make paths if needed
|
||||||
|
IGN_DIRS=(
|
||||||
|
"${TMP_DIR}"
|
||||||
|
"${DL_DIR}"
|
||||||
|
"${BUILD_DIR}"
|
||||||
|
"${CCACHE_DIR}"
|
||||||
|
"${DOCKER_DIR}"
|
||||||
|
)
|
||||||
|
for dir in "${IGN_DIRS[@]}"; do
|
||||||
|
test -d "${dir}" || mkdir -p "${dir}"
|
||||||
|
done
|
||||||
|
unset IGN_DIRS
|
||||||
|
|
||||||
# function names, descriptions, completions
|
# function names, descriptions, completions
|
||||||
unset FB_FUNC_NAMES FB_FUNC_DESCS FB_FUNC_COMPLETION
|
unset FB_FUNC_NAMES FB_FUNC_DESCS FB_FUNC_COMPLETION
|
||||||
FB_FUNC_NAMES=()
|
FB_FUNC_NAMES=()
|
||||||
@@ -38,7 +56,7 @@ src_scripts() {
|
|||||||
export FB_RUNNING_AS_SCRIPT=1
|
export FB_RUNNING_AS_SCRIPT=1
|
||||||
thisFile="$(readlink -f "$0")"
|
thisFile="$(readlink -f "$0")"
|
||||||
export REPO_DIR="$(cd "$(dirname "${thisFile}")/.." && echo "$PWD")"
|
export REPO_DIR="$(cd "$(dirname "${thisFile}")/.." && echo "$PWD")"
|
||||||
source "${REPO_DIR}/main.sh" || return 1
|
source "${REPO_DIR}/main.sh" || exit 1
|
||||||
scr_name="$(bash_basename $0)"
|
scr_name="$(bash_basename $0)"
|
||||||
cmd="${scr_name//.sh/}"
|
cmd="${scr_name//.sh/}"
|
||||||
if [[ $DEBUG == 1 ]]; then set -x; fi
|
if [[ $DEBUG == 1 ]]; then set -x; fi
|
||||||
@@ -56,28 +74,30 @@ 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() {
|
||||||
echo -e "~~~ Usable Commands ~~~\n"
|
echo -e "~~~ Usable Commands ~~~\n"
|
||||||
for funcname in "${FB_FUNC_NAMES[@]}"; do
|
for funcName in "${FB_FUNC_NAMES[@]}"; do
|
||||||
color="${CYAN}" word="${funcname}:" echo_wrapper "\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
|
||||||
done
|
done
|
||||||
echo -e "\n"
|
echo -e "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_completions() {
|
set_completions() {
|
||||||
for funcname in "${FB_FUNC_NAMES[@]}"; do
|
for funcName in "${FB_FUNC_NAMES[@]}"; do
|
||||||
complete -W "${FB_FUNC_COMPLETION[${funcname}]}" "${funcname}"
|
complete -W "${FB_FUNC_COMPLETION[${funcName}]}" "${funcName}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC1091
|
|
||||||
test -f "${HOME}/.bashrc" && source "${HOME}/.bashrc"
|
|
||||||
src_scripts || return 1
|
src_scripts || return 1
|
||||||
determine_pkg_mgr || return 1
|
determine_pkg_mgr || return 1
|
||||||
check_compile_opts_override || return 1
|
check_compile_opts_override || return 1
|
||||||
|
|
||||||
if [[ $FB_RUNNING_AS_SCRIPT -eq 0 ]]; then
|
# set local prefix since some functions need it
|
||||||
|
# as opposed to user-defined PREFIX
|
||||||
|
LOCAL_PREFIX="${IGN_DIR}/$(print_os)_sysroot"
|
||||||
|
|
||||||
|
if [[ ${FB_RUNNING_AS_SCRIPT} -eq 0 ]]; then
|
||||||
print_cmds || return 1
|
print_cmds || return 1
|
||||||
fi
|
fi
|
||||||
set_completions || return 1
|
set_completions || return 1
|
||||||
|
|||||||
11
patches/libmp3lame/fix_lame_init_old_symbol.patch
Normal file
11
patches/libmp3lame/fix_lame_init_old_symbol.patch
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# https://sourceforge.net/p/lame/mailman/message/36081038/
|
||||||
|
diff --git a/include/libmp3lame.sym b/include/libmp3lame.sym
|
||||||
|
index ff7d318..fd120f5 100644
|
||||||
|
--- a/include/libmp3lame.sym
|
||||||
|
+++ b/include/libmp3lame.sym
|
||||||
|
@@ -1,5 +1,4 @@
|
||||||
|
lame_init
|
||||||
|
-lame_init_old
|
||||||
|
lame_set_num_samples
|
||||||
|
lame_get_num_samples
|
||||||
|
lame_set_in_samplerate
|
||||||
24
patches/libvorbis/add-lm-to-pc.patch
Normal file
24
patches/libvorbis/add-lm-to-pc.patch
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
diff --git a/vorbis.pc.in b/vorbis.pc.in
|
||||||
|
index f5ca77d..50cad9e 100644
|
||||||
|
--- a/vorbis.pc.in
|
||||||
|
+++ b/vorbis.pc.in
|
||||||
|
@@ -10,6 +10,6 @@ Description: vorbis is the primary Ogg Vorbis library
|
||||||
|
Version: @VERSION@
|
||||||
|
Requires.private: ogg
|
||||||
|
Conflicts:
|
||||||
|
-Libs: -L${libdir} -lvorbis
|
||||||
|
-Libs.private: @VORBIS_LIBS@
|
||||||
|
+Libs: -L${libdir} -lvorbis
|
||||||
|
+Libs.private: @VORBIS_LIBS@ -lm
|
||||||
|
Cflags: -I${includedir}
|
||||||
|
diff --git a/vorbisenc.pc.in b/vorbisenc.pc.in
|
||||||
|
index a412b7a..4222daf 100644
|
||||||
|
--- a/vorbisenc.pc.in
|
||||||
|
+++ b/vorbisenc.pc.in
|
||||||
|
@@ -10,5 +10,5 @@ Description: vorbisenc is a library that provides a convenient API for setting u
|
||||||
|
Version: @VERSION@
|
||||||
|
Requires.private: vorbis
|
||||||
|
Conflicts:
|
||||||
|
-Libs: -L${libdir} -lvorbisenc
|
||||||
|
+Libs: -L${libdir} -lvorbisenc -lm
|
||||||
|
Cflags: -I${includedir}
|
||||||
13
patches/libvpx/ignore-unknown-configure-options.patch
Normal file
13
patches/libvpx/ignore-unknown-configure-options.patch
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
diff --git a/build/make/configure.sh b/build/make/configure.sh
|
||||||
|
index cc5bf6c..c229965 100644
|
||||||
|
--- a/build/make/configure.sh
|
||||||
|
+++ b/build/make/configure.sh
|
||||||
|
@@ -16,8 +16,6 @@
|
||||||
|
die_unknown(){
|
||||||
|
echo "Unknown option \"$1\"."
|
||||||
|
echo "See $0 --help for available options."
|
||||||
|
- clean_temp_files
|
||||||
|
- exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
die() {
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
export FB_RUNNING_AS_SCRIPT=1
|
export FB_RUNNING_AS_SCRIPT=1
|
||||||
thisFile="$(readlink -f "$0")"
|
thisFile="$(readlink -f "$0")"
|
||||||
export REPO_DIR="$(cd "$(dirname "${thisFile}")/.." && echo "$PWD")"
|
export REPO_DIR="$(cd "$(dirname "${thisFile}")/.." && echo "$PWD")"
|
||||||
source "${REPO_DIR}/main.sh" || return 1
|
source "${REPO_DIR}/main.sh" || exit 1
|
||||||
scr_name="$(bash_basename $0)"
|
scr_name="$(bash_basename $0)"
|
||||||
cmd="${scr_name//.sh/}"
|
cmd="${scr_name//.sh/}"
|
||||||
if [[ $DEBUG == 1 ]]; then set -x; fi
|
if [[ $DEBUG == 1 ]]; then set -x; fi
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ inotifywait -m -r \
|
|||||||
-e close_write \
|
-e close_write \
|
||||||
-e moved_to \
|
-e moved_to \
|
||||||
--format '%w%f' \
|
--format '%w%f' \
|
||||||
"$base/lib" \
|
"${base}/lib" \
|
||||||
"$base/scripts" \
|
"${base}/scripts" \
|
||||||
"$base/main.sh" | while read -r file; do
|
"${base}/main.sh" | while read -r file; do
|
||||||
if [[ -f $file && $file =~ .sh ]]; then
|
if [[ -f $file && $file =~ .sh ]]; then
|
||||||
shfmt --write --simplify "$file"
|
shfmt --indent 4 --write --simplify "${file}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user