LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
LinkBack Search this Thread
Old 11-27-2007, 09:56 AM   #61
mmatt
Member
 
Registered: Nov 2005
Location: UK
Distribution: archlinux
Posts: 90

Rep: Reputation: 19
Smile Lengthy discussion!


Wow, I didn't realise this thread was still active. Back when it started I'm not sure there were any tools to do this easily, hence the scripts.

Out of interest, do those tools transfer the tags as well as the data? And will they cope with badly formed tag fields?
 
Old 11-28-2007, 03:22 AM   #62
hoodooman
Member
 
Registered: Oct 2006
Location: Stirling in Scotland
Distribution: Slackware 13.37 64 bit
Posts: 297

Rep: Reputation: 42
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.
 
Old 11-28-2007, 09:42 AM   #63
mmatt
Member
 
Registered: Nov 2005
Location: UK
Distribution: archlinux
Posts: 90

Rep: Reputation: 19
For large collections...

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.

Enjoy your music.
 
Old 01-16-2008, 09:29 PM   #64
nobodysbusiness
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Rep: Reputation: 0
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.
 
Old 05-15-2008, 07:24 AM   #65
akamikeym
Member
 
Registered: May 2008
Posts: 104

Rep: Reputation: 21
Usage preference

Hi,

I've taken the scripts from this post and changed the user interface a little to work in what I would consider a more acceptable manner.

It takes a list of m4a files (including wildcards) and converts them into mp3's and dumps them in the working directory.

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"
		# Get the source wav file produced by faad
		x=`echo "$i"|sed -e 's/.m4a/.wav/'`
		# Get the destination filename including path
		y=`echo "$i"|sed -e 's/.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"
	fi
done
 
Old 05-15-2008, 01:52 PM   #66
Steel_J
Member
 
Registered: Oct 2004
Location: Montreal, Canada
Distribution: Kubuntu 10.04, Mint 8 and Puppy 4.3.1
Posts: 355
Blog Entries: 1

Rep: Reputation: 31
Thank will try it
 
Old 08-07-2008, 03:29 PM   #67
kah00na
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Rep: Reputation: 0
One more suggestion for all the scripts

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.
 
Old 08-07-2008, 03:31 PM   #68
kah00na
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Rep: Reputation: 0
Heres that last script updated to move the m4a files to the trash:

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"
		# Get the source wav file produced by faad
		x=`echo "$i"|sed -e 's/.m4a/.wav/'`
		# Get the destination filename including path
		y=`echo "$i"|sed -e 's/.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

Last edited by kah00na; 08-07-2008 at 03:39 PM. Reason: Oops... wrong variable. It is good now.
 
Old 08-07-2008, 03:35 PM   #69
kah00na
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Rep: Reputation: 0
Add to Right-Click Scripts menu

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:

Code:
ln -s /path/to/your/script ~/.gnome2/nautilus-scripts
This right-click menu has saved me a lot of time.
 
Old 10-19-2008, 01:33 PM   #70
slopshid
LQ Newbie
 
Registered: Oct 2008
Posts: 1

Rep: Reputation: 0
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
 
Old 12-12-2008, 08:49 PM   #71
rocksniffer
Member
 
Registered: Apr 2005
Location: Houston
Distribution: mandrake
Posts: 79

Rep: Reputation: 15
p0g0, that script of yours is the only one I could get to work and it works great!
 
Old 05-10-2009, 10:01 AM   #72
elektronaut
LQ Newbie
 
Registered: Nov 2006
Distribution: Ubuntu Edgy
Posts: 12

Rep: Reputation: 0
Doing it with recursion

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...
 
Old 05-11-2009, 12:09 PM   #73
Steel_J
Member
 
Registered: Oct 2004
Location: Montreal, Canada
Distribution: Kubuntu 10.04, Mint 8 and Puppy 4.3.1
Posts: 355
Blog Entries: 1

Rep: Reputation: 31
Wow, I first posted a script version to this thread 3 years ago, hahaha!

Cool!

Glad to see the scripts evolving. I'll try this last one.
 
Old 10-23-2010, 08:13 PM   #74
IpV8
LQ Newbie
 
Registered: Oct 2010
Posts: 1

Rep: Reputation: 0
Quality

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.
 
Old 10-23-2010, 09:09 PM   #75
Steel_J
Member
 
Registered: Oct 2004
Location: Montreal, Canada
Distribution: Kubuntu 10.04, Mint 8 and Puppy 4.3.1
Posts: 355
Blog Entries: 1

Rep: Reputation: 31
True

Any conversion reduces quality my friend. It is a price you chose to pay for getting out of proprietary formats.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting .ogg to .mp3? servnov Linux - General 8 03-06-2014 03:21 PM
converting m4u to mp3? minm Linux - Newbie 6 10-06-2005 02:26 PM
converting wma to mp3 rolanaj Linux - Software 2 08-16-2003 03:46 PM
Converting mp3 to ogg schatoor Linux - Software 8 07-07-2003 12:58 AM
Converting mp3 to wav. ??? rayflynn Linux - General 2 12-11-2001 05:07 AM


All times are GMT -5. The time now is 09:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration