Advertisement
BuccoBruce

AudioTool MSYS2

Aug 15th, 2022
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 33.14 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3.  
  4. #######
  5. #
  6. #   audiotool.sh [/path/to/input.mkv] [/path/to/output.mkv]
  7. #
  8. #   input.mkv will be the source path & file, while output.mkv will be the output path & file
  9. #
  10. #######
  11.  
  12.  
  13. # Colour text variables
  14.  
  15. R=$(tput setaf 1)
  16. G=$(tput setaf 2)
  17. Y=$(tput setaf 3)
  18. B=$(tput setaf 4)
  19. P=$(tput setaf 5)
  20. C=$(tput setaf 6)
  21. D=$(tput sgr0)
  22. echo
  23.  
  24. # Folder checks, environment, FFmpeg libs, & in/out variables
  25.  
  26. # Set home working directory
  27. HWD=$(echo "$PWD")
  28.  
  29. # Codecs folder checks
  30. if [ -d "$HWD"/Codecs/ ]; then
  31.     cd Codecs/
  32.     CODWD=$(echo "$PWD")
  33.     if [ -z "$(ls ${CODWD})" ]; then
  34.         echo "Directory AudioTool/Codecs/ is ${R}empty${D}!"
  35.         echo "It requires an FFmpeg dependencies folder with .dll files"
  36.         echo
  37.         echo "See README.md for the necessary folder & file structure."
  38.         echo
  39.         exit 1
  40.     else
  41.         :
  42.     fi
  43.    
  44.     # FFmpeg libs checks
  45.     if [ -d $(echo "$CODWD"/*windows*) ]; then
  46.         FFLIBS=$(echo "$CODWD"/*windows*)
  47.         if [ -z "$(ls ${FFLIBS})" ]; then
  48.             echo "Directory AudioTool/Codecs/$(basename "$FFLIBS") is ${R}empty${D}!"
  49.             echo "It requires .dll files"
  50.             echo
  51.             echo "See README.md for the necessary folder & file structure."
  52.             echo
  53.             exit 1
  54.         else
  55.             :
  56.         fi
  57.     else
  58.         echo "FFmpeg dependencies folder ${R}not present${D} in AudioTool/Codecs/"
  59.         echo
  60.         echo "See README.md for the necessary folder & file structure."
  61.         echo
  62.         exit 1
  63.     fi
  64. else
  65.     echo "Directory AudioTool/Codecs/ ${R}does not exist${D}!"
  66.     echo
  67.     echo "See README.md for the necessary folder & file structure."
  68.     echo
  69.     exit 1
  70. fi
  71.  
  72. # Encoder folder checks
  73. if [ -d "$HWD"/Encoder/ ]; then
  74.     cd "$HWD"/Encoder/
  75.     ENCWD=$(echo "$PWD")
  76.     if [ -z "$(ls ${ENCWD})" ]; then
  77.         echo "Directory AudioTool/Encoder/ is ${R}empty${D}!"
  78.         echo "It requires eae-license.txt, EasyAudioEncoder, and a Windows folder with Plex Transcoder and .dll files."
  79.         echo
  80.         echo "See README.md for the necessary folder & file structure."
  81.         echo
  82.         exit 1
  83.     else
  84.         :
  85.     fi
  86.    
  87.     # Windows folder checks
  88.     if [ ! -d "$ENCWD"/Windows/ ]; then
  89.         echo "Directory Windows/ ${R}not present${D} in AudioTool/Encoder/"
  90.         echo
  91.         echo "See README.md for the necessary folder & file structure."
  92.         echo
  93.         exit 1
  94.     else
  95.         if [ -z "$(ls ${ENCWD}/Windows/)" ]; then
  96.             echo "Directory AudioTool/Encoder/Windows/ is ${R}empty${D}!"
  97.             echo "It requires Plex Transcoder.exe and .dll files"
  98.             echo
  99.             echo "See README.md for the necessary folder & file structure."
  100.             echo
  101.             exit 1
  102.         else
  103.             :
  104.         fi
  105.     fi
  106.    
  107.     # eae-license.txt file check
  108.     if [ ! -s "$ENCWD"/eae-license.txt ]; then
  109.         echo "eae-license.txt file ${R}not present${D} in AudioTool/Encoder/"
  110.         echo
  111.         echo "See README.md for the necessary folder & file structure."
  112.         echo
  113.         exit 1
  114.     else
  115.         :
  116.     fi
  117.    
  118.     # EasyAudioEncoder file check
  119.     if [ ! -s "$ENCWD"/EasyAudioEncoder.exe ]; then
  120.         echo "EasyAudioEncoder binary file ${R}not present${D} in AudioTool/Encoder/"
  121.         echo
  122.         echo "See README.md for the necessary folder & file structure."
  123.         echo
  124.         exit 1
  125.     else
  126.         :
  127.     fi
  128.    
  129.     # Plex Transcoder check
  130.     if [ ! -s "$ENCWD"/Windows/Plex\ Transcoder.exe ]; then
  131.         echo "Plex Transcoder binary file ${R}not present${D} in AudioTool/Encoder/Windows/"
  132.         echo
  133.         echo "See README.md for the necessary folder & file structure."
  134.         echo
  135.         exit 1
  136.     else
  137.         :
  138.     fi
  139. else
  140.     echo "Directory AudioTool/Encoder/ ${R}does not exist${D}!"
  141.     echo
  142.     echo "See README.md for the necessary folder & file structure."
  143.     echo
  144.     exit 1
  145. fi
  146. echo "Folder structure/file dependencies check ${G}satisfied${D}!"
  147. echo "Checking for correct input/output values..."
  148. echo
  149. # input and output variables set
  150. INMKV="$1"
  151. OUTMKV="$2"
  152.  
  153. ## Style & tool Functions
  154.  
  155. # Border around text functions
  156.  
  157. border () {
  158.     local str="$*"      # Put all arguments into single string
  159.     local len=${#str}
  160.     local i
  161.     for (( i = 0; i < len + 4; ++i )); do
  162.         printf '='
  163.     done
  164.     printf "\n| %s |\n" "$C""$str""$D"
  165.     for (( i = 0; i < len + 4; ++i )); do
  166.         printf '='
  167.     done
  168.     echo
  169. }
  170.  
  171. border2 () {
  172.     local str="$*"      # Put all arguments into single string
  173.     printf "========================="
  174.     printf "\n> %s\n" "$C""$str""$D"
  175.     printf "========================="
  176.     echo
  177. }
  178.  
  179. # Output audio info function
  180.  
  181. outputinfo () {
  182.     AOUTFORMAT0=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream=codec_name -of default=nw=1:nk=1 "$1")
  183.     AOUTLAYOUT0=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$1")
  184.     AOUTTITLE0=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream_tags=title -of default=nw=1:nk=1 "$1")
  185.     AOUTFORMAT1=$(./ffprobe -hide_banner -loglevel error -select_streams a:1 -show_entries stream=codec_name -of default=nw=1:nk=1 "$1")
  186.     AOUTLAYOUT1=$(./ffprobe -hide_banner -loglevel error -select_streams a:1 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$1")
  187.     AOUTTITLE1=$(./ffprobe -hide_banner -loglevel error -select_streams a:1 -show_entries stream_tags=title -of default=nw=1:nk=1 "$1")
  188.     AOUTFORMAT2=$(./ffprobe -hide_banner -loglevel error -select_streams a:2 -show_entries stream=codec_name -of default=nw=1:nk=1 "$1")
  189.     AOUTLAYOUT2=$(./ffprobe -hide_banner -loglevel error -select_streams a:2 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$1")
  190.     AOUTTITLE2=$(./ffprobe -hide_banner -loglevel error -select_streams a:2 -show_entries stream_tags=title -of default=nw=1:nk=1 "$1")
  191.     AOUTFORMAT3=$(./ffprobe -hide_banner -loglevel error -select_streams a:3 -show_entries stream=codec_name -of default=nw=1:nk=1 "$1")
  192.     AOUTLAYOUT3=$(./ffprobe -hide_banner -loglevel error -select_streams a:3 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$1")
  193.     AOUTTITLE3=$(./ffprobe -hide_banner -loglevel error -select_streams a:3 -show_entries stream_tags=title -of default=nw=1:nk=1 "$1")
  194.     AOUTFORMAT4=$(./ffprobe -hide_banner -loglevel error -select_streams a:4 -show_entries stream=codec_name -of default=nw=1:nk=1 "$1")
  195.     AOUTLAYOUT4=$(./ffprobe -hide_banner -loglevel error -select_streams a:4 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$1")
  196.     AOUTTITLE4=$(./ffprobe -hide_banner -loglevel error -select_streams a:4 -show_entries stream_tags=title -of default=nw=1:nk=1 "$1")
  197.     AOUTFORMAT5=$(./ffprobe -hide_banner -loglevel error -select_streams a:5 -show_entries stream=codec_name -of default=nw=1:nk=1 "$1")
  198.     AOUTLAYOUT5=$(./ffprobe -hide_banner -loglevel error -select_streams a:5 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$1")
  199.     AOUTTITLE5=$(./ffprobe -hide_banner -loglevel error -select_streams a:5 -show_entries stream_tags=title -of default=nw=1:nk=1 "$1")
  200.     AOUTFORMAT6=$(./ffprobe -hide_banner -loglevel error -select_streams a:6 -show_entries stream=codec_name -of default=nw=1:nk=1 "$1")
  201.     AOUTLAYOUT6=$(./ffprobe -hide_banner -loglevel error -select_streams a:6 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$1")
  202.     AOUTTITLE6=$(./ffprobe -hide_banner -loglevel error -select_streams a:6 -show_entries stream_tags=title -of default=nw=1:nk=1 "$1")
  203.  
  204.     echo "Audio information for output file ${P}${1}${D}:"
  205.     echo
  206.     echo "a:0 (first audio track): ${B}${AOUTFORMAT0} ${AOUTLAYOUT0}${D}${AOUTTITLE0}"
  207.     echo "a:1 (second audio track): ${B}${AOUTFORMAT1} ${AOUTLAYOUT1}${D}${AOUTTITLE1}"
  208.     echo "a:2 (third audio track): ${B}${AOUTFORMAT2} ${AOUTLAYOUT2}${D}${AOUTTITLE2}"
  209.     echo "a:3 (fourth audio track): ${B}${AOUTFORMAT3} ${AOUTLAYOUT3}${D}${AOUTTITLE3}"
  210.     echo "a:4 (fifth audio track): ${B}${AOUTFORMAT4} ${AOUTLAYOUT4}${D}${AOUTTITLE4}"
  211.     echo "a:5 (sixth audio track): ${B}${AOUTFORMAT5} ${AOUTLAYOUT5}${D}${AOUTTITLE5}"
  212.     echo "a:6 (seventh audio track): ${B}${AOUTFORMAT6} ${AOUTLAYOUT6}${D}${AOUTTITLE6}"
  213. }
  214.  
  215. # time left progress stats function
  216.  
  217. sec2min()
  218. {
  219.  local S=${1}
  220.  ((h=S/3600))
  221.  ((m=S%3600/60))
  222.  ((s=S%60))
  223.  printf "%dh:%dm:%ds\n" "$h" "$m" "$s"
  224. }
  225.  
  226. sec2hms () {
  227.     num=$1
  228.     min=0
  229.     hour=0
  230.     day=0
  231.     if((num>59));then
  232.         ((sec=num%60))
  233.         ((num=num/60))
  234.         if((num>59));then
  235.             ((min=num%60))
  236.             ((num=num/60))
  237.             if((num>23));then
  238.                 ((hour=num%24))
  239.                 ((day=num/24))
  240.             else
  241.                 ((hour=num))
  242.             fi
  243.         else
  244.             ((min=num))
  245.         fi
  246.     else
  247.         ((sec=num))
  248.     fi
  249.     echo "$day"d "$hour"h "$min"m "$sec"s
  250. }
  251.  
  252. timeleft () {
  253.     currenttime=$(date '+%H:%M:%S')
  254.     currenttimeseconds=$(echo "$currenttime" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
  255.     starttimeseconds=$(head -n 1 "$ENCWD"/out.txt)
  256.     speed=$(tail -n 1 "$ENCWD"/out.txt | sed 's/.*speed=//; s/x.*//')
  257.     elapsed=$(tail -n 1 "$ENCWD"/out.txt | sed 's/.*time=//; s/\..*//')
  258.     sizekb=$(tail -n 1 "$ENCWD"/out.txt | sed 's/.*size=//; s/k.*//')
  259.     if [ ! -z $(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream_tags=duration -of default=nw=1:nk=1 "$INMKV" | sed 's/\..*//') ]
  260.     then
  261.         duration=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream_tags=duration -of default=nw=1:nk=1 "$INMKV" | sed 's/\..*//')
  262.     elif [ ! -z $(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream_tags=duration-eng -of default=nw=1:nk=1 "$INMKV" | sed 's/\..*//') ]
  263.     then
  264.         duration=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream_tags=duration-eng -of default=nw=1:nk=1 "$INMKV" | sed 's/\..*//')
  265.     else
  266.         duration="00:00:00"
  267.     fi 
  268.     durationseconds=$(echo "$duration" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
  269.     timeleftseconds=$(echo "$durationseconds / $speed" | bc)
  270.     timeleftminutes=$(sec2min "$timeleftseconds")
  271.     elapsedseconds=$(echo "$elapsed" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
  272.     durationleftseconds=$(($durationseconds - $elapsedseconds))
  273.     durationleftminutes=$(sec2min "$durationleftseconds")
  274.     endtimeseconds=$(($starttimeseconds + $timeleftseconds))
  275.     timeremainingseconds=$(($endtimeseconds - $currenttimeseconds))
  276.     timeremaininghms=$(sec2min "$timeremainingseconds")
  277.  
  278. #   echo "Stats for Nerds:"
  279. #   echo
  280. #   echo "time at start (seconds): $starttimeseconds"
  281. #   echo "end time (seconds): $endtimeseconds"
  282. #   echo "speed multiplier: $speed"
  283. #   echo "total duration (h:m:s): $duration"
  284. #   echo "total duration (seconds): $durationseconds"
  285. #   echo "current time: $currenttime"
  286. #   echo "current time (seconds): $currenttimeseconds"
  287. #   echo "How long it'll take to encode (seconds): $timeleftseconds"
  288. #   echo "How long it'll take to encode (h:m:s): $timeleftminutes"
  289. #   echo "Duration left to encode (seconds): $durationleftseconds"
  290. #   echo "time left (seconds): $timeremainingseconds"
  291. #   echo "encoded duration so far (seconds): $elapsedseconds"
  292.  
  293.     clear
  294.     border "$1"
  295.     echo
  296.     echo "Audio duration: $duration"
  297.     echo "Duration left to encode: $durationleftminutes"
  298.     echo "Encoded so far: $elapsed"
  299.     echo "Current size: "$(numfmt --from=iec --to=si "$sizekb"K)
  300.     echo "Approximate encode time: $timeleftminutes"
  301.     echo "Time until finished encoding: ${P}$timeremaininghms${D}"
  302. }
  303.  
  304. ## Main Functions
  305.  
  306. # TrueHD 7.1 to eac3 7.1
  307.  
  308. thd () {
  309.     ./EasyAudioEncoder.exe &
  310.     echo "$(echo $(date '+%H:%M:%S') | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')" > "$ENCWD"/out.txt
  311.     (EAE_ROOT="$ENCWD" FFMPEG_EXTERNAL_LIBS="$FFLIBS"/ X_PLEX_TOKEN='xxxxxxxxxxxxxxxxxxxx' ''${ENCWD}'/Windows/Plex Transcoder.exe' \
  312.     '-c:v:0' 'hevc' \
  313.     '-c:a:0' 'truehd_eae' \
  314.     '-noaccurate_seek' \
  315.     '-analyzeduration' '20000000' \
  316.     '-probesize' '20000000' \
  317.     '-i' "$1" \
  318.     '-map' '0:v:0' \
  319.     '-map' '0:a:0' \
  320.     '-c:v:0' 'copy' \
  321.     '-c:a:0' 'copy' \
  322.     '-filter_complex' '[0:a:0] aresample=async=1:ocl='\''7.1'\'':rematrix_maxval=60.000000dB:osr=48000[0]' \
  323.     '-map' '[0]' \
  324.     '-metadata:s:a:1' 'title=EAC3 7.1 from TrueHD' \
  325.     '-metadata:s:a:1' 'language=eng' \
  326.     '-c:a:1' 'eac3_eae' \
  327.     '-b:a:1' '1280k' \
  328.     '-map' '0:a:1?' \
  329.     '-c:a:2' 'copy' \
  330.     '-map' '0:a:2?' \
  331.     '-c:a:3' 'copy' \
  332.     '-map' '0:a:3?' \
  333.     '-c:a:4' 'copy' \
  334.     '-map' '0:a:4?' \
  335.     '-c:a:5' 'copy' \
  336.     '-map' '0:a:5?' \
  337.     '-c:a:6' 'copy' \
  338.     '-map' '0:s?' \
  339.     '-c:s' 'copy' \
  340.     '-start_at_zero' \
  341.     '-copyts' \
  342.     '-vsync' 'cfr' \
  343.     '-avoid_negative_ts' 'disabled' \
  344.     '-v' 'fatal' '-stats' \
  345.     "$2" 2>&1)
  346.     sleep 1
  347.     thdpid=$(ps -ef | grep 'Plex Transcoder.exe -c:v:0 hevc -c:a:0 truehd_eae' | grep -v grep | tr -s ' ' | cut -d ' ' -f3)
  348.     eaepid=$(ps -ef | grep 'EasyAudioEncoder.exe' | grep -v grep | tr -s ' ' | cut -d ' ' -f3)
  349.     trap "kill $thdpid 2> /dev/null" EXIT
  350.     trap "kill $eaepid 2> /dev/null" EXIT  
  351.     while kill -0 $thdpid 2> /dev/null; do
  352.         echo
  353.         timeleft "$3"
  354.         echo
  355.         sleep 2
  356.     done
  357.     trap - EXIT
  358.     echo
  359.     echo "Terminating EasyAudioEncoder..."
  360.     kill $(ps aux | grep -v grep | grep -v findandkill.sh | grep -i 'EasyAudioEncoder.exe' | awk '{print $2}') > /dev/null 2>&1 || { echo "Failed. Either no running process(es) matching 'EasyAudioEncoder', or process(es) $1 belong(s) to root." ; exit 1; }
  361. }
  362.  
  363. # DTS 7.1 to eac3 7.1
  364.  
  365. dts () {
  366.     ./EasyAudioEncoder.exe &
  367.     echo "$(echo $(date '+%H:%M:%S') | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')" > "$ENCWD"/out.txt
  368.     (EAE_ROOT="$ENCWD" FFMPEG_EXTERNAL_LIBS="$FFLIBS"/ X_PLEX_TOKEN='xxxxxxxxxxxxxxxxxxxx' ''${ENCWD}'/Windows/Plex Transcoder.exe' \
  369.     '-c:v:0' 'hevc' \
  370.     '-c:a:0' 'dca' \
  371.     '-noaccurate_seek' \
  372.     '-analyzeduration' '20000000' \
  373.     '-probesize' '20000000' \
  374.     '-i' "$1" \
  375.     '-map' '0:v:0' \
  376.     '-map' '0:a:0' \
  377.     '-c:v:0' 'copy' \
  378.     '-c:a:0' 'copy' \
  379.     '-filter_complex' '[0:a:0] aresample=async=1:ocl='\''7.1'\'':rematrix_maxval=60.000000dB:osr=48000[0]' \
  380.     '-map' '[0]' \
  381.     '-metadata:s:a:1' 'title=EAC3 7.1 from DTS' \
  382.     '-metadata:s:a:1' 'language=eng' \
  383.     '-c:a:1' 'eac3_eae' \
  384.     '-b:a:1' '1280k' \
  385.     '-map' '0:a:1?' \
  386.     '-c:a:2' 'copy' \
  387.     '-map' '0:a:2?' \
  388.     '-c:a:3' 'copy' \
  389.     '-map' '0:a:3?' \
  390.     '-c:a:4' 'copy' \
  391.     '-map' '0:a:4?' \
  392.     '-c:a:5' 'copy' \
  393.     '-map' '0:a:5?' \
  394.     '-c:a:6' 'copy' \
  395.     '-map' '0:s?' \
  396.     '-c:s' 'copy' \
  397.     '-start_at_zero' \
  398.     '-copyts' \
  399.     '-vsync' 'cfr' \
  400.     '-avoid_negative_ts' 'disabled' \
  401.     '-v' 'fatal' '-stats' \
  402.     "$2" 2>&1)
  403.     sleep 1
  404.     dtspid=$(ps -ef | grep 'Plex Transcoder.exe -c:v:0 hevc -c:a:0 dca' | grep -v grep | tr -s ' ' | cut -d ' ' -f3)
  405.     eaepid=$(ps -ef | grep 'EasyAudioEncoder.exe' | grep -v grep | tr -s ' ' | cut -d ' ' -f3)
  406.     trap "kill $dtspid 2> /dev/null" EXIT
  407.     trap "kill $eaepid 2> /dev/null" EXIT  
  408.     while kill -0 $dtspid 2> /dev/null; do
  409.         echo
  410.         timeleft "$3"
  411.         echo
  412.         sleep 2
  413.     done
  414.     trap - EXIT
  415.     echo
  416.     echo "Terminating EasyAudioEncoder..."
  417.     kill $(ps aux | grep -v grep | grep -v findandkill.sh | grep -i 'EasyAudioEncoder' | awk '{print $2}') > /dev/null 2>&1 || { echo "Failed. Either no running process(es) matching 'EasyAudioEncoder', or process(es) $1 belong(s) to root." ; exit 1; }
  418. }
  419.  
  420. # Any to eac3
  421.  
  422. eac3 () {
  423.     echo "$(echo $(date '+%H:%M:%S') | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')" > "$ENCWD"/out.txt
  424.     (ffmpeg \
  425.     '-i' "$1" \
  426.     '-map' '0:v' \
  427.     '-map' '0:a:0' \
  428.     '-map' '0:a' \
  429.     '-map' '0:s?' \
  430.     '-c:v' 'copy' \
  431.     '-c:a' 'copy' \
  432.     '-c:s' 'copy' \
  433.     '-metadata:s:a:1' title='EAC3 640kbps' \
  434.     '-metadata:s:a:1' 'language=eng' \
  435.     '-c:a:1' 'eac3' \
  436.     '-b:a:1' '640k' \
  437.     '-v' 'fatal' '-stats' \
  438.     "$2" 2>&1)
  439.     sleep 1
  440.     eac3pid=$(ps -ef | grep 'EAC3 640kbps -metadata:s:a:1 language' | grep -v grep | tr -s ' ' | cut -d ' ' -f3)
  441.     trap "kill $eac3pid 2> /dev/null" EXIT
  442.     while kill -0 $eac3pid 2> /dev/null; do
  443.         echo
  444.         timeleft "$3"
  445.         echo
  446.         sleep 2
  447.     done
  448.     trap - EXIT
  449. }
  450.  
  451. # Any to ac3
  452.  
  453. ac3 () {
  454.     echo "$(echo $(date '+%H:%M:%S') | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')" > "$ENCWD"/out.txt
  455.     (ffmpeg \
  456.     '-i' "$1" \
  457.     '-map' '0:v' \
  458.     '-map' '0:a:0' \
  459.     '-map' '0:a' \
  460.     '-map' '0:s?' \
  461.     '-c:v' 'copy' \
  462.     '-c:a' 'copy' \
  463.     '-c:s' 'copy' \
  464.     '-metadata:s:a:1' title='AC3 640kbps' \
  465.     '-metadata:s:a:1' 'language=eng' \
  466.     '-c:a:1' 'ac3' \
  467.     '-b:a:1' '640k' \
  468.     '-v' 'fatal' '-stats' \
  469.     "$2" 2>&1)
  470.     sleep 1
  471.     ac3pid=$(ps -ef | grep 'AC3 640kbps -metadata:s:a:1 language' | grep -v grep | tr -s ' ' | cut -d ' ' -f3)
  472.     trap "kill $ac3pid 2> /dev/null" EXIT
  473.     while kill -0 $ac3pid 2> /dev/null; do
  474.         echo
  475.         timeleft "$3"
  476.         echo
  477.         sleep 2
  478.     done
  479.     trap - EXIT
  480. }
  481.  
  482. # Strip audio stream
  483.  
  484. stripstream () {
  485.     echo "$(echo $(date '+%H:%M:%S') | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')" > "$ENCWD"/out.txt
  486.     (ffmpeg \
  487.     '-i' "$1" \
  488.     '-map' '0' \
  489.     '-map' -0:a:"$2" \
  490.     '-c' 'copy' \
  491.     '-v' 'fatal' '-stats' \
  492.     "$3" 2>&1)
  493.     sleep 1
  494.     sspid=$(ps -ef | grep 'map 0 -map -0:a:' | grep -v grep | tr -s ' ' | cut -d ' ' -f3)
  495.     trap "kill $sspid 2> /dev/null" EXIT
  496.     while kill -0 $sspid 2> /dev/null; do
  497.         echo
  498.         timeleft "$4"
  499.         echo
  500.         sleep 2
  501.     done
  502.     trap - EXIT
  503.    
  504. }
  505.  
  506. # Change Input and Output Paths & Files
  507.  
  508. changeinmkv () {
  509.     CHANGEINANS=n
  510.     while [ "$CHANGEINANS" != "y" -o "$CHANGEINANS" != "Y" ];
  511.     do
  512.         read -p "Change input path & file? [y/n]: " CHANGEINANS
  513.         if [ "$CHANGEINANS" = "n" -o "$CHANGEINANS" = "N" ];
  514.         then
  515.             echo
  516.             echo "Input path & file will remain as: ${P}${INMKV}${D}"
  517.             sleep 0.7
  518.             break
  519.         elif [ "$CHANGEINANS" = "y" -o "$CHANGEINANS" = "Y" ];
  520.         then
  521.             FLAG=1
  522.             while [ "$FLAG" != "0" ];
  523.             do
  524.                 echo
  525.                 read -ep "Enter new ${R}absolute${D} path & file for ${P}input${D} (tab completion enabled): " USERINMKV
  526.                 if [ ! -s "$USERINMKV" ]
  527.                 then
  528.                     echo
  529.                     echo "${P}${USERINMKV}${D} ${R}does not exist${D}! Try again."
  530.                     sleep 0.7
  531.                     continue
  532.                 elif [ "$USERINMKV" = "$OUTMKV" ]
  533.                 then
  534.                     echo
  535.                     echo "${P}${USERINMKV}${D} is identical to your output file!"
  536.                     echo "Input and output files cannot be identical, or FFmpeg's encode execution will fail. Try again."
  537.                     sleep 0.7
  538.                     continue
  539.                 elif [ -s "$USERINMKV" ]
  540.                 then
  541.                     INMKV="$USERINMKV"
  542.                     echo
  543.                     echo "Changed input path & file to: ${P}${INMKV}${D}"
  544.                     sleep 0.7
  545.                     FLAG=0
  546.                 fi
  547.             done
  548.             break
  549.         else
  550.             echo "Accepted answers are y or n"
  551.             sleep 0.7
  552.         fi
  553.     done
  554. }
  555.  
  556. changeoutmkv () {
  557.     CHANGEOUTANS=n
  558.     while [ "$CHANGEOUTANS" != "y" -o "$CHANGEOUTANS" != "Y" ];
  559.     do
  560.         read -p "Change output path & file? [y/n]: " CHANGEOUTANS
  561.         if [ "$CHANGEOUTANS" = "n" -o "$CHANGEOUTANS" = "N" ];
  562.         then
  563.             echo
  564.             echo "Output path & file will remain as: ${P}${OUTMKV}${D}"
  565.             sleep 0.7
  566.             break
  567.         elif [ "$CHANGEOUTANS" = "y" -o "$CHANGEOUTANS" = "Y" ];
  568.         then
  569.             FLAG=1
  570.             while [ "$FLAG" != "0" ];
  571.             do
  572.                 echo
  573.                 read -ep "Enter new ${R}absolute${D} path & file for ${P}output${D} (tab completion enabled): " USEROUTMKV
  574.                 if [ "$USEROUTMKV" = "$INMKV" ]
  575.                 then
  576.                     echo
  577.                     echo "${P}${USEROUTMKV}${D} is identical to your input file!"
  578.                     echo "Input and output files cannot be identical, or FFmpeg's encode execution will fail. Try again."
  579.                     sleep 0.7
  580.                     continue
  581.                 elif [ -s "$USEROUTMKV" ]
  582.                 then
  583.                     echo
  584.                     echo "${P}${USEROUTMKV}${D} ${R}already exists${D}, or is a directory! FFmpeg will prompt you to overwite the existing file."
  585.                     echo
  586.                     CHOUTANS=y
  587.                     while [ "$CHOUTANS" != "n" ] && [ "$CHOUTANS" != "N" ];
  588.                     do
  589.                         read -rp "Proceed? [y/n]: " CHOUTANS
  590.                         if [ "$CHOUTANS" = "y" ] || [ "$CHOUTANS" = "Y" ];
  591.                         then
  592.                             OUTMKV="$USEROUTMKV"
  593.                             echo
  594.                             echo "Changed output path & file to: ${P}${OUTMKV}${D}"
  595.                             sleep 0.7
  596.                             FLAG=0
  597.                             break
  598.                         elif [ "$CHOUTANS" = "n" ] || [ "$CHOUTANS" = "N" ];
  599.                         then
  600.                             echo
  601.                             echo "Output not chaged to ${USEROUTMKV}. Try again."
  602.                             sleep 0.7
  603.                         else
  604.                             echo "Accepted answers are y or n check"
  605.                             sleep 0.7
  606.                         fi
  607.                     done
  608.                 elif [ ! -s "$USEROUTMKV" ]
  609.                 then
  610.                     OUTMKV="$USEROUTMKV"
  611.                     echo
  612.                     echo "Changed output path & file to: ${P}${OUTMKV}${D}"
  613.                     sleep 0.7
  614.                     FLAG=0
  615.                 fi
  616.             done
  617.             break
  618.         else
  619.             echo "Accepted answers are y or n"
  620.             sleep 0.7
  621.         fi
  622.     done
  623. }
  624.  
  625. ##########
  626. ## MAIN ##
  627. ##########
  628.  
  629. if [[ $# -eq 2 ]] && [[ -s "$INMKV" ]] && [ ! -s "$OUTMKV" ]; then
  630.     echo "input/output checks ${G}satisfied${D}!"
  631.     echo
  632.  
  633.     while [ "$ANS" != "7" ];
  634.     do
  635.         # input audio info
  636.         AFORMAT0=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream=codec_name -of default=nw=1:nk=1 "$INMKV")
  637.         ALAYOUT0=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$INMKV")
  638.         ATITLE0=$(./ffprobe -hide_banner -loglevel error -select_streams a:0 -show_entries stream_tags=title -of default=nw=1:nk=1 "$INMKV")
  639.         AFORMAT1=$(./ffprobe -hide_banner -loglevel error -select_streams a:1 -show_entries stream=codec_name -of default=nw=1:nk=1 "$INMKV")
  640.         ALAYOUT1=$(./ffprobe -hide_banner -loglevel error -select_streams a:1 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$INMKV")
  641.         ATITLE1=$(./ffprobe -hide_banner -loglevel error -select_streams a:1 -show_entries stream_tags=title -of default=nw=1:nk=1 "$INMKV")
  642.         AFORMAT2=$(./ffprobe -hide_banner -loglevel error -select_streams a:2 -show_entries stream=codec_name -of default=nw=1:nk=1 "$INMKV")
  643.         ALAYOUT2=$(./ffprobe -hide_banner -loglevel error -select_streams a:2 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$INMKV")
  644.         ATITLE2=$(./ffprobe -hide_banner -loglevel error -select_streams a:2 -show_entries stream_tags=title -of default=nw=1:nk=1 "$INMKV")
  645.         AFORMAT3=$(./ffprobe -hide_banner -loglevel error -select_streams a:3 -show_entries stream=codec_name -of default=nw=1:nk=1 "$INMKV")
  646.         ALAYOUT3=$(./ffprobe -hide_banner -loglevel error -select_streams a:3 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$INMKV")
  647.         ATITLE3=$(./ffprobe -hide_banner -loglevel error -select_streams a:3 -show_entries stream_tags=title -of default=nw=1:nk=1 "$INMKV")
  648.         AFORMAT4=$(./ffprobe -hide_banner -loglevel error -select_streams a:4 -show_entries stream=codec_name -of default=nw=1:nk=1 "$INMKV")
  649.         ALAYOUT4=$(./ffprobe -hide_banner -loglevel error -select_streams a:4 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$INMKV")
  650.         ATITLE4=$(./ffprobe -hide_banner -loglevel error -select_streams a:4 -show_entries stream_tags=title -of default=nw=1:nk=1 "$INMKV")
  651.         AFORMAT5=$(./ffprobe -hide_banner -loglevel error -select_streams a:5 -show_entries stream=codec_name -of default=nw=1:nk=1 "$INMKV")
  652.         ALAYOUT5=$(./ffprobe -hide_banner -loglevel error -select_streams a:5 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$INMKV")
  653.         ATITLE5=$(./ffprobe -hide_banner -loglevel error -select_streams a:5 -show_entries stream_tags=title -of default=nw=1:nk=1 "$INMKV")
  654.         AFORMAT6=$(./ffprobe -hide_banner -loglevel error -select_streams a:6 -show_entries stream=codec_name -of default=nw=1:nk=1 "$INMKV")
  655.         ALAYOUT6=$(./ffprobe -hide_banner -loglevel error -select_streams a:6 -show_entries stream=channel_layout -of default=nw=1:nk=1 "$INMKV")
  656.         ATITLE6=$(./ffprobe -hide_banner -loglevel error -select_streams a:6 -show_entries stream_tags=title -of default=nw=1:nk=1 "$INMKV")
  657.    
  658.         # Main Menu
  659.         border "Audio Tool"
  660.         echo
  661.         echo "Audio information for input file ${P}${INMKV}${D}:"
  662.         echo
  663.         echo "a:0 (first audio track): ${B}${AFORMAT0} ${ALAYOUT0}${D}${ATITLE0}"
  664.         echo "a:1 (second audio track): ${B}${AFORMAT1} ${ALAYOUT1}${D}${ATITLE1}"
  665.         echo "a:2 (third audio track): ${B}${AFORMAT2} ${ALAYOUT2}${D}${ATITLE2}"
  666.         echo "a:3 (fourth audio track): ${B}${AFORMAT3} ${ALAYOUT3}${D}${ATITLE3}"
  667.         echo "a:4 (fifth audio track): ${B}${AFORMAT4} ${ALAYOUT4}${D}${ATITLE4}"
  668.         echo "a:5 (sixth audio track): ${B}${AFORMAT5} ${ALAYOUT5}${D}${ATITLE5}"
  669.         echo "a:6 (seventh audio track): ${B}${AFORMAT6} ${ALAYOUT6}${D}${ATITLE6}"
  670.         echo
  671.         echo "Output path & file: ${P}${OUTMKV}${D}"
  672.         echo
  673.         if [ -s "$OUTMKV" ]
  674.         then
  675.             echo "${R}WARNING${D}: Output file ${P}${OUTMKV}${D} exists! Options 1–5 will prompt you to overwrite it (unless input & output are identical, then they will fail) until you change your output path & file (option 6)."
  676.             echo
  677.         fi
  678.         echo "${G}1${D} - a:0 TrueHD 7.1 to a:1 EAC3 7.1"
  679.         echo "${G}2${D} - a:0 DTS 7.1 to a:1 EAC3 7.1"
  680.         echo "${G}3${D} - a:0 Any to a:1 EAC3 5.1 and below"
  681.         echo "${G}4${D} - a:0 Any to a:1 AC3 5.1 and below"
  682.         echo "${G}5${D} - Strip Audio Stream"
  683.         echo "${G}6${D} - Change Input and Output Paths & Files"
  684.         echo "${G}7${D} - Quit"
  685.         if [ "$INMKV" = "$OUTMKV" ]
  686.         then
  687.             echo
  688.             echo "${R}WARNING${D}: Your input and output files are the same! Options 1–5 will fail until you change either your input or output paths & files (option 6)."
  689.         fi
  690.         echo
  691.         read -rp "Selection: " ANS
  692.    
  693.         case $ANS in
  694.    
  695.     ## 1. TrueHD 7.1 to EAC3 7.1
  696.  
  697.             1)
  698.            
  699.             clear
  700.             thdheading='a:0 TrueHD 7.1 to a:1 EAC3 7.1'
  701.             border "${thdheading}"
  702.             echo
  703.             if [ "$AFORMAT0" = "truehd" ]; then
  704.                 if [ "$ALAYOUT0" = "7.1" ]; then
  705.                     echo "${ALAYOUT0} TrueHD stream found at audio position 1 (a:0)."
  706.                     echo
  707.                     echo "${G}Creating${D} EAC3 7.1 at audio position 2 (a:1) in file ${P}${OUTMKV}${D}..."
  708.                     echo
  709.                     THDANS=y
  710.                     while [ "$THDANS" != "n" ] && [ "$THDANS" != "N" ];
  711.                     do
  712.                         read -rp "Proceed? [y/n]: " THDANS
  713.                         if [ "$THDANS" = "y" ] || [ "$THDANS" = "Y" ];
  714.                         then
  715.                             echo
  716.                             thd "$INMKV" "$OUTMKV" "$thdheading"
  717.                             echo
  718.                             echo "Complete!"
  719.                             echo
  720.                             outputinfo "$OUTMKV"
  721.                             echo
  722.                             rm "$ENCWD"/out.txt
  723.                             break
  724.                         elif [ "$THDANS" = "n" ] || [ "$THDANS" = "N" ];
  725.                         then
  726.                             echo
  727.                             echo "Nothing written to output."
  728.                             echo "Aborting..."
  729.                             echo
  730.                             sleep 0.7
  731.                         else
  732.                             echo "Accepted answers are y or n"
  733.                             sleep 0.7
  734.                         fi
  735.                     done
  736.                 else
  737.                     echo "TrueHD channel layout at audio position 1 (a:0) isn't 7.1!"
  738.                     echo "It is: ${ALAYOUT0}."
  739.                     echo "Aborting..."
  740.                     echo
  741.                 fi
  742.             else
  743.                 echo "No TrueHD audio stream found at audio position 1 (a:0)."
  744.                 echo "Audio at position 1 (a:0) for this file is: ${AFORMAT0}."
  745.                 echo "Aborting..."
  746.                 echo
  747.             fi 
  748.            
  749.             ;;
  750.  
  751.     ## 2. DTS 7.1 to EAC3 7.1
  752.        
  753.             2)
  754.    
  755.             clear
  756.             dtsheading='a:0 DTS 7.1 to a:1 EAC3 7.1'
  757.             border "${dtsheading}"
  758.             echo
  759.             if [ "$AFORMAT0" = "dts" ]; then
  760.                 if [ "$ALAYOUT0" = "7.1" ]; then
  761.                     echo "${ALAYOUT0} DTS stream found at audio position 1 (a:0)."
  762.                     echo
  763.                     echo "${G}Creating${D} EAC3 7.1 at audio position 2 (a:1) in file ${P}${OUTMKV}${D}..."
  764.                     echo
  765.                     DTSANS=y
  766.                     while [ "$DTSANS" != "n" ] && [ "$DTSANS" != "N" ];
  767.                     do
  768.                         read -rp "Proceed? [y/n]: " DTSANS
  769.                         if [ "$DTSANS" = "y" ] || [ "$DTSANS" = "Y" ];
  770.                         then
  771.                             echo
  772.                             dts "$INMKV" "$OUTMKV" "$dtsheading"
  773.                             echo
  774.                             echo "Complete!"
  775.                             echo
  776.                             outputinfo "$OUTMKV"
  777.                             echo
  778.                             rm "$ENCWD"/out.txt
  779.                             break
  780.                         elif [ "$DTSANS" = "n" ] || [ "$DTSANS" = "N" ];
  781.                         then
  782.                             echo
  783.                             echo "Nothing written to output."
  784.                             echo "Aborting..."
  785.                             echo
  786.                             sleep 0.7
  787.                         else
  788.                             echo "Accepted answers are y or n"
  789.                             sleep 0.7
  790.                         fi
  791.                     done
  792.                 else
  793.                     echo "DTS channel layout at audio position 1 (a:0) isn't 7.1!"
  794.                     echo "It is: ${ALAYOUT0}."
  795.                     echo "Aborting..."
  796.                     echo
  797.                 fi
  798.             else
  799.                 echo "No DTS audio stream found at audio position 1 (a:0)."
  800.                 echo "Audio at position 1 (a:0) for this file is: ${AFORMAT0}."
  801.                 echo "Aborting..."
  802.                 echo
  803.             fi 
  804.            
  805.             ;;
  806.        
  807.     ## 3. Any to EAC3 (5.1 and below)
  808.  
  809.             3)
  810.        
  811.             clear
  812.             eac3heading='a:0 Any to a:1 EAC3 5.1 and below'
  813.             border "${eac3heading}"
  814.             echo
  815.             if [ "$ALAYOUT0" = "7.1" ]; then
  816.                 echo "${R}WARNING${D}: a:0 is a 7.1 ${AFORMAT0} stream. Please use option 1 or 2 to encode an EAC3 7.1 track from TrueHD or DTS."
  817.                 echo "Options 3 and 4 will mixdown 7.1 channels to 5.1."
  818.                 echo
  819.             fi
  820.             echo "${ALAYOUT0} ${AFORMAT0} stream found at audio position 1 (a:0)."
  821.             echo
  822.             echo "${G}Creating${D} a 5.1 and below EAC3 stream at audio position 2 (a:1) in file ${P}${OUTMKV}${D}..."
  823.             echo
  824.             EAC3ANS=y
  825.             while [ "$EAC3ANS" != "n" ] && [ "$EAC3ANS" != "N" ];
  826.             do
  827.                 read -rp "Proceed? [y/n]: " EAC3ANS
  828.                 if [ "$EAC3ANS" = "y" ] || [ "$EAC3ANS" = "Y" ];
  829.                 then
  830.                     echo
  831.                     eac3 "$INMKV" "$OUTMKV" "$eac3heading"
  832.                     echo
  833.                     echo "Complete!"
  834.                     echo
  835.                     outputinfo "$OUTMKV"
  836.                     echo
  837.                     rm "$ENCWD"/out.txt
  838.                     break
  839.                 elif [ "$EAC3ANS" = "n" ] || [ "$EAC3ANS" = "N" ];
  840.                 then
  841.                     echo
  842.                     echo "Nothing written to output."
  843.                     echo "Aborting..."
  844.                     echo
  845.                     sleep 0.7
  846.                 else
  847.                     echo "Accepted answers are y or n"
  848.                     sleep 0.7
  849.                 fi
  850.             done
  851.            
  852.             ;;
  853.  
  854.     ## 4. Any to AC3 (5.1 and below)
  855.  
  856.             4)
  857.        
  858.             clear
  859.             ac3heading='a:0 Any to a:1 AC3 5.1 and below'
  860.             border "${ac3heading}"
  861.             echo
  862.             if [ "$ALAYOUT0" = "7.1" ]; then
  863.                 echo "${R}WARNING${D}: a:0 is a 7.1 ${AFORMAT0} stream. AC3 doesn't support more than 5.1 channels."
  864.                 echo "Options 3 and 4 will mixdown 7.1 channels to 5.1."
  865.                 echo
  866.             fi
  867.             echo "${ALAYOUT0} ${AFORMAT0} stream found at audio position 1 (a:0)."
  868.             echo
  869.             echo "${G}Creating${D} a 5.1 and below AC3 stream at audio position 2 (a:1) in file ${P}${OUTMKV}${D}..."
  870.             echo
  871.             AC3ANS=y
  872.             while [ "$AC3ANS" != "n" ] && [ "$AC3ANS" != "N" ];
  873.             do
  874.                 read -rp "Proceed? [y/n]: " AC3ANS
  875.                 if [ "$AC3ANS" = "y" ] || [ "$AC3ANS" = "Y" ];
  876.                 then
  877.                     echo
  878.                     ac3 "$INMKV" "$OUTMKV" "$ac3heading"
  879.                     echo
  880.                     echo "Complete!"
  881.                     echo
  882.                     outputinfo "$OUTMKV"
  883.                     echo
  884.                     rm "$ENCWD"/out.txt
  885.                     break
  886.                 elif [ "$AC3ANS" = "n" ] || [ "$AC3ANS" = "N" ];
  887.                 then
  888.                     echo
  889.                     echo "Nothing written to output."
  890.                     echo "Aborting..."
  891.                     echo
  892.                     sleep 0.7
  893.                 else
  894.                     echo "Accepted answers are y or n"
  895.                     sleep 0.7
  896.                 fi
  897.             done
  898.            
  899.             ;;
  900.  
  901.     ## 5. Strip Audio Stream
  902.        
  903.             5)
  904.    
  905.             clear
  906.             ssheading='Strip Audio Stream'
  907.             border "${ssheading}"
  908.             echo
  909.             echo "Enter 0 to strip audio track 1: ${B}${AFORMAT0} ${ALAYOUT0}${D}${ATITLE0}"
  910.             echo "Enter 1 to strip audio track 2: ${B}${AFORMAT1} ${ALAYOUT1}${D}${ATITLE1}"
  911.             echo "Enter 2 to strip audio track 3: ${B}${AFORMAT2} ${ALAYOUT2}${D}${ATITLE2}"
  912.             echo "Enter 3 to strip audio track 4: ${B}${AFORMAT3} ${ALAYOUT3}${D}${ATITLE3}"
  913.             echo "Enter 4 to strip audio track 5: ${B}${AFORMAT4} ${ALAYOUT4}${D}${ATITLE4}"
  914.             echo "Enter 5 to strip audio track 6: ${B}${AFORMAT5} ${ALAYOUT5}${D}${ATITLE5}"
  915.             echo "Enter 6 to strip audio track 7: ${B}${AFORMAT6} ${ALAYOUT6}${D}${ATITLE6}"
  916.             echo "If stream is higher than track seven, minus 1 and enter that number (ex: track 9, enter 8)."
  917.             echo
  918.             read -rp "Enter number: " STRIPNUMBER
  919.             echo
  920.             echo "${R}Removing${D} a:${STRIPNUMBER} in output file ${P}${OUTMKV}${D}..."
  921.             echo
  922.             STRIPANS=y
  923.             while [ "$STRIPANS" != "n" ] && [ "$STRIPANS" != "N" ];
  924.             do
  925.                 read -rp "Proceed? [y/n]: " STRIPANS
  926.                 if [ "$STRIPANS" = "y" ] || [ "$STRIPANS" = "Y" ];
  927.                 then
  928.                     echo
  929.                     stripstream "$INMKV" "$STRIPNUMBER" "$OUTMKV" "$ssheading"
  930.                     echo
  931.                     echo "Complete!"
  932.                     echo
  933.                     outputinfo "$OUTMKV"
  934.                     echo
  935.                     rm "$ENCWD"/out.txt
  936.                     break
  937.                 elif [ "$STRIPANS" = "n" ] || [ "$STRIPANS" = "N" ];
  938.                 then
  939.                     echo
  940.                     echo "Nothing written to output."
  941.                     echo "Aborting..."
  942.                     echo
  943.                     sleep 0.7
  944.                 else
  945.                     echo "Accepted answers are y or n"
  946.                     sleep 0.7
  947.                 fi
  948.             done
  949.            
  950.             ;;
  951.  
  952.     ## 6. Change Input & Output Paths & Files
  953.        
  954.             6)
  955.    
  956.             clear
  957.             border "Change Input and Output Paths & Files"
  958.             echo
  959.             echo "Current input path & file: ${P}${INMKV}${D}"
  960.             echo "Current output path & file: ${P}${OUTMKV}${D}"
  961.             echo
  962.             changeinmkv
  963.             echo
  964.             changeoutmkv
  965.             echo
  966.             echo "Complete!"
  967.             echo
  968.             echo "Active input path & file: ${P}${INMKV}${D}"
  969.             echo "Active output path & file: ${P}${OUTMKV}${D}"
  970.             echo
  971.            
  972.             ;;
  973.  
  974.  
  975.     ## 7. Quitting
  976.        
  977.             7)
  978.    
  979.             echo
  980.             echo "Quitting..."
  981.             echo
  982.             sleep 0.7
  983.            
  984.             ;;
  985.  
  986.     ## Invalid selection
  987.        
  988.             *)
  989.    
  990.             echo
  991.             echo "${R}Invalid selection${D}."
  992.             sleep 0.7
  993.            
  994.             ;;
  995.    
  996.         esac
  997.     done
  998. elif [ ! -s "$INMKV" ]; then
  999.     echo "Input ${INMKV} ${R}does not exist${D}!"
  1000.     echo
  1001.     echo "Input file must exist for proper execution."
  1002.     echo
  1003.     echo "Usage: audiotool.sh [/path/to/input.mkv] [/path/to/output.mkv]"
  1004.     echo
  1005.     echo "Requires 2 arguments. input.mkv must exist, and will be the source path & file, while output.mkv cannot exist, and will be the output path & file."
  1006.     echo
  1007.     exit 1
  1008. elif [ -s "$OUTMKV" ]; then
  1009.     echo "Output ${OUTMKV} ${R}exists${D}, or is a directory!"
  1010.     echo
  1011.     echo "Though FFmpeg prompts to overwrite output, your initial output value must not exist. To be prompted to overwrite a file, enter an initial output value that doesn't exist, then use option 6 to change your output to one that exists, but isn't identical to your input file."
  1012.     echo
  1013.     echo "Note: Input and output files cannot be identical, or FFmpeg's encode execution will fail."
  1014.     echo
  1015.     echo "Usage: audiotool.sh [/path/to/input.mkv] [/path/to/output.mkv]"
  1016.     echo
  1017.     echo "Requires 2 arguments. input.mkv must exist, and will be the source path & file, while output.mkv cannot exist, and will be the output path & file."
  1018.     echo
  1019.     exit 1
  1020. elif [[ ! $# -eq 2 ]]; then
  1021.     echo "Requires 2 arguments."
  1022.     echo
  1023.     echo "Usage: audiotool.sh [/path/to/input.mkv] [/path/to/output.mkv]"
  1024.     echo
  1025.     echo "input.mkv must exist, and will be the source path & file, while output.mkv cannot exist, and will be the output path & file."
  1026.     echo
  1027.     exit 1
  1028.  
  1029. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement