Facebook
From Soyeb, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 210
  1. #!/bin/bash
  2.  
  3. # Check if ffmpeg is installed
  4. if ! command -v ffmpeg &> /dev/null; then
  5.   echo "ffmpeg is not installed. Please install ffmpeg and try again."
  6.   exit 1
  7. fi
  8.  
  9. # Function to convert video to audio using the selected audio quality
  10. function convert_to_audio() {
  11.   local input_file=$1
  12.  
  13.   # Output audio file with the same name but ".mp3" extension
  14.   local output_file="${input_file%.*}.mp3"
  15.  
  16.   # Check if the output file already exists
  17.   if [ -f "$output_file" ]; then
  18.     echo "Output file already exists: $output_file"
  19.     exit 1
  20.   fi
  21.  
  22.   # Audio quality options
  23.   local quality_options=("128K" "192K" "256K" "320K")
  24.  
  25.   # Function to convert video to audio using the selected audio quality
  26.   function convert_audio() {
  27.     local selected_quality=${quality_options[$selected_index]}
  28.     echo "Conversion in progress..."
  29.     ffmpeg -i "$input_file" -b:a "$selected_quality" -vn "$output_file" ## 2> /dev/null
  30.     echo "Conversion complete. The audio file is saved as: $output_file"
  31.     exit 0
  32.   }
  33.  
  34.   # Main loop for audio conversion
  35.   while true; do
  36.     clear
  37.     echo "Audio Conversion Options:"
  38.     echo "1) Convert to MP3"
  39.     echo "2) Back to Main Menu"
  40.     read -p "Enter your choice: " audio_choice
  41.  
  42.     case $audio_choice in
  43.       1)
  44.         # Display audio quality options
  45.         clear
  46.         echo "Select Audio Quality:"
  47.         for i in "${!quality_options[@]}"; do
  48.           echo "$(($i+1))) ${quality_options[$i]}"
  49.         done
  50.         read -p "Enter the number for the desired audio quality: " selected_index
  51.  
  52.         # Check if the selected index is within the valid range
  53.         if [[ "$selected_index" =~ ^[0-9]+$ ]] && ((selected_index >= 1 && selected_index <= ${#quality_options[@]})); then
  54.           selected_index=$((selected_index - 1))
  55.           convert_audio
  56.         else
  57.           echo "Invalid selection. Please try again."
  58.         fi
  59.         ;;
  60.       2)
  61.         exit 0
  62.         ;;
  63.       *)
  64.         echo "Invalid choice. Please try again."
  65.         ;;
  66.     esac
  67.   done
  68. }
  69.  
  70. # Function to convert video to different video quality options
  71. function convert_to_video() {
  72.   local input_file=$1
  73.  
  74.   # Output video file with the same name but different quality and extension
  75.   local output_file_base="${input_file%.*}"
  76.   local output_file=""
  77.    local selected_resoluti
  78.   local bitrate=""
  79.  
  80.   # Video quality options
  81.    local resoluti "1280:720" "854:480" "640:360")
  82.  
  83.   # Function to convert video using the selected resolution and bitrate
  84.   function convert_video() {
  85.     echo "Conversion in progress..."
  86.  
  87.     # Check if bitrate is set
  88.     if [ -n "$bitrate" ]; then
  89.       ffmpeg -i "$input_file" -b:v "$bitrate" -c:v libx264 -preset medium -vf "scale=$selected_resolution" "$output_file" ## 2> /dev/null
  90.     else
  91.       ffmpeg -i "$input_file" -c:v libx264 -preset medium -vf "scale=$selected_resolution" "$output_file" ## 2> /dev/null
  92.     fi
  93.  
  94.     echo "Conversion complete. The video file is saved as: $output_file"
  95.     exit 0
  96.   }
  97.  
  98.   # Main loop for video conversion
  99.   while true; do
  100.     clear
  101.     echo "Video Conversion Options:"
  102.     echo "1) Convert to different video resolution"
  103.     echo "2) Back to Main Menu"
  104.     read -p "Enter your choice: " video_choice
  105.  
  106.     case $video_choice in
  107.       1)
  108.         # Display video resolution options
  109.         clear
  110.         echo "Select Video Resolution:"
  111.         for i in "${!resolution_options[@]}"; do
  112.           echo "$(($i+1))) ${resolution_options[$i]}"
  113.         done
  114.         read -p "Enter the number for the desired video resolution: " selected_index
  115.  
  116.         # Check if the selected index is within the valid range
  117.         if [[ "$selected_index" =~ ^[0-9]+$ ]] && ((selected_index >= 1 && selected_index <= ${#resolution_options[@]})); then
  118.           selected_index=$((selected_index - 1))
  119.            selected_resoluti
  120.  
  121.           # Display bitrate options
  122.           clear
  123.           echo "Select Bitrate Option for $selected_resolution:"
  124.           echo "1) Default Bitrate"
  125.           echo "2) Custom Bitrate"
  126.           read -p "Enter your choice: " bitrate_choice
  127.  
  128.           case $bitrate_choice in
  129.             1)
  130.               bitrate=""
  131.               ;;
  132.             2)
  133.               read -p "Enter the custom bitrate (e.g., 1000k): " bitrate
  134.               ;;
  135.             *)
  136.               echo "Invalid choice. Using default bitrate."
  137.               ;;
  138.           esac
  139.  
  140.           # Set output file name
  141.           output_file="${output_file_base}_${selected_resolution}.mp4"
  142.  
  143.           convert_video
  144.         else
  145.           echo "Invalid selection. Please try again."
  146.         fi
  147.         ;;
  148.       2)
  149.         exit 0
  150.         ;;
  151.       *)
  152.         echo "Invalid choice. Please try again."
  153.         ;;
  154.     esac
  155.   done
  156. }
  157.  
  158. # Main loop for the program
  159. while true; do
  160.   clear
  161.   echo "Main Menu:"
  162.   echo "Script created by:"
  163.   echo "
  164.             (       )     )          
  165.       (     )\ ) ( /(  ( /(      (  
  166.  (    )\   (()/( )\()) )\())(  ( )\  
  167.  )\((((_)(  /(_)|(_)\ ((_)\ )\ )((_)
  168. ((_))\ _ )\(_))   ((_)_ ((_|(_|(_)_  
  169. | __(_)_\(_) __| / _ \ \ / / __| _ )
  170. | _| / _ \ \__ \| (_) \ V /| _|| _ \
  171. |___/_/ \_\|___/ \___/ |_| |___|___/      
  172.          twitter.com/easoyeb                          
  173. "
  174.   echo "1) Convert Video to Audio"
  175.   echo "2) Convert Video to Different Video Quality"
  176.   echo "3) Exit"
  177.   read -p "Enter your choice: " main_choice
  178.  
  179.   case $main_choice in
  180.     1)
  181.       if [ $# -eq 0 ]; then
  182.         echo "Please provide a video file as an argument."
  183.         exit 1
  184.       fi
  185.       convert_to_audio "$1"
  186.       ;;
  187.     2)
  188.       if [ $# -eq 0 ]; then
  189.         echo "Please provide a video file as an argument."
  190.         exit 1
  191.       fi
  192.       convert_to_video "$1"
  193.       ;;
  194.     3)
  195.       echo "Exiting the program. Goodbye!"
  196.       exit 0
  197.       ;;
  198.     *)
  199.       echo "Invalid choice. Please try again."
  200.       ;;
  201.   esac
  202. done