Advertisement
MaxDjently

Ziggle Wump Media Compressor 0.2-beta.09.29.2024

Sep 28th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 38.81 KB | Source Code | 0 0
  1. #!/data/data/com.termux/files/usr/bin/bash
  2.  
  3. # ATTENTION:
  4.  
  5. # Copying and pasting the script can introduce formatting that is improper to bash.  If the script doesn't run, you may need to use the dos2unix command to fix it.
  6.  
  7. # ex.  dos2unix ziggle_wump.sh
  8.  
  9. # --------------------
  10. #     Licence
  11. # --------------------
  12.  
  13. # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  14.  
  15. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  16.  
  17. # You should have received a copy of the GNU General Public License along with  this program. If not, see <https://www.gnu.org/licenses/>.
  18.  
  19. # -----------------
  20. #     About
  21. # -----------------
  22.  
  23. # This script is for Termux on Android and is not associated with the apps it uses.
  24.  
  25. # Copyright Joshua Hansen and contributors: Microsoft Co-Pilot, OpenAI ChatGPT and Google Gemini.
  26.  
  27. # Shout out to Webernets https://youtu.be/0aeCfDKLfbs?si=58y58eWSiXurcHpj who gave me the inspiration for this, the one who did the heavy lifting figuring out the command line options. And this video helping me figure out how to do it in Handbrake, but I needed it all in a one-line command line option and this was it, I had to write it myself.
  28.  
  29. # -----------------------
  30. #   Instructions
  31. # -----------------------
  32.  
  33. instructions="Ziggle Wump: The Simple FFmpeg Command Line Companion Script for Termux on Android
  34.  
  35. Disclaimer
  36.  
  37. * This script does not allow conversion of encrypted files, typically indicating copyrighted material.
  38.  
  39. * The script itself does not violate copyright, but user actions might. The script cannot prevent users from circumventing copyright protection, nor is it the script's responsibility to do so. The onus lies with the copyright holder to encrypt their media.
  40.  
  41. * It is not recommended to use the script to violate copyright law. US copyright law allows for spaceshifting and fair use of copyrighted material.
  42. Note
  43.  
  44. * Some phones, like the Galaxy S24, have battery-saving features that can impact encoding. Ensure Termux is in focus (full screen or split-screen) while encoding, and keep the screen on during the process.
  45.  
  46. * For more information and potential fixes for specific phones, visit https://dontkillmyapp.com/.
  47.  
  48. Getting Started
  49.  
  50. * Download or Copy: Download or copy this script to a file and rename it if desired (e.g., ziggle_wump.sh). Placing it in your Movies folder makes it easily accessible on both Android and Termux, although you can also put it in /data/data/com.termux/files/usr/bin to use it system-wide.
  51.  
  52. * Install Termux and Termux:Widget (Optional): Grab Termux from F-Droid if you haven't already. Termux:Widget is optional for a more user-friendly interface.
  53.  
  54. * Obtain Storage Access: Run termux-setup-storage and allow access.
  55.  
  56. * Run the Script: Execute the script using bash ./ziggle_wump.sh [options]. (FIRST TIME RUN: Use bash ./ziggle_wump.sh -d to install dependencies.)
  57.  
  58. Termux:Widget (Optional):
  59.  
  60. * Install Termux:Widget and grant it permissions.
  61.  
  62. * Place the widget on your Home Screen.
  63.  
  64. * Run bash ziggle_wump.sh -i to install the script to /data/data/com.termux/files/usr/bin and create a widget in $HOME/.shortcuts.
  65.  
  66. * Reload the Widget to see 'Ziggle Wump Media Compressor.sh.'
  67.  
  68. Options:
  69.  
  70. * -r resolution: Sets a custom resolution height while preserving aspect ratio for both videos and images (e.g., bash ziggle_wump.sh -r 720).
  71. * -d: Checks and upgrades dependencies.
  72. * -y: Automatically confirms prompts.
  73. * -o output_fps: Sets a custom output video frames per second. (e.g., bash ziggle_wump.sh -o 60).
  74. * -b max_video_bitrate: Sets a custom maximum video bitrate in kilobits per second. (e.g., bash ziggle_wump.sh -b 2000).
  75. * -a avg_audio_bitrate: Sets a custom average audio bitrate in kilobits per second for both videos and audio files. (e.g., bash ziggle_wump.sh -a 128).
  76. * -p preset: Sets encoding speed preset for videos. (0=slowest, 8=fastest) (e.g., bash ziggle_wump.sh -p 4).
  77. * -P video_encoding_profile Sets the profile found in profiles.conf
  78. * -i: Installs the script to /data/data/com.termux/files/usr/bin/zwmc. Installs widget to ~/.shortcuts.
  79. * -u: Uninstalls the script from /data/data/com.termux/files/usr/bin/zwmc.  Removes widget.
  80. * -m: Shows the menu for setting options.
  81. * -h, --help: Displays help message."
  82.  
  83. # -----------------------------
  84. #        Variables
  85. # -----------------------------
  86.  
  87. # Supported File Types
  88. video_ext="mp4 mkv avi mov flv wmv webm mts 3gp mpeg ogv rmvb m4v f4v vob ts m2ts asf swf m2v divx xvid mpg mpe m1v dvr-ms mxf gxf bink mng nsv"
  89. audio_ext="mp3 aac wav flac ogg m4a wma ac3 eac3 opus amr aiff alac caf dts mka mp2 ra tta voc"
  90. img_ext="jpg jpeg png bmp tiff gif webp heic heif jxl ppm pgm pbm pam tga sgi pcx ras xbm xpm ico dds exr hdr svg"
  91.  
  92. # Maximum resolution by height in pixels maintaining aspect ratio. Either the user defined value or the input video or image original value will be selected
  93. resolution=600
  94. max_video_bitrate=688 # In Kilobits per second.
  95. # Set the audio bitrate for both videos and audio files.
  96. avg_audio_bitrate=96 # In Kilobits per second.
  97. output_fps=24 # Maximum output FPS. Original or user input, whichever is lower.
  98. crf=28
  99. # Define an array of presets from slowest to fastest
  100. presets=("veryslow" "slower" "slow" "medium" "fast" "faster" "veryfast" "superfast" "ultrafast")
  101. preset=slow # Default Speed Preset
  102. profile="" # custom Ziggle Wump profile.
  103.  
  104. # Full Log file path
  105. log_file="/storage/emulated/0/Movies/VideoDrop/convert.log"
  106.  
  107. # Full directory paths
  108. video_drop_dir="/storage/emulated/0/Movies/VideoDrop"
  109. video_processing_dir="/storage/emulated/0/Movies/VideoProcessing"
  110. output_dir_base="/storage/emulated/0/Movies/VideoConverted"
  111.  
  112. # combine audio and video extension variables to pass to find command.
  113. filetypes=""
  114. for ext in $audio_ext $video_ext $img_ext; do
  115.     filetypes="$filetypes -iname '*.$ext' -o"
  116. done
  117. # Remove the trailing ' -o'
  118. filetypes="${filetypes% -o}"
  119.  
  120. # Define a lock file
  121. LOCKFILE="/data/data/com.termux/files/usr/var/lock/zwmc.lock"
  122. LOCKDIR=$(dirname "$LOCKFILE")
  123.  
  124. # Ensure the lock directory exists
  125. mkdir -p "$LOCKDIR"
  126.  
  127. # Cleanup function to remove the lock file
  128. cleanup() {
  129.     rm -f "$LOCKFILE"
  130. }
  131.  
  132. # Set the trap to call cleanup on script exit
  133. trap cleanup EXIT
  134.  
  135. # Try to acquire the lock
  136. exec 200>"$LOCKFILE"
  137. flock -n 200 || { echo "Script is already running"; exit 1; }
  138.  
  139. # The lock file will be removed when the script exits, thanks to the trap
  140.  
  141. # --------------------------------------------------
  142. #    Setting up files and folders
  143. # --------------------------------------------------
  144.  
  145. width=$(tput cols)
  146.  
  147. # Create necessary directories if they don't exist
  148. mkdir -p "$video_drop_dir" "$video_processing_dir" "$output_dir_base"
  149.  
  150. # Check if log file exists
  151. if [ -f "$log_file" ]; then
  152.     echo "Old log file found.  Deleting..."
  153.     rm "$log_file"
  154.     echo "File deleted."
  155. else
  156.     echo "Log File does not exist.  The script will create $log_file"
  157. fi
  158.  
  159. echo ""
  160. echo "$instructions" | tee -a "$log_file" | fmt -w $width
  161.  
  162. # Check if profiles.conf exists, if not, create it
  163. if [ ! -f "$video_drop_dir/profiles.conf" ]; then
  164.     cat <<EOL > "$video_drop_dir/profiles.conf"
  165. [1080p_cell_phone]
  166. resolution=1080
  167. frame_rate=30
  168. video_bitrate=2000
  169. audio_bitrate=96
  170. crf=23
  171. preset=3
  172.  
  173. [90s_game_console]
  174. resolution=240
  175. frame_rate=15
  176. video_bitrate=200
  177. audio_bitrate=48
  178. crf=30
  179. preset=4
  180.  
  181. [Cinema_Quality]
  182. resolution=2160
  183. frame_rate=24
  184. video_bitrate=8000
  185. audio_bitrate=192
  186. crf=18
  187. preset=2
  188.  
  189. [Desktop_High-End]
  190. resolution=2160
  191. frame_rate=60
  192. video_bitrate=10000
  193. audio_bitrate=256
  194. crf=20
  195. preset=2
  196.  
  197. [Desktop_Low-End]
  198. resolution=1080
  199. frame_rate=30
  200. video_bitrate=1500
  201. audio_bitrate=96
  202. crf=24
  203. preset=3
  204.  
  205. [Desktop_Mid-Range]
  206. resolution=1440
  207. frame_rate=60
  208. video_bitrate=2500
  209. audio_bitrate=128
  210. crf=22
  211. preset=2
  212.  
  213. [DVD_Quality]
  214. resolution=480
  215. frame_rate=24
  216. video_bitrate=1000
  217. audio_bitrate=64
  218. crf=28
  219. preset=3
  220.  
  221. [Low_Bandwidth_Stream]
  222. resolution=270
  223. frame_rate=15
  224. video_bitrate=100
  225. audio_bitrate=48
  226. crf=32
  227. preset=5
  228.  
  229. [Low_Res_Mobile]
  230. resolution=360
  231. frame_rate=24
  232. video_bitrate=300
  233. audio_bitrate=48
  234. crf=28
  235. preset=4
  236.  
  237. [Mobile_High-End]
  238. resolution=1080
  239. frame_rate=60
  240. video_bitrate=1500
  241. audio_bitrate=96
  242. crf=24
  243. preset=3
  244.  
  245. [Mobile_Low_End]
  246. resolution=360
  247. frame_rate=15
  248. video_bitrate=150
  249. audio_bitrate=48
  250. crf=32
  251. preset=5
  252.  
  253. [Mobile_Mid-Range]
  254. resolution=720
  255. frame_rate=30
  256. video_bitrate=800
  257. audio_bitrate=64
  258. crf=26
  259. preset=3
  260.  
  261. [Modern_Laptop]
  262. resolution=1080
  263. frame_rate=60
  264. video_bitrate=1500
  265. audio_bitrate=96
  266. crf=24
  267. preset=3
  268.  
  269. [Old_Smartphone]
  270. resolution=360
  271. frame_rate=24
  272. video_bitrate=300
  273. audio_bitrate=64
  274. crf=28
  275. preset=4
  276.  
  277. [Retro_Computer_16-bit]
  278. resolution=320
  279. frame_rate=30
  280. video_bitrate=150
  281. audio_bitrate=32
  282. crf=32
  283. preset=5
  284.  
  285. [Retro_Computer_8-bit]
  286. resolution=240
  287. frame_rate=15
  288. video_bitrate=100
  289. audio_bitrate=32
  290. crf=32
  291. preset=5
  292.  
  293. [Retro_PC]
  294. resolution=480
  295. frame_rate=15
  296. video_bitrate=200
  297. audio_bitrate=64
  298. crf=30
  299. preset=4
  300.  
  301. [Streaming_High_Bandwidth]
  302. resolution=1080
  303. frame_rate=60
  304. video_bitrate=1500
  305. audio_bitrate=96
  306. crf=24
  307. preset=3
  308.  
  309. [Streaming_Low_Bandwidth]
  310. resolution=270
  311. frame_rate=15
  312. video_bitrate=150
  313. audio_bitrate=48
  314. crf=32
  315. preset=5
  316.  
  317. [Streaming_Medium_Bandwidth]
  318. resolution=720
  319. frame_rate=30
  320. video_bitrate=800
  321. audio_bitrate=64
  322. crf=26
  323. preset=3
  324.  
  325. [Tablet_Profile]
  326. resolution=720
  327. frame_rate=30
  328. video_bitrate=800
  329. audio_bitrate=64
  330. crf=26
  331. preset=3
  332.  
  333. [VHS_Quality]
  334. resolution=240
  335. frame_rate=30
  336. video_bitrate=250
  337. audio_bitrate=64
  338. crf=30
  339. preset=4
  340. EOL
  341. fi
  342.  
  343. # Function to read profile from profiles.conf
  344. read_profile() {
  345.     local profile_name=$1
  346.     resolution=$(awk -F "=" "/^\[$profile_name\]/ {a=1} a==1 && \$1~/resolution/ {print \$2; exit}" $video_drop_dir/profiles.conf)
  347.     output_fps=$(awk -F "=" "/^\[$profile_name\]/ {a=1} a==1 && \$1~/frame_rate/ {print \$2; exit}" $video_drop_dir/profiles.conf)
  348.     max_video_bitrate=$(awk -F "=" "/^\[$profile_name\]/ {a=1} a==1 && \$1~/video_bitrate/ {print \$2; exit}" $video_drop_dir/profiles.conf)
  349.     avg_audio_bitrate=$(awk -F "=" "/^\[$profile_name\]/ {a=1} a==1 && \$1~/audio_bitrate/ {print \$2; exit}" $video_drop_dir/profiles.conf)
  350.     crf=$(awk -F "=" "/^\[$profile_name\]/ {a=1} a==1 && \$1~/crf/ {print \$2; exit}" $video_drop_dir/profiles.conf)
  351.     preset=$(awk -F "=" "/^\[$profile_name\]/ {a=1} a==1 && \$1~/preset/ {print \$2; exit}" $video_drop_dir/profiles.conf)
  352.     preset=${presets[$preset]}
  353. }
  354.  
  355. # Function to list profiles from profiles.conf
  356. list_profiles() {
  357.     awk -F "=" '/^\[.*\]/ {gsub(/[\[\]]/, "", $1); print $1}' $video_drop_dir/profiles.conf
  358. }
  359.  
  360. # --------------------------------
  361. #     Command Flags
  362. # --------------------------------
  363.  
  364. show_menu() {
  365.     auto_yes=true  # Turn on auto_yes when the menu is shown
  366.     while true; do
  367.         deps_status="Off"
  368.         if [ "$check_deps" = true ]; then
  369.             deps_status="On"
  370.         fi
  371.  
  372.         menu_choice=$(dialog --menu "Ziggle Wump Media Compressor Chooser" 17 50 11 \
  373.             1 "Set Max Resolution ($resolution)" \
  374.             2 "Set Max Output FPS ($output_fps)" \
  375.             3 "Set Max Video Bitrate ($max_video_bitrate)" \
  376.             4 "Set Average Audio Bitrate ($avg_audio_bitrate)" \
  377.             5 "Set Constant Rate Factor ($crf)" \
  378.             6 "Set Encoding Speed ($preset)" \
  379.             7 "Check Dependencies ($deps_status)" \
  380.             8 "Install Script" \
  381.             9 "Uninstall Script" \
  382.             10 "Set Conversion Profile" \
  383.             11 "Compress Files in $(basename $video_drop_dir)" 2>&1 >/dev/tty)
  384.  
  385.         case $menu_choice in
  386.             1)
  387.                 new_resolution=$(dialog --inputbox "Enter resolution maximum height in pixels ($resolution):" 8 40 "$resolution" 2>&1 >/dev/tty)
  388.                 if [ $? -eq 0 ]; then
  389.                     resolution="$new_resolution"
  390.                 fi
  391.                 ;;
  392.             2)
  393.                 new_output_fps=$(dialog --inputbox "Enter maximum output FPS ($output_fps):" 8 40 "$output_fps" 2>&1 >/dev/tty)
  394.                 if [ $? -eq 0 ]; then
  395.                     output_fps="$new_output_fps"
  396.                 fi
  397.                 ;;
  398.             3)
  399.                 new_max_video_bitrate=$(dialog --inputbox "Enter maximum video bitrate ($max_video_bitrate):" 8 40 "$max_video_bitrate" 2>&1 >/dev/tty)
  400.                 if [ $? -eq 0 ]; then
  401.                     max_video_bitrate="$new_max_video_bitrate"
  402.                 fi
  403.                 ;;
  404.             4)
  405.                 new_avg_audio_bitrate=$(dialog --inputbox "Enter average audio bitrate ($avg_audio_bitrate):" 8 40 "$avg_audio_bitrate" 2>&1 >/dev/tty)
  406.                 if [ $? -eq 0 ]; then
  407.                     avg_audio_bitrate="$new_avg_audio_bitrate"
  408.                 fi
  409.                 ;;
  410.             5)
  411.                 dialog --msgbox "CRF (Constant Rate Factor) is a quality setting for video encoding. It ranges from 0 (lossless) to 51 (worst quality). Lower values mean better quality and larger files, while higher values mean lower quality and smaller files." 10 50
  412.                 new_crf=$(dialog --inputbox "Enter CRF value (0-51) ($crf):" 8 40 "$crf" 2>&1 >/dev/tty)
  413.                 if [ $? -eq 0 ]; then
  414.                     echo "User entered CRF: $new_crf" >&2  # Debug message
  415.                     if [ "$new_crf" -ge 0 ] && [ "$new_crf" -le 51 ]; then
  416.                         crf="$new_crf"
  417.                         echo "CRF set to: $crf" >&2  # Debug message
  418.                     else
  419.                         dialog --msgbox "Invalid CRF value. Please enter a value between 0 and 51." 6 40
  420.                         echo "Invalid CRF value entered: $new_crf" >&2  # Debug message
  421.                     fi
  422.                 fi
  423.                 ;;
  424.             6)
  425.                 dialog --msgbox "Choose an x265 speed preset. The preset determines the encoding speed and compression efficiency. Choose a preset that best fits your needs. Slower presets will provide better compression and quality but take longer to encode." 10 50
  426.  
  427.                 # Your original preset selection dialog
  428.                 new_preset=$(dialog --menu "Choose x265 Speed Preset" 15 50 9 \
  429.                     ultrafast "8" \
  430.                     superfast "7" \
  431.                     veryfast "6" \
  432.                     faster "5" \
  433.                     fast "4" \
  434.                     medium "3" \
  435.                     slow "2" \
  436.                     slower "1" \
  437.                     veryslow "0" 2>&1 >/dev/tty)
  438.  
  439.                 # Check if a new preset was selected
  440.                 if [ $? -eq 0 ]; then
  441.                     preset=$new_preset
  442.                 fi
  443.                 ;;
  444.             7)
  445.                 while true; do
  446.                     if [ "$check_deps" = true ]; then
  447.                         check_deps=false
  448.                     else
  449.                         check_deps=true
  450.                     fi
  451.                     deps_status="Off"
  452.                     if [ "$check_deps" = true ]; then
  453.                         deps_status="On"
  454.                     fi
  455.                     dialog --msgbox "Dependencies are now $deps_status" 6 40
  456.                     break
  457.                 done
  458.                 ;;
  459.             8)
  460.                 clear
  461.                 install_script
  462.                 ;;
  463.             9)
  464.                 clear
  465.                 uninstall_script
  466.                 ;;
  467.             10)
  468.                 profile_list=$(list_profiles)
  469.                 selected_profile=$(dialog --menu "Choose Profile" 15 50 9 $(echo "$profile_list" | awk '{print NR, $0}') 2>&1 >/dev/tty)
  470.                 if [ $? -eq 0 ]; then
  471.                     read_profile "$(echo "$profile_list" | sed -n "${selected_profile}p")"
  472.                 fi
  473.                 ;;
  474.             11)
  475.                 break
  476.                 ;;
  477.             *)
  478.                 tput sgr0  # Reset terminal colors
  479.                 clear
  480.                 exit 0
  481.                 ;;
  482.         esac
  483.     done
  484. }
  485.  
  486. # Function to display help message
  487. show_help() {
  488.     width=$(tput cols)
  489.     script_name=$(basename "$0")
  490.     echo "Place your media files in $video_drop_dir." | tee -a "$log_file" | fmt -w $width
  491.     echo "Usage: bash $script_name [-r resolution] [-d] [-y] [-o output_fps] [-b max_video_bitrate] [-a avg_audio_bitrate] [-p preset] [-i] [-u] [-m] [-h|--help]" | fmt -w $width
  492.     echo "  -r resolution ex. bash $script_name -r 720 Custom resolution height preserving aspect ratio" | fmt -w $width
  493.     echo "  -d Check and upgrade dependencies." | fmt -w $width
  494.     echo "  -y Automatically say yes to prompts." | fmt -w $width
  495.     echo "  -o output_fps Set custom output FPS. ex. bash $script_name -o 60" | fmt -w $width
  496.     echo "  -b max_video_bitrate Set custom max video bitrate in kilobits per second. ex. bash $script_name -b 2000" | fmt -w $width
  497.     echo "  -a avg_audio_bitrate Set custom average audio bitrate in kilobits per second. ex. bash $script_name -a 128" | fmt -w $width
  498.     echo "  -p preset Set encoding speed preset for x265 (0=slowest, 8=fastest). ex. bash $script_name -p 4" | fmt -w $width
  499.     echo "  -i Install the script to /data/data/com.termux/files/usr/bin/zwmc" | fmt -w $width
  500.     echo "  -u Uninstall the script from /data/data/com.termux/files/usr/bin/zwmc" | fmt -w $width
  501.     echo "  -m Shows the menu for setting options." | fmt -w $width
  502.     echo " -P video_encoding_profile Sets the profile found in profiles.conf" | fmt -w $width
  503.     echo "  -h, --help Display this help message" | fmt -w $width
  504.     exit 0
  505. }
  506.  
  507. # Install Ziggle Wump to /data/data/com.termux/files/usr/bin folder and widget script to ~/.shortcuts
  508. install_script() {
  509.     if [ -f /data/data/com.termux/files/usr/bin/zwmc ]; then
  510.         current_dir=$(dirname "$0")
  511.         if [ "$current_dir" != "/data/data/com.termux/files/usr/bin" ]; then
  512.             echo "Script is installed but not running from the bin directory. Reinstalling..." | tee -a "$log_file" | fmt -w $width
  513.             cp "$(readlink -f "$0")" /data/data/com.termux/files/usr/bin/zwmc
  514.             chmod +x /data/data/com.termux/files/usr/bin/zwmc
  515.             if whereis zwmc | grep -q "/data/data/com.termux/files/usr/bin/zwmc"; then
  516.                 echo "Script reinstalled to /data/data/com.termux/files/usr/bin/zwmc"
  517.             else
  518.                 echo "Reinstallation failed" | tee -a "$log_file" | fmt -w $width
  519.             fi
  520.         else
  521.             echo "Script is already installed and running from the bin directory." | tee -a "$log_file" | fmt -w $width
  522.         fi
  523.     else
  524.         cp "$(readlink -f "$0")" /data/data/com.termux/files/usr/bin/zwmc
  525.         chmod +x /data/data/com.termux/files/usr/bin/zwmc
  526.         if whereis zwmc | grep -q "/data/data/com.termux/files/usr/bin/zwmc"; then
  527.             echo "Script installed to /data/data/com.termux/files/usr/bin/zwmc" | tee -a "$log_file" | fmt -w $width
  528.         else
  529.             echo "Installation failed" | tee -a "$log_file" | fmt -w $width
  530.         fi
  531.     fi
  532.  
  533.     # Create the shortcut script
  534.     mkdir -p $HOME/.shortcuts
  535.     echo '#!/data/data/com.termux/files/usr/bin/bash' > $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  536.     echo 'zwmc -m' >> $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  537.     echo 'read -p "Press Enter to continue.  Bye!"' >> $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  538.     echo 'case $return in' >> $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  539.     echo '    * ) echo "Exiting script."' >> $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  540.     echo 'esac' >> $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  541.     chmod +x $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  542.  
  543.     exit 0
  544. }
  545.  
  546. uninstall_script() {
  547.     if [ ! -f /data/data/com.termux/files/usr/bin/zwmc ]; then
  548.         echo "Script is not installed." | tee -a "$log_file" | fmt -w $width
  549.         exit 0
  550.     else
  551.         rm -f /data/data/com.termux/files/usr/bin/zwmc
  552.         if ! whereis zwmc | grep -q "/data/data/com.termux/files/usr/bin/zwmc"; then
  553.             echo "Script uninstalled from /data/data/com.termux/files/usr/bin/zwmc" | tee -a "$log_file" | fmt -w $width
  554.         else
  555.             echo "Uninstallation failed" | tee -a "$log_file" | fmt -w $width
  556.         fi
  557.     fi
  558.  
  559.     # Remove the shortcut script
  560.     rm -f $HOME/.shortcuts/Ziggle\ Wump\ Media\ Compressor.sh
  561.  
  562.     exit 0
  563. }
  564.  
  565. # Parse command-line options
  566. check_deps=false
  567. auto_yes=false  # Set auto_yes to false by default
  568. while getopts "r:dyho:b:a:c:iump:P:" opt; do
  569.     case $opt in
  570.         r) resolution="$OPTARG" ;;  # Set custom resolution by height
  571.         d) check_deps=true ;;  # Check and upgrade dependencies
  572.         y) auto_yes=true ;;  # Automatically say yes to prompts
  573.         o) output_fps="$OPTARG" ;;  # Set custom output FPS
  574.         b) max_video_bitrate="$OPTARG" ;;  # Set custom max video bitrate
  575.         a) avg_audio_bitrate="$OPTARG" ;;  # Set custom average audio bitrate
  576.         c) crf="$OPTARG" ;;  # Set custom CRF value
  577.         i) install_script ;;  # Install the script
  578.         u) uninstall_script ;;  # Uninstall the script
  579.         m) auto_yes=true; show_menu ;;  # Show menu and turn on auto_yes
  580.         p) preset="${presets[$OPTARG]}" ;;  # Set preset based on number 0-8
  581.         P) profile="$OPTARG"; read_profile "$profile" ;;
  582.         h) show_help ;;  # Display help
  583.         *) show_help ;;  # Display help for invalid options
  584.     esac
  585. done
  586.  
  587. shift $((OPTIND -1))
  588.  
  589. # ------------------------------
  590. #     Dependencies
  591. # ------------------------------
  592.  
  593. if $check_deps; then
  594.     echo "Checking and upgrading dependencies, please wait..."
  595.     pkg update && pkg upgrade -y
  596.     if ! command -v bc &> /dev/null; then
  597.         pkg install bc -y
  598.     fi
  599.     if ! command -v ffmpeg &> /dev/null; then
  600.         pkg install ffmpeg -y
  601.     fi
  602.     if ! command -v ncurses-utils &> /dev/null; then
  603.         pkg install ncurses-utils -y
  604.     fi
  605.     echo "Update complete."
  606. fi
  607.  
  608. # ------------------------
  609. #     Start script
  610. # ------------------------
  611.  
  612. echo "Running... Press Ctrl+C to stop."
  613.  
  614. echo ""
  615. # Function to prompt the user to continue or quit
  616. prompt_continue_or_quit() {
  617.     while true; do
  618.         # Recursively find and process videos and audio
  619.         video_count=$(eval "find \"$video_drop_dir\" -type f \( $filetypes \) | wc -l")
  620.         echo "Detected $video_count compatible video and/or audio file(s) in:" | tee -a "$log_file" | fmt -w $width
  621.    
  622.         if [ "$video_count"  -eq 0 ]; then
  623.             echo "$video_drop_dir folder created. Place your videos and audio here including files in folders using your favorite file manager for Android, and then run  the script again.  
  624.  
  625. Supported File Types:
  626.  
  627. Video: $video_ext
  628.  
  629. Audio: $audio_ext
  630.  
  631. Images: $img_ext" | tee -a "$log_file" | fmt -w $width
  632.             exit 0
  633.         fi
  634.  
  635.         # Prompt text
  636.         prompt_text="$video_drop_dir. You can start encoding now. Do you wish to proceed? (Y/N): "
  637.  
  638.         # Format the prompt text
  639.         formatted_prompt=$(echo "$prompt_text" | fmt -w $width)
  640.  
  641.         if $auto_yes; then
  642.             echo "$formatted_prompt"
  643.             echo "Y"
  644.             return 0  # Automatically continue
  645.         else
  646.             # Read user input with formatted prompt
  647.             read -p "$formatted_prompt" yn
  648.             case $yn in
  649.                 [Yy]* ) return 0;;  # Continue
  650.                 [Nn]* ) echo "Exiting script."; exit 0;;  # Quit
  651.                 * ) echo "Please answer Y or N.";;
  652.             esac
  653.         fi
  654.     done
  655. }
  656.  
  657. # Function to clean up file names
  658. clean_file_names() {
  659.     eval "find \"$video_drop_dir\" -type f \( $filetypes \)" | while read -r file; do
  660.         dir=$(dirname "$file")
  661.         base=$(basename "$file")
  662.         new_base=$(echo "$base" | sed 's/[^a-zA-Z0-9 ._-]//g' | tr -s ' ')
  663.         new_file="$dir/$new_base"
  664.         if [ "$file" != "$new_file" ]; then
  665.             mv "$file" "$new_file"
  666.         fi
  667.     done
  668. }
  669.  
  670. # Clean up file names before processing
  671. clean_file_names
  672.  
  673. # Prompt the user to continue or quit?
  674. prompt_continue_or_quit
  675.  
  676. # Initialize ffmpeg_custom_options
  677. ffmpeg_custom_options="-c:v libx265 -x265-params \"deblock=-1:no-sao=1:keyint=250:aq-mode=3:psy-r=0.75:psy-rdoq=2.0:rd=4:rdoq-level=1:rect=0:strong-intra-smoothing=0\" -crf $crf -preset $preset -c:a libopus -vbr on -ac 2 -af \"loudnorm=I=-23:LRA=7:TP=-2\""
  678.  
  679. # Add avg audio bitrate if avg_audio_bitrate is set
  680. if [ -n "$avg_audio_bitrate" ]; then
  681.     ffmpeg_custom_options="$ffmpeg_custom_options -b:a ${avg_audio_bitrate}k"
  682. fi
  683.  
  684. # Add maxrate and bufsize options if max_video_bitrate is set
  685. if [ -n "$max_video_bitrate" ]; then
  686.     ffmpeg_custom_options="$ffmpeg_custom_options -maxrate ${max_video_bitrate}k -bufsize 60M"
  687. fi
  688.  
  689. # Function to check the log file for "Killed" message
  690. check_for_killed_message() {
  691.     if grep -q " Killed     " "$log_file"; then
  692.         echo "$(date '+%Y-%m-%d %H:%M:%S') Error: Process was killed. Check log file for details." | tee -a "$log_file"
  693.         return 1
  694.     fi
  695.     return 0
  696. }
  697.  
  698. echo "Starting conversion process..." | tee -a "$log_file"
  699.  
  700. # -----------------------------
  701. #    Image Encoder
  702. # -----------------------------
  703.  
  704. width=$(tput cols)
  705.  
  706. # Function to process image files
  707. process_image() {
  708.     local image="$1"
  709.     local relative_path="${image#$video_drop_dir/}"
  710.     local dir_path=$(dirname "$relative_path")
  711.     local base_name=$(basename "$relative_path" | tr -cd '[:alnum:]._ -')
  712.     local output_dir="$output_dir_base/$dir_path"
  713.     local output_file="$output_dir/${base_name}_converted.png"
  714.  
  715.     mkdir -p "$output_dir"  # Create output directory
  716.  
  717.     echo "$(date '+%Y-%m-%d %H:%M:%S') Processing $image to $output_file" | tee -a "$log_file"
  718.  
  719.     # Get input image resolution
  720.     input_resolution=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 "$image" | tr -d '[:space:],')
  721.  
  722.     if [ -n "$resolution" ]; then
  723.         if [ "$input_resolution" -gt "$resolution" ]; then
  724.             scale_filter="scale=-2:$resolution:flags=lanczos"
  725.             echo "Input resolution ($input_resolution) is higher than user-defined resolution ($resolution). Using user-defined resolution." | tee -a "$log_file"
  726.     else
  727.             echo "Input resolution ($input_resolution) is lower or equal to user-defined resolution ($resolution). Keeping original resolution." | tee -a "$log_file"
  728.         fi
  729.     else
  730.         echo "Resolution set to: original" | tee -a "$log_file"
  731.     fi
  732.  
  733.     # Construct the FFmpeg command for image processing
  734.     ffmpeg_command="ffmpeg -nostdin -loglevel error -stats -y -i \"$image\" -compression_level 100 -vf \"$scale_filter\" \"$output_file\""
  735.  
  736.     echo "$ffmpeg_command" | tee -a "$log_file"
  737.  
  738.     # Execute the FFmpeg command
  739.     eval $ffmpeg_command 2>&1 | tee -a "$log_file"
  740.  
  741.     # Check for "Killed" message in the log file
  742.     if ! check_for_killed_message; then
  743.         echo "$(date '+%Y-%m-%d %H:%M:%S') Error: Process was killed. Exiting." | tee -a "$log_file"
  744.         exit 1
  745.     fi
  746.  
  747.     if [ $? -eq 0 ]; then
  748.       #  mv "$temp_output_file" "$output_file"  # Rename the temporary file to the final output file
  749.         mkdir -p "$video_processing_dir/$dir_path"  # Create processing directory
  750.         mv "$image" "$video_processing_dir/$relative_path"
  751.         echo ""
  752.         echo "$(date '+%Y-%m-%d %H:%M:%S') Converted $image. Your original files will be in the $video_processing_dir folder for comparison. Your new files are in $output_dir_base" | tee -a "$log_file" | fmt -w $width
  753.     else
  754.         echo ""
  755.         echo "$(date '+%Y-%m-%d %H:%M:%S') Error processing \"$image\". Check log file for details." | tee -a "$log_file"
  756.         exit 1
  757.     fi
  758. }
  759.  
  760. # -----------------------------
  761. #    Audio Encoder
  762. # -----------------------------
  763.  
  764. width=$(tput cols)
  765.  
  766. # Function to process audio files
  767. process_audio() {
  768.     local audio="$1"
  769.     local relative_path="${audio#$video_drop_dir/}"
  770.     local dir_path=$(dirname "$relative_path")
  771.     local base_name=$(basename "$relative_path" | tr -cd '[:alnum:]._ -')
  772.     local output_dir="$output_dir_base/$dir_path"
  773.     local output_file="$output_dir/${base_name}_converted.opus"
  774.     local temp_output_file="$output_file.tmp"
  775.  
  776.     mkdir -p "$output_dir"  # Create output directory
  777.  
  778.     echo "$(date '+%Y-%m-%d %H:%M:%S') Processing $audio to $output_file" | tee -a "$log_file"
  779.  
  780.     # Construct the FFmpeg command for audio processing
  781.     local ffmpeg_command="ffmpeg -nostdin -loglevel error -stats -stats_period 1 -y -i \"$audio\" -c:a libopus -b:a ${avg_audio_bitrate}k -vbr on -ac 2 -af \"loudnorm=I=-23:LRA=7:TP=-2\" -f opus \"$temp_output_file\""
  782.  
  783.     echo "$ffmpeg_command" | tee -a "$log_file"
  784.  
  785.     # Execute the FFmpeg command
  786.     eval $ffmpeg_command 2>&1 | tee -a "$log_file"
  787.  
  788.     # Check for "Killed" message in the log file
  789.     if ! check_for_killed_message; then
  790.         echo "$(date '+%Y-%m-%d %H:%M:%S') Error: Process was killed. Exiting." | tee -a "$log_file"
  791.         exit 1
  792.     fi
  793.  
  794.     if [ $? -eq 0 ]; then
  795.         mv "$temp_output_file" "$output_file"  # Rename the temporary file to the final output file
  796.         mkdir -p "$video_processing_dir/$dir_path"  # Create processing directory
  797.         mv "$audio" "$video_processing_dir/$relative_path"
  798.         echo ""
  799.         echo "$(date '+%Y-%m-%d %H:%M:%S') Converted $audio. Your original files will be in the $video_processing_dir folder for comparison. Your new files are in $output_dir_base" | tee -a "$log_file" | fmt -w $width
  800.     else
  801.         echo ""
  802.         echo "$(date '+%Y-%m-%d %H:%M:%S') Error processing \"$audio\". Check log file for details." | tee -a "$log_file"
  803.         exit 1
  804.     fi
  805. }
  806.  
  807. # ------------------------------
  808. #      Video Encoder
  809. # ------------------------------
  810.  
  811. width=$(tput cols)
  812.  
  813. # Function to check the log file for "Killed" message
  814. check_for_killed_message() {
  815.     if grep -q " Killed     " "$log_file"; then
  816.         echo "$(date '+%Y-%m-%d %H:%M:%S') Error: Process was killed. Check log file for details." | tee -a "$log_file" | fmt -w $width
  817.         exit 1
  818.     fi
  819. }
  820.  
  821. process_video() {
  822.     local video="$1"
  823.     local relative_path="${video#$video_drop_dir/}"
  824.     local dir_path=$(dirname "$relative_path")
  825.     local base_name=$(basename "$relative_path" | tr -cd '[:alnum:]._ -')
  826.     local output_dir="$output_dir_base/$dir_path"
  827.     local output_file="$output_dir/${base_name}_converted.mkv"
  828.  
  829.    
  830.     # Get input video resolution
  831.     input_resolution=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 "$video" | tr -d '[:space:],')
  832.  
  833.     if [ -n "$resolution" ]; then
  834.         if [ "$input_resolution" -lt "$resolution" ]; then
  835.             local scale_filter="scale=-2:$input_resolution:flags=lanczos"
  836.             echo "Input resolution ($input_resolution) is lower than user-defined resolution ($resolution). Keeping original resolution." | tee -a "$log_file"
  837.         else
  838.             local scale_filter="scale=-2:$resolution:flags=lanczos"
  839.             echo "Input resolution ($input_resolution) is higher or equal to user-defined resolution ($resolution). Using user-defined resolution." | tee -a "$log_file"
  840.         fi
  841.     else
  842.         echo "Resolution set to: original" | tee -a "$log_file"
  843.     fi
  844.  
  845.     mkdir -p "$output_dir"  # Create output directory
  846.  
  847.     echo "$(date '+%Y-%m-%d %H:%M:%S') Processing $video to $output_file" | tee -a "$log_file"
  848.  
  849.     # Get the frame rate of the input video
  850.     input_fps=$(ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate,r_frame_rate -of csv=p=0 "$video" | awk -F'/' '{if ($2) print $1/$2; else print $1}' | bc -l)
  851.  
  852.     # Define common frame rates
  853.     common_fps=(23.976 24 25 29.97 30 50 59.94 60)
  854.  
  855.     # Function to find the nearest valid frame rate
  856.     nearest_fps() {
  857.         local fps=$1
  858.         local nearest=${common_fps[0]}
  859.         local min_diff=$(echo "scale=5; $fps - ${common_fps[0]}" | bc | awk '{print ($1 >= 0) ? $1 : -$1}')
  860.         for rate in "${common_fps[@]}"; do
  861.             local diff=$(echo "scale=5; $fps - $rate" | bc | awk '{print ($1 >= 0) ? $1 : -$1}')
  862.             if (( $(echo "$diff < $min_diff" | bc -l) )); then
  863.                 min_diff=$diff
  864.                 nearest=$rate
  865.             fi
  866.         done
  867.         echo $nearest
  868.     }
  869.  
  870.     # Round the frame rate to the nearest valid frame rate
  871.     rounded_fps=$(nearest_fps $input_fps)
  872.  
  873.     # Determine the lower frame rate
  874.     if (( $(echo "$rounded_fps > $output_fps" | bc -l) )); then
  875.         final_fps=$output_fps
  876.     else
  877.         final_fps=$rounded_fps
  878.     fi
  879.  
  880. # Set the initial video filter option
  881. video_filter_option="yadif=2,fps=$final_fps"
  882.  
  883. # Check if scale_filter is not empty
  884. if [ -n "$scale_filter" ]; then
  885.     video_filter_option="${video_filter_option},${scale_filter}"
  886. fi
  887.  
  888. echo "Video filter option: $video_filter_option" | tee -a "$log_file"
  889.  
  890. # Detect the pixel format using ffprobe
  891. input_file="$video"
  892. pix_fmt=$(ffprobe -v repeat+level+error -select_streams v:0 -show_entries stream=pix_fmt -of default=noprint_wrappers=1:nokey=1 "$input_file" | awk 'NR==1{print $1}')
  893.  
  894. echo "Pixel format: $pix_fmt"
  895.  
  896. # Validate the pixel format
  897. valid_pix_fmt=$(ffmpeg -pix_fmts | grep -w "$pix_fmt")
  898.  
  899. # Check if 10-bit encoding is selected
  900. if [[ "$pix_fmt" == *"10le"* || "$pix_fmt" == *"10be"* ]]; then
  901.     video_filter_option="$video_filter_option,deband=1thr=0.01:2thr=0.01:3thr=0.01:4thr=0.01:range=4:direction=-3.14:blur=1:coupling=0"
  902. fi
  903.  
  904. # Define a variable for probe size and analyze duration
  905. probe_analyze_opts="-probesize 2147483647 -analyzeduration 2147483647"
  906.  
  907. # Detect subtitle codecs and convert unsupported ones
  908. subtitle_codecs=$(ffprobe -v error $probe_analyze_opts -select_streams s -show_entries stream=codec_name -of csv=p=0 "$input_file")
  909. subtitle_map=""
  910. if [ -n "$subtitle_codecs" ]; then
  911.     subtitle_map="-map 0:s"  # Include all subtitle streams
  912.     i=0
  913.     while read -r codec; do
  914.         case "$codec" in
  915.             # Text-based subtitles to be copied directly
  916.             srt)
  917.                 subtitle_map="$subtitle_map -c:s:$i copy"
  918.                 ;;
  919.             # Other text-based subtitles to be converted to SRT
  920.             ass|ssa|webvtt|eia_608|eia_708|scc|sami|ttml|smi|teletext|mov_text|microdvd|subviewer)
  921.                 subtitle_map="$subtitle_map -c:s:$i srt"
  922.                 ;;
  923.             # Bitmap-based subtitles to be converted to DVD subtitles
  924.             dvdsub|pgs|vobsub|hdmv_pgs_subtitle|dvd_subtitle)
  925.                 subtitle_map="$subtitle_map -c:s:$i dvdsub"
  926.                 ;;
  927.             # Copy other compatible subtitles
  928.             *)
  929.                 subtitle_map="$subtitle_map -c:s:$i copy"
  930.                 ;;
  931.         esac
  932.         i=$((i + 1))
  933.     done <<< "$subtitle_codecs"
  934. else
  935.     echo "No subtitle streams detected." | tee -a "$log_file"
  936. fi
  937.  
  938. # Combine common and custom FFmpeg options
  939. combined_ffmpeg_options="-nostdin -loglevel error -stats -stats_period 5 $probe_analyze_opts -y -fix_sub_duration -i \"$video\" -map 0:v:0 -map 0:a:? -map_chapters 0 $ffmpeg_custom_options"
  940.  
  941. # Construct the FFmpeg command
  942. local ffmpeg_command
  943. if [ -n "$valid_pix_fmt" ]; then
  944.     if [ -n "$subtitle_map" ]; then
  945.         ffmpeg_command="ffmpeg $combined_ffmpeg_options -vf \"$video_filter_option\" -pix_fmt $pix_fmt $subtitle_map"
  946.     else
  947.         ffmpeg_command="ffmpeg $combined_ffmpeg_options -vf \"$video_filter_option\" -pix_fmt $pix_fmt"
  948.     fi
  949. else
  950.     if [ -n "$subtitle_map" ]; then
  951.         ffmpeg_command="ffmpeg $combined_ffmpeg_options -vf \"$video_filter_option\" $subtitle_map"
  952.     else
  953.         ffmpeg_command="ffmpeg $combined_ffmpeg_options -vf \"$video_filter_option\""
  954.     fi
  955. fi
  956.  
  957. # Ensure all subtitle streams are marked as "default: off"
  958. subtitle_streams=$(ffprobe -v error $probe_analyze_opts -select_streams s -show_entries stream=index -of csv=p=0 "$input_file")
  959. if [ -n "$subtitle_streams" ]; then
  960.     for stream_index in $subtitle_streams; do
  961.         ffmpeg_command="$ffmpeg_command -disposition:s:$stream_index 0"
  962.     done
  963. fi
  964.  
  965. # Add the output file name at the end
  966. ffmpeg_command="$ffmpeg_command \"$output_file\""
  967.  
  968. echo "FFmpeg command: $ffmpeg_command" | tee -a "$log_file"
  969.  
  970. # Execute the FFmpeg command
  971. if ! eval $ffmpeg_command 2>&1 | tee -a "$log_file"; then
  972.     echo "FFmpeg command failed. Check the log for details." | tee -a "$log_file"
  973.     exit 1
  974. fi
  975.  
  976.     # Check for "Killed" message in the log file
  977.     check_for_killed_message
  978.  
  979.    if [ $? -eq 0 ]; then
  980.         mkdir -p "$video_processing_dir/$dir_path"  # Create processing directory
  981.         mv "$video" "$video_processing_dir/$relative_path"
  982.         echo ""
  983.         echo "$(date '+%Y-%m-%d %H:%M:%S') Complete.  Your original files are in $video_processing_dir.  Your new files are in $output_dir_base" | tee -a "$log_file" | fmt -w $width
  984.     else
  985.         echo ""
  986.         echo "$(date '+%Y-%m-%d %H:%M:%S') Error processing \"$video\". Check log file for details." | tee -a "$log_file"
  987.         exit 1
  988.     fi
  989. }
  990.  
  991. # --------------------------------------
  992. #    Start Batch Encoding
  993. # --------------------------------------
  994.  
  995. width=$(tput cols)
  996.  
  997. stop_processing=false
  998.  
  999. # Function to handle SIGINT (Ctrl+C)
  1000. handle_sigint() {
  1001.     echo ""
  1002.     echo "Caught SIGINT (Ctrl+C). Exiting immediately." | fmt -w $width
  1003.     stop_processing=true
  1004.     exit 1  # Exit immediately without performing cleanup
  1005. }
  1006.  
  1007. # Trap SIGINT and call the handle_sigint function
  1008. trap handle_sigint SIGINT
  1009.  
  1010. # Process each file found
  1011. eval "find \"$video_drop_dir\" -type f \( $filetypes \)" | while read -r file; do
  1012.     if [ "$stop_processing" = true ]; then
  1013.         echo "Stopping processing due to SIGINT."
  1014.         exit 1
  1015.     fi
  1016.  
  1017.     case "$file" in
  1018.         *.mp3|*.aac|*.wav|*.flac|*.ogg|*.m4a|*.wma|*.ac3|*.eac3|*.opus|*.amr|*.aiff|*.alac|*.caf|*.dts|*.mka|*.mp2|*.ra|*.tta|*.voc)
  1019.             process_audio "$file" || exit 1
  1020.             ;;
  1021.  
  1022.         *.mp4|*.mkv|*.avi|*.mov|*.flv|*.wmv|*.webm|*.mts|*.3gp|*.mpeg|*.ogv|*.rmvb|*.m4v|*.f4v|*.vob|*.ts|*.m2ts|*.asf|*.swf|*.m2v|*.divx|*.xvid|*.mpg|*.mpe|*.m1v|*.dvr-ms|*.mxf|*.gxf|*.bink|*.mng|*.nsv)
  1023.             process_video "$file" || exit 1
  1024.             ;;
  1025.  
  1026.         *.jpg|*.jpeg|*.png|*.bmp|*.tiff|*.gif|*.webp|*.heic|*.heif|*.jxl|*.ppm|*.pgm|*.pbm|*.pam|*.tga|*.sgi|*.pcx|*.ras|*.xbm|*.xpm|*.ico|*.dds|*.exr|*.hdr|*.svg)
  1027.             process_image "$file" || exit 1
  1028.             ;;
  1029.     esac
  1030. done
  1031.  
  1032. # -----------------------------
  1033. #     Finishing Up
  1034. # -----------------------------
  1035.  
  1036. width=$(tput cols)
  1037.  
  1038. find "$video_drop_dir" -type d -empty -delete
  1039. echo "removed empty folders in $video_drop_dir directory"
  1040.  
  1041. # final output message
  1042. echo ""
  1043. echo "Log file is in $video_drop_dir.  There may be unprocessed media files or other incompatible files.  Some files may need to be remuxed for compatibility." | tee -a "$log_file" | fmt -w $width
  1044. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement