Skip to content

Instantly share code, notes, and snippets.

@klappradla
Last active December 10, 2022 20:02
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save klappradla/04c41d559f71bcc9527e to your computer and use it in GitHub Desktop.
Save klappradla/04c41d559f71bcc9527e to your computer and use it in GitHub Desktop.
Using lame command line tool (e.g. convert flac to mp3
# Convert .flac to .mp3 (lossless)
for f in *.flac; do ffmpeg -i "$f" -aq 1 "${f%flac}mp3"; done
# Convert .flac to .mp3, compress to ~ 120k
for f in *.flac; do ffmpeg -i "$f" -aq 5 "${f%flac}mp3"; done
# Convert .flac to mp3, compress to ~ 128k
for f in *.flac; do ffmpeg -i "$f" -b:a 128k "${f%flac}mp3"; done
# Convert .flac to mp3, compress to variable 190k
for f in *.flac; do ffmpeg -i "$f" -aq 2 "${f%flac}mp3"; done
# Compress .mp3 files with lame to constant 128k
for i in *.mp3; do lame --preset 128 "$i" "${i}.mp3"; done
# Compress .mp3 to variable 190k (constant quality)
for i in *.mp3; do lame -V2 "$i"; done
# Compress .mp3 to variable 190k bitrate and replace files
for i in *.mp3; do lame -V2 "$i" tmp && mv tmp "$i"; done
@westondeboer
Copy link

This worked perfect, thanks so much for this!

@pdupreez
Copy link

This is very nice, but how do you ensure that you do not inflate the bitrate? I have found a few flac files with very low bit rates (why, I do not know) but it would be useful to ensure that it only do a conversion if the flac bitrate is higher than target bitrate.

Is that possible?

@batthias
Copy link

you should add the -nostdin option and either -n or -y to all the ffmpeg calls

@jolespin
Copy link

I've been looking for something like this. thanks!

@piotrpolak
Copy link

Amazing!!11

@trudge42
Copy link

This is really great, and thank you. It works fine in a Mac shell, but I'd like to run it from a Perl script. When I do it seems to hang and the perl script does not continue. Ideas / suggestions?

@klappradla
Copy link
Author

Hm, I don't think I can help you there @trudge42 😞 I put these snippets down at what feel like ages ago because I needed to convert something... I'm not familiar with the details in there plus I don't know the Perl language 🤷‍♂️

But maybe share you're approach and someone else may be able to chime in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment