Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
As far as I know ecasound doesnt copy the tags over.It may well do if you looked at the man for it but as I only use it sometimes this isnt a problem for me.It would be a perfect app if it did that too.
I see. Handy tool for the occasional file or two then, I'll remember that.
For the benefit of future readers then, If you want to convert you're entire (for example iTunes) music collection from m4a to mp3, keeping all the tags, you may still need to do it the hard way. Or should I say less convenient way; it's not really hard, especially as there are now two or three different scripts to choose from in this thread.
I just wrote a program to convert M4As to MP3s, transferring the artist, album, song name and track number tags. It's available here. Drop a comment if it breaks or there are some tags you want that aren't transferred.
Instead of removing the m4a files or just leaving them, they could just as easily be moved to the trash. If the file does get hosed up, you could still retrieve it from the trash. Here's the command - just remove the "rm $x" or whatever variable name you end up using.
Code:
mv "$i" ~/.local/share/Trash/files
I modified my script to do this and it sure is nice to not to actually lose the m4a files. Just remember to empty your trash occasionally!
Last edited by kah00na; 08-07-2008 at 03:39 PM.
Reason: variable now matches the last script.
Also, since this script is reading files as arguments, you can add a link to your ~/.gnome2/nautilus-scripts directory then when you right click a file, under "Scripts" will be your script. You can then click on it and it will do the conversion without having to open a terminal window. There won't be any progress information, but you can just watch for your CPU to drop off. Here's the command to make the link:
If anyone's interested at all - instead of having to explicitly use sed to strip the extraneous extensions from the mp3, you can use ${i%.m4a}.wav, etc.:
Code:
#!/bin/bash
#
# Dump m4a to mp3
if [ "$#" -eq "0" ] ; then
echo "Usage: '$0 filenames'"
exit 1
fi
for i in "$@"
do
echo Editing file - $i
if [ -f "$i" ]; then
faad "${i%.m4a}.wav"
# Get the source wav file produced by faad
x=`echo "${i%.m4a}.wav"
# Get the destination filename including path
y=`echo "${i%.m4a}.mp3"
# Strip pathso it's put in the current directory
y=`echo ${y##*/}`
# Get the track info
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: //'`
# Convert the file using lame
lame --alt-preset 160 --tt "$title" --ta "$artist" --tl "$album" --tg "$genre" --tn "$track" --ty "$year" "$x" "$y"
# Remove temporary files
rm .trackinfo.txt
rm "$x"
mv "$i" ~/.local/share/Trash/files
fi
done
I found a way to convert ALL m4a's in my music collection recursively. Haven't been looking at this thread for a while, there's another suggestion to do the recursion, but mine gives you the opportunity to check if everything went well. There are two parts, first the script for recursively working in all directories with m4a files inside, then the conversion script which is mostly the same as the one on http://wiki.linuxquestions.org/wiki/.m4a_to_.ogg
For the recursion and logfiles:
Code:
#!/bin/bash
# m4a2ogg_r.sh
# converts m4a audio files to ogg files recursively
INPUTFILES=~/m4a2ogg_in.txt
EXPECTED_OUT=~/m4a2ogg_exp.txt
OUTPUTFILES=~/m4a2ogg_out.txt
DIFFRESULT=~/m4a2ogg_diff.txt
TEMP=~/m4a2ogg.tmp
find . -type f -iname '*.m4a' | sed "s+\.+$PWD+" > "$INPUTFILES"
cat "$INPUTFILES" | sed -e 's/.m4a/.ogg/' > "$EXPECTED_OUT"
if [ -f "$OUTPUTFILES" ]
then
rm "$OUTPUTFILES"
fi
touch "$OUTPUTFILES"
LASTDIR=""
while read LINE ;
do
DIRNAME=`dirname "${LINE}"`
if [ "${DIRNAME}" != "${LASTDIR}" ]
then
cd "${DIRNAME}"
m4a2ogg | grep 'encoded' | sed "s;encoded ;${DIRNAME}/;" >> "$OUTPUTFILES"
fi
LASTDIR="${DIRNAME}"
done < $INPUTFILES
cat "$EXPECTED_OUT" | sort > "$TEMP" && mv "$TEMP" "$EXPECTED_OUT"
cat "$OUTPUTFILES" | sort > "$TEMP" && mv "$TEMP" "$OUTPUTFILES"
diff "$EXPECTED_OUT" "$OUTPUTFILES" > "$DIFFRESULT"
exit 0
My adaption of the conversion script, successful output is now echoed to stdout so that it can be used for the logging files.
Code:
#!/bin/bash
#
# m4a2ogg, converts m4a files to ogg files
# based on http://wiki.linuxquestions.org/wiki/.m4a_to_.ogg
# see also http://www.linuxquestions.org/questions/linux-general-1/converting-m4a-to-mp3-170553/
for i in *.m4a; do
tmp=$(mktemp)
y=`echo "$i"|sed -e 's/.m4a/.ogg/'`
faad -i "$i" 1>/dev/null 2>"$tmp"
if [ $? -ne 0 ] ; then
rm "$tmp"
echo "failed to get information from $i"
continue
fi
title=`grep 'title: ' "$tmp"|sed -e 's/title: //'`
artist=`grep 'artist: ' "$tmp"|sed -e 's/artist: //'`
album=`grep 'album: ' "$tmp"|sed -e 's/album: //'`
genre=`grep 'genre: ' "$tmp"|sed -e 's/genre: //'`
track=`grep 'track: ' "$tmp"|sed -e 's/track: //'`
year=`grep 'year: ' "$tmp"|sed -e 's/date: //'`
faad "$i" -o - | oggenc -q 5 -t "$title" -a "$artist" -l "$album" -G "$genre" -N "$track" -d "$year" -o "$y" -
if [ $? -ne 0 ] ; then
echo "failed to encode $i"
else
echo "encoded $y"
fi
rm "$tmp"
done
After checking that everything went well, you can delete the m4a files with a little script (or you choose the other solution of moving them into Trash, given a few posts earlier):
Code:
#!/bin/bash
# this deletes all files whose paths occur
# in the text file given as the parameter
while read LINE ;
do
rm "$LINE"
done < $1
exit 0
After all this I found out that soundKonverter exists. Well, now I can do this on the command line and have exercised again a bit in shell scripting...
Did anyone else notice that all these methods GREATLY reduce the sound quality of the files? Maybe I just have picky ears, but I find it rather frustrating that there isn't a way to convert m4a's without loss of quality.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.