- #!/bin/bash
- # Check if ffmpeg is installed
- if ! command -v ffmpeg &> /dev/null; then
- echo "ffmpeg is not installed. Please install ffmpeg and try again."
- exit 1
- fi
- # Function to convert video to audio using the selected audio quality
- function convert_to_audio() {
- local input_file=$1
- # Output audio file with the same name but ".mp3" extension
- local output_file="${input_file%.*}.mp3"
- # Check if the output file already exists
- if [ -f "$output_file" ]; then
- echo "Output file already exists: $output_file"
- exit 1
- fi
- # Audio quality options
- local quality_options=("128K" "192K" "256K" "320K")
- # Function to convert video to audio using the selected audio quality
- function convert_audio() {
- local selected_quality=${quality_options[$selected_index]}
- echo "Conversion in progress..."
- ffmpeg -i "$input_file" -b:a "$selected_quality" -vn "$output_file" ## 2> /dev/null
- echo "Conversion complete. The audio file is saved as: $output_file"
- exit 0
- }
- # Main loop for audio conversion
- while true; do
- clear
- echo "Audio Conversion Options:"
- echo "1) Convert to MP3"
- echo "2) Back to Main Menu"
- read -p "Enter your choice: " audio_choice
- case $audio_choice in
- 1)
- # Display audio quality options
- clear
- echo "Select Audio Quality:"
- for i in "${!quality_options[@]}"; do
- echo "$(($i+1))) ${quality_options[$i]}"
- done
- read -p "Enter the number for the desired audio quality: " selected_index
- # Check if the selected index is within the valid range
- if [[ "$selected_index" =~ ^[0-9]+$ ]] && ((selected_index >= 1 && selected_index <= ${#quality_options[@]})); then
- selected_index=$((selected_index - 1))
- convert_audio
- else
- echo "Invalid selection. Please try again."
- fi
- ;;
- 2)
- exit 0
- ;;
- *)
- echo "Invalid choice. Please try again."
- ;;
- esac
- done
- }
- # Function to convert video to different video quality options
- function convert_to_video() {
- local input_file=$1
- # Output video file with the same name but different quality and extension
- local output_file_base="${input_file%.*}"
- local output_file=""
- local selected_resoluti
- local bitrate=""
- # Video quality options
- local resoluti "1280:720" "854:480" "640:360")
- # Function to convert video using the selected resolution and bitrate
- function convert_video() {
- echo "Conversion in progress..."
- # Check if bitrate is set
- if [ -n "$bitrate" ]; then
- ffmpeg -i "$input_file" -b:v "$bitrate" -c:v libx264 -preset medium -vf "scale=$selected_resolution" "$output_file" ## 2> /dev/null
- else
- ffmpeg -i "$input_file" -c:v libx264 -preset medium -vf "scale=$selected_resolution" "$output_file" ## 2> /dev/null
- fi
- echo "Conversion complete. The video file is saved as: $output_file"
- exit 0
- }
- # Main loop for video conversion
- while true; do
- clear
- echo "Video Conversion Options:"
- echo "1) Convert to different video resolution"
- echo "2) Back to Main Menu"
- read -p "Enter your choice: " video_choice
- case $video_choice in
- 1)
- # Display video resolution options
- clear
- echo "Select Video Resolution:"
- for i in "${!resolution_options[@]}"; do
- echo "$(($i+1))) ${resolution_options[$i]}"
- done
- read -p "Enter the number for the desired video resolution: " selected_index
- # Check if the selected index is within the valid range
- if [[ "$selected_index" =~ ^[0-9]+$ ]] && ((selected_index >= 1 && selected_index <= ${#resolution_options[@]})); then
- selected_index=$((selected_index - 1))
- selected_resoluti
- # Display bitrate options
- clear
- echo "Select Bitrate Option for $selected_resolution:"
- echo "1) Default Bitrate"
- echo "2) Custom Bitrate"
- read -p "Enter your choice: " bitrate_choice
- case $bitrate_choice in
- 1)
- bitrate=""
- ;;
- 2)
- read -p "Enter the custom bitrate (e.g., 1000k): " bitrate
- ;;
- *)
- echo "Invalid choice. Using default bitrate."
- ;;
- esac
- # Set output file name
- output_file="${output_file_base}_${selected_resolution}.mp4"
- convert_video
- else
- echo "Invalid selection. Please try again."
- fi
- ;;
- 2)
- exit 0
- ;;
- *)
- echo "Invalid choice. Please try again."
- ;;
- esac
- done
- }
- # Main loop for the program
- while true; do
- clear
- echo "Main Menu:"
- echo "Script created by:"
- echo "
- ( ) )
- ( )\ ) ( /( ( /( (
- ( )\ (()/( )\()) )\())( ( )\
- )\((((_)( /(_)|(_)\ ((_)\ )\ )((_)
- ((_))\ _ )\(_)) ((_)_ ((_|(_|(_)_
- | __(_)_\(_) __| / _ \ \ / / __| _ )
- | _| / _ \ \__ \| (_) \ V /| _|| _ \
- |___/_/ \_\|___/ \___/ |_| |___|___/
- twitter.com/easoyeb
- "
- echo "1) Convert Video to Audio"
- echo "2) Convert Video to Different Video Quality"
- echo "3) Exit"
- read -p "Enter your choice: " main_choice
- case $main_choice in
- 1)
- if [ $# -eq 0 ]; then
- echo "Please provide a video file as an argument."
- exit 1
- fi
- convert_to_audio "$1"
- ;;
- 2)
- if [ $# -eq 0 ]; then
- echo "Please provide a video file as an argument."
- exit 1
- fi
- convert_to_video "$1"
- ;;
- 3)
- echo "Exiting the program. Goodbye!"
- exit 0
- ;;
- *)
- echo "Invalid choice. Please try again."
- ;;
- esac
- done