Created
June 2, 2023 20:55
-
-
Save aayushdutt/b1b31210b111d8f76cfd97d10a5abab9 to your computer and use it in GitHub Desktop.
A bash script to concurrently convert flac files to mp3
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 | |
num_concurrent=6 | |
source_folder="<path to flac directory>" | |
destination_folder="<path to output mp3>" | |
if [ ! -d "$destination_folder" ]; then | |
mkdir -p "$destination_folder" | |
fi | |
process_concurrently() { | |
local i=0 | |
local j=0 | |
for file in "$source_folder"/*.flac; do | |
echo "Converting $file" | |
base_name=$(basename "$file" .flac) | |
echo "Saving to: $destination_folder/$base_name.mp3" | |
ffmpeg -y -i "$file" -codec:a libmp3lame -q:a 0 -map_metadata 0 -id3v2_version 3 -write_id3v1 1 "$destination_folder/$base_name.mp3" & | |
((i++)) | |
((j++)) | |
# Limit the number of concurrent processes | |
if [[ $j -eq $num_concurrent ]]; then | |
wait -n | |
((j--)) | |
fi | |
done | |
# Wait for all remaining processes to finish | |
wait | |
} | |
process_concurrently |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment