#!/usr/bin/env bash usage() { cat - < -h|--help: show this help message -i|--input: file name for input -o|--output: base file name for one million artifacts, do not include file extension -k|--keep: keep artifacts -v|--verify: verify stream with Dolby Vision toolkit, default disabled -a|--audio: transcode source audio to specified codec (opus, aac, flac) --denoise: pass denoise flag to encode script(s) [av1, hevc, all (default)] --x265crf: set an alternate x265 crf (default: 16) --x265preset: set an alternate x265 preset (default: medium) --x265tune: set an alternate x265 tune (default: none) --x265params: a string of parameters to pass to x265 --svtcrf: set an alternate svt-av1 crf (default: 22) --svtpreset: set an alternate svt-av1 preset (default: 7) --svttune: set an alternate svt-av1 tune (default: 3) --svtfilmgrain: engage svt-av1 grain analysis/reconstruction --svtmldefaults: when using a fork, force mainline svt-av1 defaults --svtparams: a string of parameters to pass to svt-av1 --av1: HIGHLY EXPERIMENTAL SUPPORT FOR AV1 --dual: Run both an hevc AND an av1 encode in one pass (more efficient) --crop: crop input video, remove offsets from dovi RPUs (no HDR10+) --no-module: disable loading of visionary module set --debug: print debugging information EOF } HEVC=1 AV1=0 while [ $# -gt 0 ]; do OPT="${1}" case "${OPT}" in -i|--input) shift INPUT="${1}" shift;; -o|--output) shift OUTPUT="${1}" shift;; -k|--keep) KEEP=1 shift;; -v|--verify) VERIFY=1 shift;; --denoise) if [[ $2 == -* ]] || [ -z "$2" ]; then DENOISE="all" else shift DENOISE="$1" fi shift;; --x265crf|--x265-crf) shift X265CRF="${1}" shift;; --x265preset|--x265-preset) shift X265PRESET="${1}" shift;; --x265tune|--x265-tune) shift X265TUNE="${1}" shift;; --x265params|--x265-params) shift X265PARAMS="${1}" shift;; --svtcrf|--svt-crf) shift SVTCRF="${1}" shift;; --svtpreset|--svt-preset) shift SVTPRESET="${1}" shift;; --svttune|--svt-tune) shift SVTTUNE="${1}" shift;; --svtfilmgrain|--svt-film-grain) shift SVTFILMGRAIN=$1 shift;; --svtmldefaults|--svt-ml-defaults) SVTMLDEFAULTS=1 shift;; --svtparams|--svt-params) shift SVTPARAMS="${1}" shift;; -a|--audio) shift AUDIO="${1}" shift;; --av1) AV1=1 HEVC=0 shift;; --dual) AV1=1 shift;; --crop) CROP=1 shift;; --no-module) NOMODULERESTORE=1 shift;; --debug) DEBUG=1 shift;; -h|--help) usage exit;; *) echo "${0}: invalid option ${1}" usage exit 1;; esac done # Check for tool dependencies SELF_FULLPATH=`realpath ${0}` SELF_DIR=`dirname ${SELF_FULLPATH}` [ ${NOMODULERESTORE:-0} -eq 0 ] && MODULE_COLLECTION="visionary" TOOLS=(mkvmerge mkvextract mediainfo grep awk dovi_tool hdr10plus_tool jq mkfifo base64 ffprobe ffmpeg SvtAv1EncApp sed bc column) [ ${VERIFY:-0} -eq 1 ] && TOOLS+=(dvesverifier) SCRIPTS=(hevcmeup2 av1meup2 striptags stripcovers addstats cropfinder) [ -n "${AUDIO}" ] && SCRIPTS+=(audiovise) if [ ! -r ${SELF_DIR}/toolchecker ]; then echo "toolchecker not found." exit 1 else . ${SELF_DIR}/toolchecker fi echo ">> visionary: Dolby Vision/HDR10+ Aware Transcoding" echo ## validate something was even provided for input if [ -z "${INPUT}" ]; then echo "No input file provided." usage exit 1 fi if [ -z "${OUTPUT}" ]; then echo "No output file base name provided." echo "Building output file base name from input file name..." OUTPUT=$(echo "${INPUT}" | sed -e 's/.\(mkv\|mp4\|ts\)/_visionary/g') echo "Output file name base: ${OUTPUT}" else [[ "${OUTPUT##*.}" == "mkv" ]] && OUTPUT="${OUTPUT%.*}" fi if [ ${AV1} -eq 1 ]; then ## figure out which fork/version of SVT-AV1 we're dealing with SVTAV1_VERSION_STR=$(${SVTAV1ENCAPP} --version) case "${SVTAV1_VERSION_STR}" in *"PSYEX"*) SVTAV1_FORK="PSYEX"; AV1_DOVI_SUPPORT=1;; *"PSY"*) SVTAV1_FORK="PSY"; AV1_DOVI_SUPPORT=1;; *"HDR"*) SVTAV1_FORK="HDR"; AV1_DOVI_SUPPORT=1;; *) SVTAV1_FORK="mainline"; AV1_DOVI_SUPPORT=0;; esac SVTAV1_VERSION=$(echo "${SVTAV1_VERSION_STR}" | head -n1 | awk '{print $2}' | sed 's/^v//g') SVTAV1_MAJOR=$(echo ${SVTAV1_VERSION} | awk -F. '{print $1}') SVTAV1_MINOR=$(echo ${SVTAV1_VERSION} | awk -F. '{print $2}') SVTAV1_PATCH=$(echo ${SVTAV1_VERSION} | awk -F. '{print $3}') if [ ${AV1_DOVI_SUPPORT:-0} -eq 0 ]; then echo "This script requires a compatible fork for Dolby Vision AV1 encoding." echo "One of: SVT-AV1-PSY, SVT-AV1-PSYEX, SVT-AV1-HDR" echo "Your SVT-AV1 version string:" echo "---------------------------" echo "${SVTAV1_VERSION_STR}" exit 1 fi fi if [ -n "$DENOISE" ] &>/dev/null; then case "$DENOISE" in "x265"|"hevc") DENOISE=hevc;; "av1"|"svt") DENOISE=av1;; "all") DENOISE=all;; *) fail "Unrecognized denoise argument: $DENOISE";; esac fi if [ -n "${SVTFILMGRAIN}" ]; then [ "$SVTFILMGRAIN" -eq "$SVTFILMGRAIN" ] &>/dev/null || fail "Invalid svt-film-grain argument: $SVTFILMGRAIN" [ "$SVTFILMGRAIN" -gt 50 ] && fail "Invalid svt-film-grain argument: $SVTFILMGRAIN" [ "$SVTFILMGRAIN" -lt 1 ] && fail "Invalid svt-film-grain argument: $SVTFILMGRAIN" fi ## build assorted artifact filenames and make sure they don't exist ## not all of these are used in all cases ## but I don't want to think about it very hard FIFO="${OUTPUT}.fifo" [ -p "${FIFO}" ] && fail "<> Named pipe already exists: ${FIFO}" BL="${OUTPUT}.BL.hevc" [ -f "${BL}" ] && fail "<> Base-layer file already exists: ${BL}" BL10P="${OUTPUT}.BL10P.hevc" [ -f "${BL10P}" ] && fail "<> HDR10+ base layer already exists: ${BL10P}" EL="${OUTPUT}.EL.hevc" [ -f "${EL}" ] && fail "<> Enhancement-layer file already exists: ${EL}" RPU="${OUTPUT}.RPU.bin" [ -f "${RPU}" ] && fail "<> RPU file already exists: ${RPU}" RPU_8="${OUTPUT}.RPU_8.bin" [ -f "${RPU_8}" ] && fail "<> Profile 8-compatible RPU file already exists: ${RPU_8}" HDR10P="${OUTPUT}.hdr10p.json" [ -f "${HDR10P}" ] && fail "<> HDR10+ JSON file already exists: ${HDR10P}" BLX265="${OUTPUT}.BL.x265.hevc" [ -f "${BLX265}" ] && fail "<> x265 transcoding destination file already exists: ${BLX265}" WITH_RPU="${OUTPUT}.BL+RPU.x265.hevc" [ -f "${WITH_RPU}" ] && fail "<> Transcoded file with RPU injection already exists: ${WITH_RPU}" AV1_IVF="${OUTPUT}.av1.ivf" [ -f "${AV1_IVF}" ] && fail "<> AV1 output file already exists: ${AV1_IVF}" REMUXED="${OUTPUT}.mkv" [ -f "${REMUXED}" ] && fail "<> Final remux target file already exists: ${REMUXED}" #HDR=$($MEDIAINFO "${INPUT}" | $GREP ^HDR\ format | $AWK -F: '{print $2}') ## Fetch and echo original video metadata because you always want to know and you never know TRACK=$(${MEDIAINFO} --output=JSON "${INPUT}" | ${JQ} -r '.media.track[] | select (."@type"=="Video") | @base64') FPS=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.FrameRate') FPS_NUM=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.FrameRate_Num') FPS_DEN=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.FrameRate_Den') HDRFORMAT=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.HDR_Format') FORMATCOMPAT=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.HDR_Format_Compatibility') DURATION=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.Duration') DURATION_PRETTY=$(printf '%02d:%02d:%02f' $(echo -e "$DURATION/3600\n$DURATION%3600/60\n$DURATION%60"| bc)) FRAME_COUNT=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.FrameCount') BITRATE=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.BitRate') BITRATE_PRETTY="$(echo "scale=2; ${BITRATE} / 1024 / 1024" | ${BC} -l) Mb/s" SIZE=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.StreamSize') SIZE_PRETTY="$(echo "scale=2; ${SIZE} / 1024 / 1024 / 1024" | ${BC} -l) GB" ISDOVI=0 ISHDR10P=0 if [[ "${HDRFORMAT}" =~ "Dolby" ]]; then ISDOVI=1 echo ">> Dolby Vision metadata present" fi if [[ "${FORMATCOMPAT}" =~ "HDR10+" ]]; then ISHDR10P=1 echo ">> HDR10+ metadata present" if [ ${CROP:-0} == 1 ]; then echo "<> Cannot crop with HDR10+" unset CROP fi fi echo let HDRSUM=${ISDOVI}+${ISHDR10P} if [ ${DEBUG:-0} -eq 1 ]; then echo echo "<< VARIABLE STATE:" echo "<< -----------------" for var in INPUT FPS HDRFORMAT FORMATCOMPAT DURATION FRAME_COUNT BITRATE SIZE ISDOVI ISHDR10P HDRSUM OUTPUT HEVC AV1 KEEP VERIFY DENOISE X265CRF X265PRESET X265TUNE X265PARAMS SVTCRF SVTPRESET SVTTUNE SVTFILMGRAIN SVTMLDEFAULTS SVTPARAMS AUDIO CROP SVTAV1_FORK SVTAV1_VERSION FIFO BL BL10P EL RPU RPU_8 HDR10P BLX265 WITH_RPU AV1_IVF REMUXED; do [ -n "${!var}" ] && echo "<< $var,${!var}" || echo "<< $var," done | ${COLUMN} --separator , --table --table-name "VARIABLE STATE" --output-separator " | " echo read -p "<> Press y to encode, any other key to exit..." confirm case $confirm in [Yy] ) true;; * ) exit;; esac fi if [ ${HDRSUM} -eq 0 ]; then fail "<> No dynamic metadata present. What are we even doing here, folks?" fi echo ">> Original stream metadata:" echo " >> fps: ${FPS} (${FPS_NUM}/${FPS_DEN})" echo " >> duration: ${DURATION_PRETTY}" echo " >> frame count: ${FRAME_COUNT}" echo " >> bitrate: ${BITRATE_PRETTY}" echo " >> stream size: ${SIZE_PRETTY}" echo echo ">> Starting Dolby Vision/HDR10+ transcode"; echo echo ">> Making named pipe"; echo set -x ${MKFIFO} "${FIFO}" || fail "<> Named pipe creation failed" { set +x; } 2>/dev/null echo ## Dolby Vision stream prep if [ ${ISDOVI} -eq 1 ]; then DOVIPROFILE=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.HDR_Format_Profile' | ${AWK} '{print $1}') DOVILEVEL=$(echo "${TRACK}" | ${BASE64} --decode | ${JQ} -r '.HDR_Format_Level' | ${AWK} '{print $1}') echo ">> Dolby Vision profile: ${DOVIPROFILE}" echo ">> Dolby Vision level: ${DOVILEVEL}" echo ">> Base layer compatibility: ${FORMATCOMPAT}"; echo case "${DOVIPROFILE}" in "dvhe.05") [ ${DEBUG:-0} -eq 1 ] && echo "<< MEL-type profile 5" echo ">> Cleaning up named pipe"; echo set -x rm "${FIFO}" { set +x; } 2>/dev/null echo fail "<> I'm sorry Dave, I cannot currently encode dolby vision profile 5 content." #echo ">> NOTE: Profile 5 uses non-standard IPT-PQ-C2 colorspace in BL. Colors will not be properly rendered on playback devices that do not support Dolby Vision." ### create stripped base layer #echo ">> Creating stripped base layer"; echo #set -x #${MKVEXTRACT} "${INPUT}" tracks 0:"${FIFO}" & #${DOVI_TOOL} remove --output "${BL}" - <"${FIFO}" || fail "<> Base layer stripping failed." #{ set +x; } 2>/dev/null #echo ### extract the RPU #echo ">> Extracting RPU"; echo #set -x #${MKVEXTRACT} "${INPUT}" tracks 0:"${FIFO}" & #${DOVI_TOOL} --mode 3 extract-rpu --rpu-out "${RPU_8}" - <"${FIFO}" || fail "<> RPU extraction failed." #{ set +x; } 2>/dev/null #echo ;; "dvhe.07") ## since I can't figure out how to preserve a FEL, we're gonna demux the BL and EL and extract the RPU to 8-compatible format [ ${DEBUG:-0} -eq 1 ] && echo "<< FEL-type profile 7" [ ${DEBUG:-0} -eq 1 ] && echo "<< Cannot preserve EL through transcoding, will convert RPU to MEL-compatible profile 8 format" ## demux the layers echo ">> Demuxing layers"; echo set -x ${MKVEXTRACT} "${INPUT}" tracks 0:"${FIFO}" & ${DOVI_TOOL} demux --bl-out "${BL}" --el-out "${EL}" - <"${FIFO}" || fail "<> Demuxing failed." { set +x; } 2>/dev/null echo ## extract the original RPU from the EL ## until I figure out how to preserve a FEL stack, no need for this step, but I'm keeping it in here #[ ${DEBUG:-0} -eq 1 ] && echo "<< Extracting RPU" #${DOVI_TOOL} extract-rpu --input ${EL} --rpu-out ${RPU} ## extract and convert the profile 7 RPU to a profile 8 RPU echo ">> Extracting RPU in profile 8 format"; echo set -x ${DOVI_TOOL} --mode 2 ${CROP:+--crop} extract-rpu --input ${EL} --rpu-out ${RPU_8} || fail "<> RPU extraction failed." { set +x; } 2>/dev/null echo ;; "dvhe.08") ## great news, we're already in profile 8 territory [ ${DEBUG:-0} -eq 1 ] && echo "<< MEL-type profile 8" ## create stripped base layer echo ">> Removing Dolby Vision RPUs from base layer"; echo set -x ${MKVEXTRACT} "${INPUT}" tracks 0:"${FIFO}" & ${DOVI_TOOL} remove --output "${BL}" - <"${FIFO}" || fail "<> Base layer stripping failed." { set +x; } 2>/dev/null echo ## extract the RPU echo ">> Extracting RPU"; echo set -x ${MKVEXTRACT} "${INPUT}" tracks 0:"${FIFO}" & ${DOVI_TOOL} ${CROP:+--crop} extract-rpu --rpu-out "${RPU_8}" - <"${FIFO}" || fail "<> RPU extraction failed." { set +x; } 2>/dev/null echo ;; *) ## not gonna need that fifo after all I guess echo ">> Cleaning up named pipe"; echo set -x rm "${FIFO}" { set +x; } 2>/dev/null echo fail "<> Unrecognized Dolby Vision identifier: ${DOVIPROFILE}";; esac fi ## HDR10+ stream prep if [ ${ISHDR10P} -eq 1 ]; then if [ ! -f "${BL}" ]; then echo ">> Creating HDR10+-free base layer"; echo set -x ${MKVEXTRACT} "${INPUT}" tracks 0:"${FIFO}" & ${HDR10PLUS_TOOL} remove --output "${BL}" - <"${FIFO}" || fail "<> Base layer stripping failed." { set +x; } 2>/dev/null echo echo ">> Extracting HDR10+ metadata"; echo set -x ${MKVEXTRACT} "${INPUT}" tracks 0:"${FIFO}" & ${HDR10PLUS_TOOL} extract -o "${HDR10P}" - <"${FIFO}" || fail "<> HDR10+ extraction failed." { set +x; } 2>/dev/null echo else echo ">> Extracting HDR10+ metadata from existing base layer ${BL}"; echo set -x ${HDR10PLUS_TOOL} extract -o "${HDR10P}" -i "${BL}" || fail "<> HDR10+ extraction failed." { set +x; } 2>/dev/null echo echo ">> Removing HDR10+ metadata from existing base layer"; echo set -x ${HDR10PLUS_TOOL} remove -o "${BL%.hevc}.nohdr10p.hevc" -i "${BL}" || fail "<> HDR10+ extraction failed." rm "${BL}" mv "${BL%.hevc}.nohdr10p.hevc" "${BL}" { set +x; } 2>/dev/null echo fi fi ## we're done with the fifo echo ">> Cleaning up named pipe"; echo set -x rm "${FIFO}" { set +x; } 2>/dev/null echo if [ ${CROP:-0} -eq 1 ]; then [ ${DEBUG:-0} -eq 1 ] && echo ">> finding crop from input file" VFCROP=$($CROPFINDER -i "${INPUT}") fi ## let's cook this sucker echo ">> Starting encode(s)..."; echo if [ ${AV1} -eq 1 ] &>/dev/null; then echo ">> Starting SVT-AV1 encode..." OPTIONS="--input ${BL} --output ${AV1_IVF}" OPTIONS="${OPTIONS} ${SVTCRF:+--crf $SVTCRF} ${SVTPRESET:+--preset $SVTPRESET} ${SVTTUNE:+--tune $SVTTUNE} ${SVTFILMGRAIN:+--film-grain $SVTFILMGRAIN}" if [ "${FPS_NUM}" != "" ] && [ "${FPS_DEN}" != "" ] && [ "${FPS_NUM}" != "null" ] && [ "${FPS_DEN}" != "null" ]; then OPTIONS="${OPTIONS} --fps ${FPS_NUM}/${FPS_DEN}" elif [ "${FPS}" != "" ]; then OPTIONS="${OPTIONS} --fps ${FPS}" else echo "=> Framerate not detected, that's a problem." exit 1 fi [ ${ISDOVI:-0} -eq 1 ] && OPTIONS="${OPTIONS} --rpufile ${RPU_8}" [ ${ISHDR10P:-0} -eq 1 ] && OPTIONS="${OPTIONS} --hdr10pfile ${HDR10P}" [ ${CROP:-0} -eq 1 ] && OPTIONS="${OPTIONS} --vf ${VFCROP}" if [ "${DENOISE}" == "all" ] || [ "${DENOISE}" == "av1" ] || [ "${DENOISE}" == "svt" ]; then OPTIONS="${OPTIONS} --denoise" fi if [ ${SVTMLDEFAULTS:-0} -eq 1 ]; then OPTIONS="${OPTIONS} --ml-defaults" fi if [ "${SVTPARAMS:-"nope"}" != "nope" ]; then OPTIONS="${OPTIONS} --params ${SVTPARAMS}" fi set -x ${AV1MEUP2} ${OPTIONS} || fail "<> Encode failed." { set +x; } 2>/dev/null echo ">> SVT-AV1 encode finished." echo elif [ -n "${SVTPRESET}" ] || [ -n "${SVTTUNE}" ] || [ -n "${SVTCRF}" ]; then echo "=> AV1 not enabled, ignoring AV1-related settings." fi if [ ${HEVC} -eq 1 ] &>/dev/null; then echo ">> Starting X265 encode..." OPTIONS="--input ${BL} --output ${BLX265} ${X265CRF:+--crf $X265CRF} ${X265PRESET:+--preset $X265PRESET} ${X265TUNE:+--tune $X265TUNE}" if [ "${FPS_NUM}" != "" ] && [ "${FPS_DEN}" != "" ] && [ "${FPS_NUM}" != "null" ] && [ "${FPS_DEN}" != "null" ]; then OPTIONS="${OPTIONS} --fps ${FPS_NUM}/${FPS_DEN}" elif [ "${FPS}" != "" ]; then OPTIONS="${OPTIONS} --fps ${FPS}" else echo "=> Framerate not detected, that's a problem." exit 1 fi [ ${ISDOVI} -eq 1 ] && OPTIONS="$OPTIONS --dovi-bl" [ ${CROP} -eq 1 ] && OPTIONS="${OPTIONS} --vf ${VFCROP}" if [ "${DENOISE}" == "all" ] || [ "${DENOISE}" == "x265" ] || [ "${DENOISE}" == "hevc" ]; then OPTIONS="${OPTIONS} --denoise" fi if [ "${X265PARAMS:-"nope"}" != "nope" ]; then OPTIONS="${OPTIONS} --params ${X265PARAMS}" fi set -x ${HEVCMEUP2} ${OPTIONS} || fail "<> Encode failed." { set +x; } 2>/dev/null COOKED="${BLX265}" echo ">> X265 encode finished." ## time to put the sidecars back in the garage ## do HDR10+ injection first, if need be if [ ${ISHDR10P} -eq 1 ]; then echo ">> Injecting HDR10+ metadata into transcoded base layer..."; echo set -x ${HDR10PLUS_TOOL} inject --input ${COOKED} --json ${HDR10P} --output ${BL10P} || fail "<> HDR10+ injection failed." { set +x; } 2>/dev/null echo ">> HDR10+ metadata merged."; echo echo COOKED="${BL10P}" FINALVIDEO_HEVC="${BL10P}" fi ## dovi injection, if need be if [ ${ISDOVI} -eq 1 ]; then echo ">> Injecting Dolby Vision RPU into transcoded BL..."; echo set -x ${DOVI_TOOL} inject-rpu --input ${COOKED} --rpu-in ${RPU_8} --output ${WITH_RPU} || fail "<> RPU injection failed." { set +x; } 2>/dev/null echo ">> Dolby Vision RPU metadata merged."; echo echo ## verify, if requested, you really shouldn't request it tho if [ ${VERIFY:-0} -eq 1 ]; then echo ">> Running Dolby Vision stream verifier"; echo set -x ${DVESVERIFIER} --input ${WITH_RPU} --rpu-compare ${RPU_8} --dv-profile ${DOVIPROFILE#dvhe.0}.${DOVILEVEL#0} --dv-level ${DOVILEVEL#0} --verbose 1 || fail "<> Dolby Vision verification failed." { set +x; } 2>/dev/null echo fi COOKED="${WITH_RPU}" FINALVIDEO_HEVC="${WITH_RPU}" fi fi if [[ "${AUDIO}" =~ (opus|aac|flac) ]]; then echo ">> Transcoding source audio to ${AUDIO}..." OTHERTRACKS="${OUTPUT}_${AUDIO}.mkv" set -x ${AUDIOVISE} -i "${INPUT}" -o ${OTHERTRACKS} --${AUDIO} --novideo { set +x; } 2>/dev/null echo elif [ -n "${AUDIO}" ] ; then echo ">> Audio codec \"${AUDIO}\" not recognized, ignoring" OTHERTRACKS="${INPUT}" else OTHERTRACKS="${INPUT}" fi echo ">> Remuxing transcoded video with other source tracks..."; echo set -x if [ $AV1 -eq 1 ]; then FINAL="${REMUXED/mkv/av1.mkv}" ${MKVMERGE} --output "${FINAL}" "${AV1_IVF}" --no-video "${OTHERTRACKS}" ${STRIPTAGS} "${FINAL}" ${STRIPCOVERS} "${FINAL}" ${ADDSTATS} "${FINAL}" [ $? -eq 0 ] || fail "<> AV1 merge failed." fi if [ $HEVC -eq 1 ]; then FINAL="${REMUXED/mkv/hevc.mkv}" ${MKVMERGE} --output "${FINAL}" "${FINALVIDEO_HEVC}" --no-video "${OTHERTRACKS}" ${STRIPTAGS} "${FINAL}" ${STRIPCOVERS} "${FINAL}" ${ADDSTATS} "${FINAL}" [ $? -eq 0 ] || fail "<> HEVC merge failed." fi { set +x; } 2>/dev/null echo if [ ${KEEP:-0} -eq 1 ]; then echo ">> Preserving intermediate files" else echo ">> Removing intermediate files..."; echo CLEANUP=(${BL} ${EL} ${RPU} ${RPU_8} ${HDR10P} ${BLX265} ${BL10P} ${WITH_RPU} ${FINALVIDEO_HEVC} ${AV1_IVF}) [[ "${OTHERTRACKS}" != "${INPUT}" ]] && CLEANUP+=(${OTHERTRACKS}) for FILE in ${CLEANUP[@]}; do if [ -f "${FILE}" ]; then set -x rm ${FILE} { set +x; } 2>/dev/null fi done fi echo echo ">> Complete"