LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   converting m4a to mp3 (https://www.linuxquestions.org/questions/linux-general-1/converting-m4a-to-mp3-170553/)

morin 04-07-2005 07:50 PM

so you mean a script that converts the m4a id tags to the mp3 id3v2 tags?

Shade 04-08-2005 04:11 AM

Haven't messed with much tagging, but the way I'd approach it would be to insert a step that reads the tag and dumps it to a text file before converting to mp3. Convert to mp3. Then reapply the tag with some tagging app. Could probably be scripted with little effort.

--Shade

dhscaresme 04-08-2005 12:17 PM

heres an answer
 
Alright I found a good example. Google for oggasm. It's a PeRL script which recursively converts mp3 to ogg. It converts the tags and applies them to the new file as well. I'm just learning perl so it's a bit out of the realm of total understanding for me, but it certainly can be done...relatively easily it looks.

d-rockbrinks 04-19-2005 05:18 PM

here's a short bash script that uses faad2 and lame to convert from .m4a to mp3, transfers all the tag information, and deletes the intermediary .wav and .txt files it created

the script still has to be saved and run in each directory containing .m4a files you want to convert, but I suspect that would be trivial to fix for anyone who actually knows a thing or two about bash scripts:


#!/bin/bash
#
# m4a to wav
for i in *.m4a
do
faad "$i"
x=`echo "$i"|sed -e 's/.m4a/.wav/'`
y=`echo "$i"|sed -e 's/.m4a/.mp3/'`
faad -i "$i" 2>.trackinfo.txt
title=`grep 'title: ' .trackinfo.txt|sed -e 's/title: //'`
artist=`grep 'artist: ' .trackinfo.txt|sed -e 's/artist: //'`
album=`grep 'album: ' .trackinfo.txt|sed -e 's/album: //'`
genre=`grep 'genre: ' .trackinfo.txt|sed -e 's/genre: //'`
track=`grep 'track: ' .trackinfo.txt|sed -e 's/track: //'`
year=`grep 'year: ' .trackinfo.txt|sed -e 's/year: //'`
lame --alt-preset 160 --tt "$title" --ta "$artist" --tl "$album" --tg "$genre" --tn "$track" --ty "$year" "$x" "$y"
rm .trackinfo.txt
rm "$x"
done




naturally you can substitute you favorite lame settings instead of --alt-preset 160
this works with mp4 file info in the format faad v2.0 prints out; later/earlier versions may require changes

d-rockbrinks 04-19-2005 05:36 PM

my lame doesn't recognize "Hip Hop/Rap", but does recognize "Hip Hop", so instead of what is up there I used the line:

genre=`grep 'genre:*/ ' .trackinfo.txt|sed -e 's/genre: //'`

of course if your m4a genre is listed as pop/funk, this will not be helpful (you will lose the "/funk" in the listing.)

you could also delete any and all references to genre and --tg in the above script

vdHummes 04-23-2005 03:32 PM

Hi all,

for the sake of completeness and quality, I have taken the liberty of modifying
d-rockbrinks' script into one that converts m4a to ogg, using faad and oggenc, and does the tagging ogg-style:

#!/bin/bash
#
# m4a to ogg
for i in *.m4a
do
faad "$i"
x=`echo "$i"|sed -e 's/.m4a/.wav/'`
y=`echo "$i"|sed -e 's/.m4a/.ogg/'`
faad -i "$i" 2>.trackinfo.txt
title=`grep 'title: ' .trackinfo.txt|sed -e 's/title: //'`
artist=`grep 'artist: ' .trackinfo.txt|sed -e 's/artist: //'`
album=`grep 'album: ' .trackinfo.txt|sed -e 's/album: //'`
genre=`grep 'genre: ' .trackinfo.txt|sed -e 's/genre: //'`
track=`grep 'track: ' .trackinfo.txt|sed -e 's/track: //'`
year=`grep 'year: ' .trackinfo.txt|sed -e 's/year: //'`
oggenc -q 10 -t "$title" -a "$artist" -l "$album" -G "$genre" -N "$track" -d "$year" -o "$y" "$x"

rm .trackinfo.txt
rm "$x"
done

jong357 05-05-2005 03:41 PM

vdHummes, you should add that script to the wiki if you sure it works well. I've started a new section for just this sort of thing. Might be nice to have conversion scripts localized in one place...

http://wiki.linuxquestions.org/wiki/Audio_conversion

Or, if you don't feel like doing it, give me the go ahead and I'll add it myself...

fakezone 05-24-2005 06:20 AM

i tried all the scrips posted here and got the same error each time .......

"Warning: Pulse coding not allowed in short blocks" fills up the terminal
and then when it finally stops it says
Could not find "19 Track 19.wav".
rm: cannot remove `19 Track 19.wav': No such file or directory

:confused:

thanks for any help
fakez

VibeOfOurTribe 05-24-2005 11:24 AM

a couple of suggestions for fakezone:

go to the directory where your m4a files are and try running
faad "filename.m4a"
on the command line

then do
ls
if you don't see a ".wav" file then you have a problem. either you need to update your faad program or there is simply a problem with your m4a files. Also make sure you have the correct permissions. And that you are copying and pasting the scripts correctly and not just typing them in (sometimes that leads to typos).

If it is the case that your faad needs to be updated (and I see you are using fc3) then type yum update and finally yum install faad2

Hope that helps,

As for me I am using d-rockbrinks' script with much success and also learning a thing or two about bash scripting.

Thanks everyone who has contributed!

court-jus 05-25-2005 02:53 AM

Quote:

Originally posted by Shade
Put all the .m4a files into one directory
then write a quick script.

-SNIP-

That will use mplayer do dump m4a into a regular wave file.
Next, you need to use lame to convert the .wavs into .mp3s. You could use oggenc if you wanted .oggs.

-SNIP-

However.. the file will look like "filename.m4a.wav.mp3"
So, to clean that up we use...

-SNIP-

Well, your solution is good but I can add some tips :

1) mplayer can write to mp3 directly using lame
2) bash can convert filenames to remove unwanted extensions :

Code:

for i in *.m4; do
  mencoder "$i" -o "${i/m4a/mp3}" -oac mp3lame
done

You can use the -lameopts mencoder flag to specify bitrate and stuff for lame....

:study: :study: RTFM is the solution :D :D :study: :study: :D

kiwi2penguin 05-26-2005 03:06 AM

multiple directory conversions
 
heres a recursive script you can use to call the scripts at

http://wiki.linuxquestions.org/wiki/Audio_conversion

convertr...

#!/bin/sh
#
# recursively call command

script=$0
command=$1
for f in echo *
do
if [ -d "$f" ]
then
cd "$f"
$script $command
cd ..
else
$command "$f"
fi
done

I used it to convert a DVDs worth of various artists.
Change to top level folder (e.g. itunes ;-) and execute 'convertr m4a2mp3' for example and the script will enter into all the subdirectories calling the conversion script specified.

Have fun!

DaWallace 05-26-2005 07:45 AM

THANK you whoever did it for making the ogg vorbis version, I don't want to use it, but shortly ago I spent several hours making and many, many more perfecting a script to convert mp3 to ogg. it hurts me deeply to find people ignoring this great format, and instead using inferior ones.

..I do realize that there is a better script written in perl that does it and with many more options but I don't really care and at the time I didn't know

jong357 05-26-2005 11:10 AM

That what I based it off of... ;) I don't care too much for tags, so I left it out... It would only add another 6 or 7 lines to make it use tags...

Thats a cool master conversion script... I never thought of that actually.... Cool addition.. Why don't you add it to the wiki?

fakezone 06-12-2005 05:24 AM

i tried the scripts on a 32 bit computer and they worked great.... any one know how to convert mpc to mp3?

xbaez 08-03-2005 12:51 PM

I really like to use MP3 with lame --preset standard

Here is my all in one script (convert, encode, delete wav and m4a) script

#!/bin/bash
# Dump m4a to wav (first step in conversion)

for i in *.m4a
do
mplayer -ao pcm "$i" -aofile "$i.wav"
done

# Now we use Lame to convert the WAV files to MP3
#Second step... use lame to convert into .mp3

for i in *.wav
do
#lame -h -b 192 "$i" "$i.mp3"
lame --preset standard "$i" "$i.mp3"
done

# Remove extrenuous extensions.
for i in *.mp3
do
x=`echo "$i"|sed -e 's/m4a.wav.mp3/mp3/'`
mv "$i" "$x"
done

#Delete the wav files
for i in *.wav
do
rm -vf "$i"
done

#Delete the m4a files
for i in *.m4a
do
rm -vf "$i"
done


I'd really like to thank the author of this script


All times are GMT -5. The time now is 11:37 PM.