13

My latest challenge is finding out the correct way to convert several .flac files to 320k .mp3's. Does anyone know how to do this, maybe with avconv, without using an elaborate python script, decompressing the files to .wav first, or any other complicated scheme?

24

First of all you must make sure that it's installed.

sudo apt-get install libav-tools

It should have lame and flac codecs, now is just create a bash script to finish the job:

$ cat > flac2mp3

Here the shell will wait for your commands, copy and paste this:

#!/bin/bash
[[ $# == 0 ]] && set -- *.flac
for f; do
  avconv -i "$f" -qscale:a 0 "${f[@]/%flac/mp3}"
done

Now press Ctrl + D. Make your script executable chmod +x flac2mp3. Now go you can use it like this:

./flac2mp3 /path/with/all/my/flacs/*.flac

You can also copy the script to somewhere in your PATH and then cd to the directory with the flacs and execute it.


With regards to the following parameter used above:

-qscale:a 0

will not actually give you a exact 320k file, although it is probably the best setting to use anyway. The suggested settings actually give a target bitrate of 245 kbits/s with a range of 220-260. If you really wanted 320k mp3s you would have to go to CBR and use:

-c:a libmp3lame -b:a 320k

but you would need great ears to notice the difference...

Reference:

| improve this answer | |
5

For Single File i use this and its work perfect for me.

avconv -i [FileName.flac] -c:a libmp3lame -b:a 320k [FileName.mp3]
| improve this answer | |
2

I know this is a quite old thread, but I have had a similar task, so I created a little tool for converting FLAC to MP3. (Raspberry pi 3, with OSMC) Maybe someone will find this with the same search, that I did.

https://github.com/erdnuesse/flac-to-mp3

Features:

  • Multithreaded
  • preserves FLAC tags
  • preserve relative directory structure
  • does not delete, does not overwrite

It consists of 2 scripts, the first starts the given number of worker-instances (one for each core, or how many you want). While the second does the work.

It's based on avconv (my OSMC has 4 cores, but does not support ffmpeg out-of-the-box, so, meh, whatever.)

It's still running, so I hope, there will be no major setbacks.

Regards, Kay

| improve this answer | |
1

This script will convert all the files in the current directory to mp3 or just about any file extension you wish from just about any audio video filetype.

I've named the script mp423 because it's easy to remember and common filetypes although you can convert any type.

#!/bin/bash
for f in *."$1"; do
 mplayer "$f" -novideo -ao pcm:file=tmp.wav
 lame -V 0 -q 0 tmp.wav "${f/.$1/.$2}"
 rm -f tmp.wav
done

Here's a use example. Save the script to your home directory and don't forget to make it executable. There is no need to provide any filename or path. Just cd into the directory where the files are and then run the script like this:

~/mp423 flac mp3 

Another example converting all mp4 files in a directory to mp3:

~/mp423 mp4 mp3

Convert all mp4 to m4a:

~/mp423 mp4 m4a

This comes in handy when you have an entire directory full of files you need to convert.

If you only have one or two files you want to convert, just make a directory to run the files in.

Also, does not delete the original files.

| improve this answer | |
  • obligatory do not parse ls – qwr Dec 31 '19 at 20:56
  • @qwr Yeah, this was a while ago. I fixed it. Thanks! – mchid Dec 31 '19 at 23:59
  • Additionally, I used to use avconv or ffmpeg but mplayer with lame is so much faster. Although it decompresses to wav first, it's not complicated considering how much time this saves when converting a large number of files or even a single large file. Not to mention the cool output that shows your progress. – mchid Jan 1 at 0:11
  • ffmpeg is fast enough for me (it runs at about 50-60x) – qwr Jan 1 at 3:56
  • @qwr I use the highest quality options with ffmpeg so that may be why it is so slow (I do have great ears). – mchid Jan 1 at 7:59
0

This flac2mp3.sh script uses ffmpeg to convert a folder tree of FLAC files into another folder tree of MP3 files. Cover art is included, when present. You can set a CORES variable to create background jobs to convert several files at a time.

| improve this answer | |
  • 3
    If that link dies this answer will no longer be useful. Can you please post the steps here to future-proof your answer? – Tom Brossman Nov 11 '18 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.