fant0men

info_txt function

Oct 11th, 2019
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Creates a function called 'info_txt', which creates info txt files
  2. # containing information generated by ffmpeg. It creates a separate
  3. # txt file for input file, output file and remux output.
  4. info_txt () {
  5.  
  6.     # Creates the basename of $if, $of and $of_remux.
  7.     if_bname="$bname"
  8.     of_bname=$(basename "$of")
  9.     of_remux_bname=$(basename "$of_remux")
  10.  
  11.     # Creates filenames for the info txt files, which contain the
  12.     # information generated by 'ffmpeg'.
  13.     # Also creates filenames for HandBrake version and options.
  14.     if_info_f="${info_dir}/${bname}_info.txt"
  15.     of_info_f="${info_dir}/${of_bname}_info.txt"
  16.     of_remux_info_f="${info_dir}/${of_remux_bname}_info.txt"
  17.     hb_version_info_f="${info_dir}/${cmd[0]}_version.txt"
  18.     hb_opts_info_f="${info_dir}/${cmd[0]}_options.txt"
  19.  
  20.     # If the info txt filenames already exist, add a random number to the
  21.     # end of the filename. Also, create empty files with those names.
  22.     for type in if of of_remux; do
  23.  
  24.         info_f_ref="${type}_info_f"
  25.         bname_ref="${type}_bname"
  26.  
  27.         if [[ -f ${!info_f_ref} ]]; then
  28.             info_f="${info_dir}/${!bname_ref}_info-${session}.txt"
  29.             touch "$info_f"
  30.         else
  31.             touch "${!info_f_ref}"
  32.         fi
  33.  
  34.     done
  35.  
  36.     # If '$hb_version_info_f' or '$hb_opts_info_f' exist as files,
  37.     # remove them.
  38.     if [[ -f $hb_version_info_f ]]; then
  39.  
  40.         rm "$hb_version_info_f"
  41.     elif [[ -f $hb_opts_info_f ]]; then
  42.  
  43.         rm "$hb_opts_info_f"
  44.     fi
  45.  
  46.     # Create new empty files, called '$hb_version_info_f' and
  47.     # '$hb_opts_info_f'.
  48.     touch "$hb_version_info_f"
  49.     touch "$hb_opts_info_f"
  50.  
  51.     # Sets IFS to newline.
  52.     IFS=$'\n'
  53.  
  54.     # Gets information about output file.
  55.     of_info=( $(eval ${cmd[1]} -hide_banner -i \"${of}\" &>/dev/stdout) )
  56.  
  57.     # Gets information about output file.
  58.     of_remux_info=( $(eval ${cmd[1]} -hide_banner -i \"${of_remux}\" &>/dev/stdout) )
  59.  
  60.     # Gets HandBrake version.
  61.     hb_version=( $(eval ${cmd[0]} --version &>/dev/stdout | grep -E "^HandBrake [[:digit:]]") )
  62.  
  63.     # Gets the list of HandBrake options.
  64.     hb_help=( $(eval ${cmd[0]} --help &>/dev/stdout) )
  65.  
  66.     IFS="$IFS_bak"
  67.  
  68.     # Echoes the information gathered from the input file, by ffmpeg.
  69.     # Echoes the information gathered from the output file, by ffmpeg.
  70.     # Echoes the information gathered from the remux output file,
  71.     # by ffmpeg.
  72.  
  73.     declare -A info_elements
  74.  
  75.     info_elements[if]="${#if_info[@]"
  76.     info_elements[of]="${#of_info[@]"
  77.     info_elements[of_remux]="${#of_remux_info[@]"
  78.  
  79.     for type in if of of_remux; do
  80.  
  81.         info_f_ref="${type}_info_f"
  82.         elements="${info_elements[${type}]}"
  83.  
  84.         for (( i = 0; i < $elements; i++ )); do
  85.  
  86.             info_ref="${type}_info[${i}]"
  87.  
  88.             echo "${!info_ref}" >> "${!info_f_ref}"
  89.         done
  90.     done
  91.  
  92.     # Echoes the version and options of HandBrake.
  93.     echo "${hb_version[0]}" > "$hb_version_info_f"
  94.     for (( i = 0; i < ${#hb_help[@]}; i++ )); do
  95.         echo "${hb_help[${i}]}" >> "$hb_opts_info_f"
  96.     done
  97. }
RAW Paste Data