stevepedwards.com/DebianAdmin linux mint IT admin tips info

Converting m4a to mp3

If you own m4a music files you bought off Apple iStore/other, and don't use iTunes now you have moved permanently away from Windoze (WHY NOT YET????!! Shame on you!!), you may know that m4a files don't play too well with mplayer on a remote server system if you are ssh'd into it – they are broken up sounding and show garbage in the ssh terminal:

m4a.png

This is not the case with remote mp3s or locally, and mplayer may even give you an album cover pic as it finds the copyright info in the m4a file:

.pngalbum

But, for your remote music server or car mp3 player, you may want/need to convert m4a files anyway.

Convert One Track At A Time

This is an easy process with a one-liner for faad and lame if you cd into the Album folder:

sudo apt-get install faad lame

faad -o tmp.wav 01TalkingtotheSun.m4a && lame -b 192 tmp.wav 01TalkingtotheSun.mp3

That's it! Just rsync or copy the files back to your remote server and you can run them via ssh and mplayer to play out of the remote servers speakers…

BUT - it will fail with track names containing white space or special characters; "(" ")" and " ' " for example. See below. For white space removal use ls to list the songs for rename to change:

  ls * | rename 's/ //g'

The files with a "(" were renamed using:

ls *\(* | rename 's/\(/_/g'

then the other bracket:

ls *\)* | rename 's/\)/_/g'

For files with apostrophes try:

for f in *; do mv "$f" `echo $f | sed 's/\x27//g'`; done

You can see this works with sed because the x27 is the hex value of the apostrophe key shown by:

