LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   convert wma > mp3? (https://www.linuxquestions.org/questions/linux-software-2/convert-wma-mp3-77093/)

andrewlkho 07-29-2003 05:35 PM

convert wma > mp3?
 
Hi,
Can anyone suggest some good software for converting wma's [nasty things :) ] into mp3's?
Thanks,

Corin 07-29-2003 06:32 PM

MP3s are nasty things too! :+)

You should be using the GPL format OGG.

Since WMA is a proprietary format, that is why you do not find any
native GNU software to convert WMAs to MP3.

One possibility would be to run a Windoze conververter program wma -> mp3 under wine.

The other would be to look at the options of mencoder which comes with MPlayer which is able to handle WMA files since it uses the Windoze dlls.

Thymox 07-30-2003 06:03 PM

Haha! MPLAYER to the rescue!

If you have the win32 codecs installed (also available from mplayer's site) then you can not only play WMA/WMV files, you can also convert them!

mplayer file.wma -ao pcm -aofile file.wav will convert to a wav file from which you can convert to an mp3/ogg yourself, or there are options to convert straight to mp3... I just can't remember them :D I know it has been touched upon quite recently though (I think it was something to do with extracting the audio from .mov files).

ravnx 08-26-2003 03:39 PM

Yes, mplayer is the one!

after reading the man pages, couldn't find anything to stream the sound to STDOUT or to an MP3, but you can simply use lame to convert to mp3 "lame -h infile.wav outfile.mp3" or to convert to ogg " oggenc infile.wav"

glj 08-27-2003 05:33 AM

You do realize then that you are compressing a compressed file?
The original file will be compressed to the WMA format, which will introduce audio artefacts, and then compressing that file with even more artefacts!
If you're happy with the output though, go for it :)

glj

ravnx 08-27-2003 09:29 AM

Yes, the original file is WMA a compressed format, but the problem here is that it's not an mp3 or ogg. Therefor I cannot play in xmms or burn it to a cd with other mp3s and oggs via K3B. When I use mplayer to convert wma to wav, mplayer is "playing" the wma file into a wav file, so, in essence, it is creating a totally new file that is not compressed. From that I produce an mp3/ogg file.

I don't see how you are saying that I am compressing an already compressed file.

Corin 08-27-2003 09:47 AM

The WAV file that is created by uncompressing the WMA is not the original WAV file.

It suffers from the compression artefacts introduced when the WMA file was created from the original WAV file.

When you compress that with MP3 of OGG software, you then introduced MP3 or OGG compression artefacts as well as including the WMA compression artefacts.

How good the sound quality is, very much depends on what bitrate was used for the original compression to WMA.

ravnx 08-27-2003 10:15 AM

agreed.

glj 08-28-2003 04:28 AM

What Corin said!
If you want an MP3 or OGG (preferably), then use the original source, CD probably. You do have the original don't you....

ravnx 08-28-2003 09:29 AM

i dont have the original. that's why this all came about, there are sometimes instances where you are looking for a song and you can ONLY find it on WMA, which is why we are on this discussion.

smc_one 09-08-2003 11:08 AM

I was reading this post, as I was in the same situation..

I decided to just stop and write a little perl program to:

1) Read all .wma files in a directory and with each one:
2) Use mplayer to make a converted copy to wav file
3) Use lame to convert the wav file to mp3
4) Remove the wav file

When complete, you will end up with an .mp3 copy of each .wma file. Im not an audio codec expert by any means, so there may be switches to make it faster/more efficient/etc.. Im also not responsible if something does not work right - but for me this works great. ;)

Just copy the code below starting at "#! /usr/bin/perl" into a new text file, name it "convert.pl" or whatever you wish - place the file in the folder with the wma files.. then run it from the command line "perl convert.pl" - and wait. Dont worry about spaces in file names - it will leave all original file names as is and use the original file names to make the .mp3 file.

Enjoy:

#! /usr/bin/perl

### WMA TO MP3 CONVERTER

$dir=`pwd`;

## READ EACH FILE, IF WMA, MAKE A "COPY" TO WAV THEN TO MP3 THEN DELETE WMA

chop($dir);

opendir(checkdir,"$dir");

while ($file=readdir(checkdir)) {

$orig_file=$file;

if ($orig_file !~ /\.wma$/i) {next};

print "Checking file: $orig_file\n";


$new_wav_file=$orig_file;$new_wav_file=~s/\.wma/\.wav/;
$new_mp3_file=$orig_file;$new_mp3_file=~s/\.wma/\.mp3/;

$convert_to_wav="mplayer \"./$orig_file\" -ao pcm -aofile \"./$new_wav_file\"";
$convert_to_mp3="lame -h \"./$new_wav_file\" \"./$new_mp3_file\"";
$remove_wav="rm -rf \"./$new_wav_file\"";

print "EXEC 1: $convert_to_wav\n";
$cmd=`$convert_to_wav`;
print "EXEC 2: $convert_to_mp3\n";
$cmd=`$convert_to_mp3`;
print "REMOVE WAV: $remove_wav\n";
$cmd=`$remove_wav`;
print "\n\n";

}

print "Done.";

ravnx 09-08-2003 11:24 AM

Interesting! I had done the same thing! See below.

#!/usr/bin/perl -w
use strict;

foreach my $file (@ARGV) {
next if ($file !~ /\.wma$/i);
my $base = $file; $base =~ s/\.wma$//i;
system "mplayer \"$file\" -ao pcm -aofile \"$base.wav\"";
system "lame -h \"$base.wav\" \"$base.mp3\"";
unlink("$base.wav");
print "$base.wma converted to mp3.\n";
}

zkar 09-18-2003 12:31 PM

Wow, for me does this line the same. How can this happen?

for i in *.wma ;do mplayer -ao pcm -aofile "${i%.wma}.wav" "$i"; oggenc "${i%.wma}.wav"; rm "${i%.wma}.wav"; done

greets and have fun

zkar

prozach 09-25-2003 09:10 AM

Ok, y'all are so smart, think you can help me here? I've got my wma files stored in a file structure so i want to convert them recursevly, can you help fix this script? It has issues with spaces and ' and such. Oh, and i'm stat'ing the files cauze some of them have the stupid wma protection and mplayer cant convert them properly so if it attempts to convert and the wav file is smaller than the wma file i basically remove the wav and move on to the next file in the list.

#!/bin/bash
DATE=$(date '+%m-%d-%Y')
TIME=$(date '+%H:%M:%S')
TIMESTAMP=$(date '+%m%d%Y')
STARTLOCATION=$1

find ${STARTLOCATION} -name *.wma -print > /tmp/wma_files.lst
sed -e 's/\.wma//g' /tmp/wma_files.lst > /tmp/tmp.wmalst
mv -f /tmp/tmp.wmalst /tmp/wma_files.lst

for FILENAME in `cat /tmp/wma_files.lst`
do
mplayer ${FILENAME}.wma -ao pcm -aofile '${FILENAME}.wav'

ORIGSIZE=`stat -c %s ${FILENAME}.wma`
NEWSIZE=`stat -c %s ${FILENAME}.wav`

if [${ORIGSIZE} -lt ${NEWSIZE} ]; then
lame -h ${FILENAME}.wav ${FILENAME}.mp3
rm -f ${FILENAME}.wma ${FILENAME}.wav
else
rm -f ${FILENAME}.wav
fi
done

/usr/bin/uuencode ${LOGFILE} /tmp/wma_files.lst | /bin/mail -s "Files converted on ${DATE}" "root"

zkar 09-25-2003 01:51 PM

the problem is, that you have to make the filename an one string:
1. test lala <- two strings
2. "test lala" <- one string

so with my modified old code: (it should work)

-------------- wma2mp3.sh ------------------------------------

#!/bin/bash
DATE=$(date '+%m-%d-%Y')
TIME=$(date '+%H:%M:%S')
STARTLOCATION="$1"

# Start a new file
echo "Start converting at $DATE $TIME with PID $$" > /tmp/wma2mp3.$$
echo "OGG is better and free (SCNR)">> /tmp/wma2mp3.$$

# For encoding wma to mp3 (but ogg is much better ;-) )
for i in "`find "${STARTLOCATION}" -name *.wma -print`"
do
mplayer -ao pcm -aofile "${i%.wma}.wav" "$i" && lame -h "${i%.wma}.wav" "${i%.wma}.mp3"

# Use this for ogg:
#mplayer -ao pcm -aofile "${i%.wma}.wav" "$i" && oggenc "${i%.wma}.wav"

# If returncode == 0
if [ $? -eq 0 ];then
echo "\"${i}\" convertet to \"${i}.mp3\"" >> /tmp/wma2mp3.$$
rm "${i%.wma}.wav" && rm "${i}"
else
echo "failed decoding \"${i}\"" >> /tmp/wma2mp3.$$
fi
done

echo "Finished converting at $DATE $TIME with PID $$" >> /tmp/wma2mp3.$$
cat /tmp/wma2mp3.$$|mail -s "Files converted on ${DATE}" root


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