Compare commits

...

2 Commits

2 changed files with 59 additions and 42 deletions

View File

@@ -1,24 +1,25 @@
#!/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
@@ -37,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
@@ -68,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() {
@@ -140,7 +153,7 @@ encode_usage() {
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 ${HOME}/"
echo -e "\n\t[-u] update script (git pull at ${REPO_DIR})" echo -e "\n\t[-u] update script (git pull at ${REPO_DIR})"
echo -e "\t[-I] system install at ${ENCODE_INSTALL_PATH}" echo -e "\t[-I] system install at ${ENCODE_INSTALL_PATH}"
@@ -163,7 +176,7 @@ 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
@@ -217,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)
@@ -262,7 +275,7 @@ set_encode_opts() {
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=''
@@ -299,6 +312,9 @@ set_encode_opts() {
gen_encode_script() { gen_encode_script() {
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
@@ -337,7 +353,7 @@ gen_encode_script() {
# arrays # arrays
local arrays=( local arrays=(
unmap unmapStreams
audioParams audioParams
videoParams videoParams
metadata metadata
@@ -348,28 +364,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
@@ -378,19 +408,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}'

View File

@@ -89,7 +89,7 @@ print_req_pkgs() {
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 ninja binutils ninja ndk-multilib-native-static
) )
local req_pkgs_env_name="${pkg_mgr/-/_}_pkgs" local req_pkgs_env_name="${pkg_mgr/-/_}_pkgs"