Last active
June 22, 2022 03:59
-
-
Save maci1011/648f322896d2245d6753a7cc5c710997 to your computer and use it in GitHub Desktop.
Linux / Mac Osx - Bash Script - Convert files of a directory - from flac to mp3 - with VLC.
This file contains 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/sh | |
# cd to/your/directory before... | |
######################## Transcode the files using ... ######################## | |
acodec="mp3" | |
ab="192" | |
channels="2" | |
samplerate="44100" | |
mux="raw" | |
############################################################################### | |
# Store path to VLC in $vlc | |
if command -pv vlc >/dev/null 2>&1; then | |
# Linux should find "vlc" when searching PATH | |
vlc="vlc" | |
else | |
# macOS seems to need an alias | |
vlc="/Applications/VLC.app/Contents/MacOS/VLC" | |
fi | |
# Sanity check | |
if ! command -pv "$vlc" >/dev/null 2>&1; then | |
printf '%s\n' "Cannot find path to VLC. Abort." >&2 | |
exit 1 | |
fi | |
for filename in ./*.flac; do | |
# This is cause sometime vlc could crash - if so, execute this script again | |
if test -f "$filename.mp3"; then | |
eval $(stat -s "$filename.mp3") | |
if (( $st_size > 32768 )) ; then | |
printf '%s\n' "'$filename' skipped... " | |
printf '\n' | |
continue | |
fi | |
fi | |
printf '%s\n' "=> Transcoding '$filename'... " | |
"$vlc" -I dummy "$filename" --sout="#transcode{acodec=$acodec,samplerate=$samplerate,channels=$channels,ab=$ab}:standard{mux=$mux,dst=\"$filename.mp3\",access=file}" vlc://quit | |
ls -lh "$filename" "$filename.mp3" | |
printf '\n' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment