#!/usr/bin/env bash # --- Configuration --- directory="_converted" # Use "." for current folder or set a specific path output_format="mp3" # Target format ffmpeg_options="" # Optional: Add extra flags here (e.g., "-b:a 192k -vn") # Create the target directory mkdir "$directory" echo "Starting conversion to .$output_format in: $(pwd)" [[ -n "$ffmpeg_options" ]] && echo "Extra options: $ffmpeg_options" # Loop through all files for file in *; do # Skip directories [ -d "$file" ] && continue # Skip the script itself and files already in the target format [[ "$file" == "$0" ]] && continue [[ "$file" == *."$output_format" ]] && continue # Construct output filename output_file="${file%.*}.${output_format}" echo "Converting: $file → $output_file" # Convert file # $ffmpeg_options expands to nothing if empty, or adds your flags if set if ffmpeg -loglevel quiet -i "$file" $ffmpeg_options "$directory/$output_file"; then echo "Done: $output_file" else echo "Error: Failed to convert $file" fi done echo "All done."