Created
July 19, 2024 06:13
-
-
Save jmcmullen/519633b197e51101fd3e896abe0d452f to your computer and use it in GitHub Desktop.
Convert all FLAC files in a directory to AIFF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Check if ffmpeg is installed | |
| if ! command -v ffmpeg &> /dev/null | |
| then | |
| echo "Can't find ffmpeg, please install it first." | |
| exit | |
| fi | |
| # Set directory containing FLAC files (modify this path) | |
| flac_dir="." | |
| # Flag to control deletion (optional) | |
| delete_flag=false | |
| # Check for -d flag | |
| if [[ "$1" == "-d" ]]; then | |
| delete_flag=true | |
| echo "Enabled FLAC file deletion after conversion." | |
| fi | |
| # Loop through all FLAC files in the directory | |
| for flac_file in "$flac_dir"/*.flac; do | |
| # Extract filename without extension | |
| filename="${flac_file%.*}" | |
| # Construct the target AIFF filename | |
| aiff_file="$filename.aiff" | |
| # Skip if the AIFF file already exists | |
| if [[ -f "$aiff_file" ]]; then | |
| echo "Skipping $flac_file (AIFF already exists)" | |
| # Delete the original FLAC file if -d flag is set | |
| if [[ $delete_flag == true ]]; then | |
| rm "$flac_file" | |
| fi | |
| continue | |
| fi | |
| # Convert FLAC to AIFF using ffmpeg | |
| ffmpeg -i "$flac_file" -c:a pcm_s16le "$aiff_file" | |
| # Delete the original FLAC file if -d flag is set | |
| if [[ $delete_flag == true ]]; then | |
| rm "$flac_file" | |
| fi | |
| done | |
| echo "FLAC to AIFF conversion complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment