Audio Format Converter

Amarok 1.x Scripts

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on opencode.net

0
5.0
Description:

This script allows you to convert the audio format of the tracks in the playlist. The script takes a snapshot of the current playlist. Once the conversion has started, you can go back to using amaroK normally.

Supported files for both input and output include .flac, .ogg, .mp3, .mpc, .m4a, and .wav. Additionally, .wma, .ra, and are supported for input. (See below for the required packages.)

I don't know how to do anything with metatags from .wma or .ra. All I know is tags will get transferred to the output file if and only if the tags show up in the amaroK playlist. If they aren't there, I suggest converting the files, then using a real tag editor like Easy Tag to put them in to the converted files.

This has only been tested on amaroK 1.2.4, but it should work on any amaroK>=1.2

The original files are NOT deleted. If the output file will overwrite an existing file, a dialog will appear to ask you whether to go ahead and overwrite or to skip the track. If you try to convert a file into the format it's already in, a dialog will ask you how to handle this situation.

Depending on the number of tracks and the speed of your computer, this can take a long time to run. With each track, a passive popup will let you know what track it's processing. At any time, you can stop the script by clicking 'stop' in the amaroK script GUI.

Required Packages:
lame -- for .mp3 in and out
flac -- for .flac in and out
oggenc -- for .ogg out
oggdec -- for .ogg in
mppenc -- for .mpc out
mppdec -- for .mpc in
mplayler -- for .wma or .ra in
faad -- for .mp4/.m4a in
faac -- for .m4a out
Last changelog:

14 years ago

v 0.7.0
++++++
The improvements in this release are due to Frederick Schaer, and I (we) thank him for his help!

The improvements are: 1) It now should handle full utf-8 character encoding for all the usual tags. 2) It corrects the error noted in the comments below about IndexError/AttributeError--something which I believe only affects more recent versions of Python.

v.6.2
++++++
For myriad reasons, a file can fail to convert but the script will continue on with the next file (as intended--I don't want one corrupted file to stop a 1,000 file batch). There is now an error log in the top-level directory where your transcoded files are saved that lists any files that failed to convert.

v.6.1
++++++
--amaroK switched the track number xml tag in their playlist from "TrackNo" to "Track". This catches up with the change, but should still work on versions earlier than 1.3.

v.6
++++++
--Fixed a piping bug that could cause the script to stop after a couple of files.
--Added a check for whether the output format is the same as the input format, with a dialog for how to handle this situation.
--Added a few more included options for encoders (OTHER still allows you to set your own options.)

bdillahu

15 years ago

It is a "lame" failing that it doesn't handle unknown genre's (by default).

I got around this by changing line 183 to read:

encodeCommand = "lame --ignore-tag-errors " + options + id3Options + " " + tempWavFile + " " + outputFileNameE

Adding the "--ignore-tag-errors " (make sure you get the trailing space) got me moving on.

Bruce

Report

sbassett

15 years ago

Any thought of providing audo cd conversion. The only thing that seperates it from Itunes in my opinion.

Report

C

mlmitton

15 years ago

I guess I'm not sure what you mean. Do you mean ripping CDs to whatever audio format? If so, I think you can already do it in amaroK, though having never tried, I'm not exactly sure how. (Probably drag and drop like all things.) But it's not something advertised, because it really is just better to use something like Grip. AmaroK is an audio player, not a file organizer, so I think I'd just as soon leave that to programs focused on ripping.

If you mean something else, let me know.

Report

sbassett

15 years ago

That is exactly what I meant, oh well. You can hope right? That is the one thing I have to hear about from the iTunes users, the fact that one needs to open another app to rip a cd. Even though amarok is the best player I have ever used.

Report

Dhraakellian

15 years ago

use audiocd:/ in the filebrowser to listen to audio CD's.

For ripping from CD to HD, dragging from audiocd:/ to your favorite kioslave-capable file manager should work.

Report

bearcatsandor

15 years ago

I just wanna say how awesome this script is. It has saved me a lot of manual work converting files from one format to another.

Thank you so much!!

Report

mrme

15 years ago

I got the following lines after I run the script and tried a conversion. I guess, there is a problem with the jave. I have j2re rpm installed and seems to work with other applications, I never had a problem with the installed java. I will be glad if you can help me. Thanks.

which: no mppdec in (/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/usr/lib/jre/bin:/home/gurayuner/bin:/usr/lib/jre/bin)
which: no mppenc in (/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/usr/lib/jre/bin:/home/gurayuner/bin:/usr/lib/jre/bin)
Could not find "/home/gurayuner/Desktop/TempDownload/temp.wav".
rm: cannot remove `/home/gurayuner/Desktop/TempDownload/temp.wav': No such file or directory

Report

C

mlmitton

15 years ago

Well, the 2 "which" errors are telling you that that it can't find mppdec or mppenc in your standard path. That is, mppenc and mppdec are not located in any of the folders listed in parentheses, so they can't be run by simply typing "mppenc" in the konsole, which is in essence what the script does. So there's a good chance you don't have these packages installed. If you do, then you just need to put them in one of those folders (or add whatever folder the mppenc/dec binaries reside in to your standard path, but that's more complicated.)

As for the next two errors, "could not find" and "rm...", what's happening is that the decoder you're trying to use, for whatever reason, isn't actually decoding the source file into temp.wav, and since you aren't creating temp.wav, you obviously can't encode it or remove it. If you're trying to transcode a musepack file, these are the exact errors you would get since you don't have mppdec installed. I suppose that's what's happening. If not, give me more info about the decoder step in your conversion (or try a different type of source file and see if that works).

Report

mrme

15 years ago

eberything goes smooth, I got the messege the coversion is done from wma to mp3, but the folder I specified is empty, nothinh there?
what would be wrong?

Report

C

mlmitton

15 years ago

I suspect it's either not encoding or decoding, probably decoding since dealing with wma is a bit trickier. If either encoding or decoding fails for some reason, the script keeps running despite the error.

Start amaroK from a terminal. (Most likely simply "amarok" will do.) Now, when you run the script, the terminal will give you the output of the mplayer command, which decodes the wma, and lame which encodes to wav. It will also give you what the error is if one of the commands doesn't work. My guess is it's probably an issue with mplayer.

Oh, also, watch the top-level of the directory where the transcoded files should end up--if you never see "temp.wav" appear, then you know there's a decoding problem.

Report

stormcloud51090

13 years ago

I had this problem - turns out it is an issue with a deprecated command in mplayer (for me anyway). To fix it i edited the script so the line under
elif inputFileFormat == ".wma" or inputFileFormat == ".ra":
read
decodeCommand = "mplayer " + inputFile + " " + "-vo null -vc dummy -af resample=44100 -ao pcm:file=" + tempWavFile

I would post the text that was originally there but i didnt back it up lol

Report

kriko

15 years ago

Same problem here

Report

jcphil

15 years ago

The script asks me where I want to save files, format to save in and quality. It then proceeds to convert files that I don't want converted. I only want it to convert m4 files that I stored in one directory. But it jumps over to another directory and completely ignores the files I would like to convert. Wouldn't it be just a little more logical to at least ask the user which files he would like to convert? I want me to decide, not the script.

Report

C

mlmitton

15 years ago

You do get to decide. If you want to convert something, put it in the playlist. If you don't want to convert it, leave it out. (Ref: the first sentence of the description on this page, or the first sentence in the "About" in amaroK, or the second sentence of the first panel when you run the script.)

Report

madpenguin8

15 years ago

Well, this could easily be done with 1.3beta2 and up if support is built into this script using the customMenuClicked notification. Have a look at http://amarok.kde.org/blog/archives/35-More-scripting-goodies.html and http://amarok.kde.org/wiki/index.php/Script-Writing_HowTo#Notifications for more details.

Report

rlklee

15 years ago

I am converting mp4's to mp3's -- the script begins to work, and does so, converting the first 5 files in the playlist successfully. After that, it just stops. No error message or anything, it just ends, even though there are nearly a thousand more files to convert. Any thought on this?

Report

C

mlmitton

15 years ago

I think I found the problem. I'll have an update posted some time in the next 1-2 days.

Report

C

mlmitton

15 years ago

I've heard of one other report of this happening. I haven't yet had time to look into it, but I'm hoping to this weekend.

Can you email me more information?

Like, if you remove those 5 or 6 files, do you still get the problem? Or does it happen after any 5 files? What type of files are they? If there's a particular file that's gumming up the works, have you tried decoding/encoding that particular file on the command line? In the top level directory where you're saving the transcoded files, is there a temp.wav file? If so, is it of a song that was successfully transcoded, or is it of a song that didn't get encoded?

Answers to any of these questions would be helpful to me. My suspicion is that the decoder is hitting a file it doesn't like and killing the process. Though in that case there should be some error output...

Anyway, please, if this has happened to anyone else, also email me any info you can give me. Email can be found in my username link.

Report

Runico

15 years ago

File "/home/sergio/.kde/share/apps/amarok/scripts/formatconverter.amarokscript/formatconverter.py", line 141, in createOutName
os.system(mkDirCommand)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 44: ordinal not in range(128)

Report

aries

16 years ago

Thanks, this looks good!

Question:
Is it possible to add monkeys audio - ape files- to the available (input)formats?

Report

C

mlmitton

15 years ago

I haven't forgotten about the request. I haven't been able to get gstreamer to play .ape, and I also can't get MAC to compile properly on my AMD64. So it's been pretty hard to test encoding and decoding .ape files:)

But, here's a version of the script which may (or may not) decode your .ape.

http://www.mlmitton.com/files/monkeytest.py

The command line options for MAC are dead-simple, so I probably have the right decode command, but of course I can't check this.

If people give me positive feedback that this works, I'll put it into a formal release. Until then, just use the script here.

Report

nimatar

16 years ago

I think you should remember users that it is usually a _bad_ _idea_ to convert lossy files to something else (lossy or not), because this will always mean loosing information (ok, not if you convert it to a lossless format, then the quality will remain the same, but the file will become a lot bigger). The only reason some one should do it is for music players that only support some file formats. Maybe it can also make some sense to convert, for example, .mpc 200kbps to .ogg 80kbps, 'cause the information lost in 200kbps will not be in a 80kbps file anyway.

I think you should mention this somewhere...

Anyway... cool script

byez ;-)

Report

cyborg

16 years ago

yeah but for some people, who are coming from windows or using some server sided music in work and so on, and have a lot of WMA's around there, such a script is worth life.

MS introduced WMA and in just 2 years people tend to use it all the way. same for wmv. i could rage for it

so this script is cool.
but it should escape "non-ascii" chars as mentioned. (some string replace where all NON-alphanumeric characters are preceded with a \ should do it).
Also mplayer has now -ao pcm:file=... not -aofile (deprecated).
and: resampling sometimes doesnt work. i had to remove it to get it work with wmas.
and: i have broken pipes sometimes. dunno why.

Report

C

mlmitton

16 years ago

You're absolutely right. I do mention this in the README. That said, I think for a fairly high percentage of people, the warnings about lossy-to-lossy conversions are overstated. A lot of people can't tell the difference between a CD and ~128kbps variable bit-rate lossy format, especially when they're listening on the speakers that came with their computer, or the headphones that came with their iPod. People with good ears probably already know the problems of lossy-to-lossy.

My recommendation is people should never convert from one lossy to another (or a different bit-rate of the same format) just for the sake of having it in a different format. As the poster noted, quality will *always* decrease. If you have to do the conversion (iPod won't play my ogg and I can't re-rip!), well, you gotta go what you gotta do. If the conversion is optional (I'm using 180kbps mp3, but I could fit everything on my Rio Karma if I converted them to 128), then try the conversion on a 10 or 20 tracks, and see if you can tell the difference. That way you can decide for yourself whether the loss in quality is sufficient to stop you from doing the conversion.

Report

famewolf

16 years ago

Please add option to use --preset voice with lame for conversion of audiobooks.

Report

14 years ago

v 0.7.0
++++++
The improvements in this release are due to Frederick Schaer, and I (we) thank him for his help!

The improvements are: 1) It now should handle full utf-8 character encoding for all the usual tags. 2) It corrects the error noted in the comments below about IndexError/AttributeError--something which I believe only affects more recent versions of Python.

v.6.2
++++++
For myriad reasons, a file can fail to convert but the script will continue on with the next file (as intended--I don't want one corrupted file to stop a 1,000 file batch). There is now an error log in the top-level directory where your transcoded files are saved that lists any files that failed to convert.

v.6.1
++++++
--amaroK switched the track number xml tag in their playlist from "TrackNo" to "Track". This catches up with the change, but should still work on versions earlier than 1.3.

v.6
++++++
--Fixed a piping bug that could cause the script to stop after a couple of files.
--Added a check for whether the output format is the same as the input format, with a dialog for how to handle this situation.
--Added a few more included options for encoders (OTHER still allows you to set your own options.)

12345678910
Be the first to comment
File (click to download) Version Description Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
Pling
0 Affiliates
Details
license
version
0.7.0
updated Apr 28 2007
added May 01 2005
downloads 24h
0
mediaviews 24h 0
pageviews 24h 2
System Tags addon