stevee@T3400 ~ $ ascii
Usage: ascii [-dxohv] [-t] [char-alias...]
-t = one-line output -d = Decimal table -o = octal table -x = hex table
-h = This help screen -v = version information
Prints all aliases of an ASCII character. Args may be chars, C \-escapes,
English names, ^-escapes, ASCII mnemonics, or numerics in decimal/octal/hex.

Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex
0 00 NUL 16 10 DLE 32 20 48 30 0 64 40 @ 80 50 P 96 60 ` 112 70 p
1 01 SOH 17 11 DC1 33 21 ! 49 31 1 65 41 A 81 51 Q 97 61 a 113 71 q
2 02 STX 18 12 DC2 34 22 " 50 32 2 66 42 B 82 52 R 98 62 b 114 72 r
3 03 ETX 19 13 DC3 35 23 # 51 33 3 67 43 C 83 53 S 99 63 c 115 73 s
4 04 EOT 20 14 DC4 36 24 $ 52 34 4 68 44 D 84 54 T 100 64 d 116 74 t
5 05 ENQ 21 15 NAK 37 25 % 53 35 5 69 45 E 85 55 U 101 65 e 117 75 u
6 06 ACK 22 16 SYN 38 26 & 54 36 6 70 46 F 86 56 V 102 66 f 118 76 v
7 07 BEL 23 17 ETB 39 27 ' 55 37 7 71 47 G 87 57 W 103 67 g 119 77 w
8 08 BS 24 18 CAN 40 28 ( 56 38 8 72 48 H 88 58 X 104 68 h 120 78 x
9 09 HT 25 19 EM 41 29 ) 57 39 9 73 49 I 89 59 Y 105 69 i 121 79 y
10 0A LF 26 1A SUB 42 2A * 58 3A : 74 4A J 90 5A Z 106 6A j 122 7A z
11 0B VT 27 1B ESC 43 2B + 59 3B ; 75 4B K 91 5B [ 107 6B k 123 7B {
12 0C FF 28 1C FS 44 2C , 60 3C < 76 4C L 92 5C \ 108 6C l 124 7C |
13 0D CR 29 1D GS 45 2D - 61 3D = 77 4D M 93 5D ] 109 6D m 125 7D }
14 0E SO 30 1E RS 46 2E . 62 3E > 78 4E N 94 5E ^ 110 6E n 126 7E ~
15 0F SI 31 1F US 47 2F / 63 3F ? 79 4F O 95 5F _ 111 6F o 127 7F DEL

sed replaces the " ' " ,  with nothing between the "//" slashes.

You may want max bitrate, which will depend on the original m4a, probably 256 bit - research it - so you can set 192 to 256 as max quality for the mp3 file too.

Incidentally, if you are playing a video with say, Videos, through your sound system, you can also play a music file with mplayer - they multiplex through the sound card equally - may be handy if you are testing/editing a backing track to a home video etc...

Now the cmd needs amending to do a whole album at a time...

Convert Whole Album At Once In About 3 Minutes!

Spent ages on this...on the web etc..I got the first part happening, but can't get lame to do the same on one line...as xargs/faad converts all the m4a first, and drops the &&...

ls *m4a | xargs -I {} faad {} > {}.wav

ls -l Music/SteveHillage/Open\(Remastered\)/
-rw-r--r-- 1 stevee stevee 5497251 Aug 2 20:19 021988Aktivator.m4a
-rw-r--r-- 1 stevee stevee 26239020 Aug 27 01:51 021988Aktivator.wav

ls *m4a | xargs -I {} faad {} > {}.wav && ls *wav | xargs -I {} lame -b 256 {}.wav {}.mp3 doesn't work

Got this to work, but it still does the conversion to .wav for all files first, then converts wavs to mp3, but with a .wav.mp3 suffix, but I think thats the way faad and lame work so take control. It also stops at tracks 11-14 because of "'" and "(" in the names..

ls *m4a | xargs -I {} faad {} > {}; ls *wav | xargs -I {} lame -b 256 {} {}.mp3

ls -l
-rw-r--r-- 1 stevee stevee 0 Aug 27 10:37 {}
-rw-r--r-- 1 stevee stevee 12794171 Aug 2 20:19 01TalkingtotheSun.m4a
-rw-r--r-- 1 stevee stevee 63524908 Aug 27 10:37 01TalkingtotheSun.wav
-rw-r--r-- 1 stevee stevee 11525641 Aug 27 10:38 01TalkingtotheSun.wav.mp3

I renamed tracks like:

11Don'tDither,DoIt.m4a to 11DontDitherDoIt.m4a

and they all ran - lame doesn't like special chars...

lame.png

Also, I noticed during the conversion that these are 64 bits, so no point using -b 256 either - it just makes bigger files and takes longer...

Yep, this final line does the lot when you cd into the Album directory.

ls *m4a | xargs -I {} faad {} > {}; ls *wav | xargs -I {} lame -b 256 {} {}.mp3; ls *wav* | rename 's/wav.mp3/mp3/g'

On my T3400 Quad server it's pretty quick!

mp3ok.png

The files without an extension are from prior rename mistakes. These are removed with:

rm -v *[.]

 

The final dir is now tidy with both mp3 and original m4a files:

finaldir.png

For tech interest, you may want to research the default bitrate of purchased m4a to know what rate to transcode to with lame.

file does not tell you:

filespecs.png

https://developer.apple.com/library/ios/technotes/tn2236/_index.html

Recommended Bit Rate Range

Based on the unique characteristics of each AAC codec, for stereo audio sampled at 44.1 kHz the recommended operational bitrate ranges are:

HE-AAC v2 for lower bitrates between 16 - 40 kb/s.
HE-AAC v1 for bitrates between 32 - 80 kb/s.
AAC-LC for bitrates higher than 80 kb/s

As I found on my Electronic Music course, most people can't tell the difference between MP3 and CD quality until compared directly in an A/B test, and then most got it wrong due to individual human preferences for toppiness, bass etc. - even MP3s encoded from a CD wav at 320kbps - so provided they sound good to you, go with a lowest rate to save file space - I think a good compromise for MP3 is 128kbps at the lowest to 192kbps highest. I agree with this guy:

https://hydrogenaud.io/index.php/topic,96130.0.html

"Listening tests have shown that people generally stop noticing the difference between the original and the lossy version at bitrate n for MP3 and at bitrate n-minus-something for AAC. But you shouldn't infer from that "if I decode 256 kbps AAC and re-encode it as 320 kbps MP3, it will be the same quality." It's the same quality if you can't tell the difference. If you can't tell the difference between the AAC and the content transcoded to 128 kbps MP3, then it's highly likely the transcoded material at all MP3 bitrates from 128 to 320 is the same, maximum quality."

I think I will re run the conversion at lame -b 192...and check sizes before and after:

du -cks *mp3
11256 01TalkingtotheSun.mp3
4652 021988Aktivator.mp3
16632 03NewAgeSynthesis_Unzippingthe.mp3
11476 04HealingFeeling.mp3
16100 05Earthrise.mp3
9916 06Open.mp3
8872 07DefiniteActivity.mp3
5608 08GettingBetter.mp3
11856 09DayAfterDay.mp3
6116 10GettingInTune.mp3
9556 11DontDitherDoIt.mp3
11820 12TheFireInside.mp3
8972 13DontDitherDoIt_BackingTrack.mp3
16732 14FourEverRainbowPt3_Alterna.mp3
149564 total

du -cks *mp3
8444 01TalkingtotheSun.mp3
3488 021988Aktivator.mp3
12476 03NewAgeSynthesis_Unzippingthe.mp3
8608 04HealingFeeling.mp3
12076 05Earthrise.mp3
7440 06Open.mp3
6656 07DefiniteActivity.mp3
4208 08GettingBetter.mp3
8892 09DayAfterDay.mp3
4588 10GettingInTune.mp3
7168 11DontDitherDoIt.mp3
8864 12TheFireInside.mp3
6728 13DontDitherDoIt_BackingTrack.mp3
12548 14FourEverRainbowPt3_Alterna.mp3
112184 total

Saved about 30k, so when you have GBs of MPs it's negligible...if you can hear higher quality at larger bit rates, have it.

Comments are closed.

Post Navigation