LinuxQuestions.org

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

jonfa 04-15-2004 11:50 AM

converting m4a to mp3
 
Hi All,

I have .m4a audio files that I can play in mplayer with no problem, but cannot with xmms version 1.2.7. Is there a way to use mplayer to convert the m4a file to mp3? Or any other progrram to convert? Thanks for the help.

Jon

legolin 04-23-2004 01:32 PM

can you play this files under linux?
 
i have m4a as well...

how can i play them under linux? do i have to install mplayer (which version)?

thankx


leg

Shade 04-23-2004 04:33 PM

Mplayer is all I could find to do it.
In fact, I did this conversion yesterday.

Put all the .m4a files into one directory
then write a quick script.

Code:

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

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

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.

Code:

#!/bin/bash
#
#Second step... use lame to convert into .mp3

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

That's it. you've got all your files as mp3s.
However.. the file will look like "filename.m4a.wav.mp3"
So, to clean that up we use...

Code:

#!/bin/bash
#
# Remove extrenuous extensions.

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

There you go.
I suppose these could all be combined into one script, but i wanted to take it one step at a time when I did it yesterday.
You could change the mv "$i" "$x" to a cp command instead, if you want to be safe.

--Shade

legolin 04-27-2004 02:31 AM

oh thankxxxxxxxx!!!!


it really works.

In a world without walls and fences, who needs windows or gates?

vince v 05-18-2004 03:14 PM

I am a real newbie on redhat 9 and I have some basic questions. I saved all three of these scripts as

step1.script

in a 'scripts' file in my home directory. How do I invoke these scripts to act upon the m4a files ( which are all in a directory called 'itunes' )?

Also, how do I point the scripts( do I even need to point them?) to act on the directory with the m4a files?
Do I need to be in the 'itunes' directory to do this?

I thought I might have to just type the script file path and name and 'boom' it would work but I got 'access denied'. Then, I tried it from root and still the same thing. Also preceded it with

exec step1.script

but no success.

If anybody could explain anything further regarding these scripts and how to execute them (do I use the exec command?) , that would be helpful. Thanks.

Shade 05-18-2004 11:45 PM

Sorry.

I left out an important bit ;)

you'll want to
chmod +x each script, to give it execute permissions.

for example
chmod +x script1
chmod +x script2
etc..
Then run them with
./script1

--Shade

legolin 05-19-2004 11:00 AM

you can also copy the scripts to an order named
~/bin

i think you have to create it with
cd
mkdir bin

from now on, every script in this place will be executed by just calling his name on the bash... you don't need to write ./script anymore

bye

leg

Shade 05-19-2004 09:40 PM

True, but they still have to be executable :-D

You could place them anywhere in your $PATH and they'll run like that.

However, some distros don't include ~/bin/ in your path, so it may not work without a little modification.

--Shade

vince v 05-20-2004 03:53 PM

ugh, i am still struggling with this.

Does the . in
./script1

have to be there? Does is work like a command or isi t helping declare the path to the scripts?

I am wondering also, in the three scripts in the thread above, if the scripts automatically search for the directory with m4a files or if it is assuming the user is running the scripts while the user is in the directory that is to be effected--the directory with the m4a files. Any comments.

Also, if my script is located in


mycomputer/home/scripts


...and my m4a files are located in


mycomputer/home/music/iTunes


...how would these scripts look to work right?

I think I am almost there. Let's hope my mplayer is configured right to work...also, I am using RH 9.

-Vince

dnorseman 06-04-2004 09:35 AM

First off, thank you very much to Shade for that script. I have been fooling around with different scripts to convert these files without success.

Quote:

Does the . in ./script1 have to be there? Does is work like a command or isi t helping declare the path to the scripts?

I am wondering also, in the three scripts in the thread above, if the scripts automatically search for the directory with m4a files or if it is assuming the user is running the scripts while the user is in the directory that is to be effected--the directory with the m4a files. Any comments.

Also, if my script is located in mycomputer/home/scripts ...and my m4a files are located in mycomputer/home/music/iTunes ...how would these scripts look to work right?
As long as the script is in your PATH you can execute it as that user anywhere your permissions allow, I put my scripts in /home/user/bin which is in my path. You can execute that script by typing its name w/o the ./ in your music directory where the .m4a files are located. You would have to change the script to search through directories and I don't know how to do that, yet. Thanks again to Shade.

VibeOfOurTribe 09-07-2004 03:49 PM

Beautiful Script!

synx13 09-27-2004 03:47 PM

Hmm...
Code:

#!/bin/bash
#
# Dump m4a to mp3

for i in *.m4a
do
        if [ -f $i ]; then
                rm -f "$i.wav"
                mkfifo "$i.wav"
                mplayer -ao pcm "$i" -aofile "$i.wav" &
                dest=`echo "$i"|sed -e 's/m4a$/mp3/'`
                lame "$i.wav" "$dest"
        fi
done

Oh yes baby! XD
Nobody wants a 400 megabyte .wav file for every one of their m4a/mp3 files. u.u

p0g0 10-31-2004 12:48 PM

another script that deletes the .wav files right away
 
i'm using this script here. copy the .sh script in the directory containing your m4a files and run "sh m4a2mp3".

Code:

# 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/'`
lame -h -b 192 "$x" "$y"
rm "$x"
done


morin 10-31-2004 11:47 PM

There is a plugin for xmms to play m4a files, it's called libfaad2. You can get the source at:

http://www.audiocoding.com

also, check out
this thread

dhscaresme 04-07-2005 11:24 AM

saving the tag information
 
These scripts work great, but what if I wanted to save all my m4a tags, then automatically reapply them to the new mp3/ogg? Any suggestions?...I'm sure there are programs out there that do a wonderful job, but a bash or perl script would be saweet!

--Jim


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