Author Topic: wma2mp3 software  (Read 4981 times)

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
wma2mp3 software
« on: 20 December 2005, 18:48 »
Hi.

You might be interested to know about wma2mp3 which you can find at http://wma2mp3.501megs.com - it is a set of scripts that i am now maintaining, which convert files of one audio type, to another audio type, using the bash command line. At the moment all it does is simplifies the process of using mplayer and lame to convert between various formats without the user having to do each file individually and remember all the command line switches.

See what you think of it, hope it's useful. I have big plans for it, but not sure when they will end up being implemented!
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

piratePenguin

  • VIP
  • Member
  • ***
  • Posts: 3,027
  • Kudos: 775
    • http://piratepenguin.is-a-geek.com/~declan/
Re: wma2mp3 software
« Reply #1 on: 20 December 2005, 19:31 »
I made my own bash script for doing this a while ago, but it sucked (but it did do the job).
This one looks nice. Good job.
"What you share with the world is what it keeps of you."
 - Noah And The Whale: Give a little love



a poem by my computer, Macintosh Vigilante
Macintosh amends a damned around the requested typewriter. Macintosh urges a scarce design. Macintosh postulates an autobiography. Macintosh tolls the solo variant. Why does a winter audience delay macintosh? The maker tosses macintosh. Beneath female suffers a double scum. How will a rat cube the heavier cricket? Macintosh calls a method. Can macintosh nest opposite the headache? Macintosh ties the wrong fairy. When can macintosh stem the land gang? Female aborts underneath macintosh. Inside macintosh waffles female. Next to macintosh worries a well.

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
Re: wma2mp3 software
« Reply #2 on: 20 December 2005, 21:21 »
thanks! it's v simple right now, but perhaps with a few arms and legs it can be a lot more versatile.

one thing i'm thinking about now is when i add more options whether to make it interactive or just use commandline switches. the whole point of the script is to cut down on switches. On the other hand if the user wants to do a whole batch job then it'd be a pain in the arse to have it asking what bitrate to make the output files every time it was invoked (for example), although that'd still be fractionally better than having to type out a big long command plus switches for every individial file...
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

piratePenguin

  • VIP
  • Member
  • ***
  • Posts: 3,027
  • Kudos: 775
    • http://piratepenguin.is-a-geek.com/~declan/
Re: wma2mp3 software
« Reply #3 on: 20 December 2005, 22:26 »
Quote from: Calum
one thing i'm thinking about now is when i add more options whether to make it interactive or just use commandline switches. the whole point of the script is to cut down on switches. On the other hand if the user wants to do a whole batch job then it'd be a pain in the arse to have it asking what bitrate to make the output files every time it was invoked (for example), although that'd still be fractionally better than having to type out a big long command plus switches for every individial file...
I'd use switches, and maybe have a switch for specifying a config file (storing a list of switches, possibly). If things got complicated enough, you could even package a few config files for e.g. mp3 128kbps (and other options) etc.
"What you share with the world is what it keeps of you."
 - Noah And The Whale: Give a little love



a poem by my computer, Macintosh Vigilante
Macintosh amends a damned around the requested typewriter. Macintosh urges a scarce design. Macintosh postulates an autobiography. Macintosh tolls the solo variant. Why does a winter audience delay macintosh? The maker tosses macintosh. Beneath female suffers a double scum. How will a rat cube the heavier cricket? Macintosh calls a method. Can macintosh nest opposite the headache? Macintosh ties the wrong fairy. When can macintosh stem the land gang? Female aborts underneath macintosh. Inside macintosh waffles female. Next to macintosh worries a well.

solemnwarning

  • Member
  • **
  • Posts: 747
  • Kudos: 338
    • http://www.solemnwarning.net
Re: wma2mp3 software
« Reply #4 on: 21 December 2005, 05:56 »
i might write a perl\C++ version of this that will get stuff from STDIN by default but you can also use command line switches or a config file.
-----BEGIN GEEK CODE BLOCK-----
 Version: 3.1
 GCS/CM d- s+:+ a--- C++ UL++++>$ P+ L+++ !E W++ !N !o !K-- w !O !M !V PS+ PE- !Y !PGP !t !5 !X !R tv b+ DI+ !D G e- h !r y-
 ------END GEEK CODE BLOCK------

Refalm

  • Administrator
  • Member
  • ***
  • Posts: 5,183
  • Kudos: 704
  • Sjembek!
    • RADIOKNOP
Re: wma2mp3 software
« Reply #5 on: 21 December 2005, 22:21 »
Does it automatically delete shit put in by WMP?

Jack2000

  • Guest
Re: wma2mp3 software
« Reply #6 on: 22 December 2005, 22:03 »
You can make a siwch
for "silent" work :)
and/or  use a settings file :)

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
Re: wma2mp3 software
« Reply #7 on: 25 December 2005, 19:14 »
thanks folks, i will probably end up having differently named scripts for different bitrates, with the thing of a symlink to the default one and being able to execute one of the others if necessary. Anyway, that's all to come...

Quote from: Refalm
Does it automatically delete shit put in by WMP?


uh?

well, the sonic content of the wma or wmv file gets output into an ms pcm wav file, usiplayer, and then the wav file gets encoded into a 192mp3 file using lame. So, should be only the music that gets from the input file to the output file.

if that's what you mean.
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

solemnwarning

  • Member
  • **
  • Posts: 747
  • Kudos: 338
    • http://www.solemnwarning.net
Re: wma2mp3 software
« Reply #8 on: 18 February 2006, 01:30 »
I've been a bit bored over the past hour so i ported one of the shell scripts to C++ and added support for reading a list of files to convert, enjoy.

Code: [Select]
//C++ port of Calum and Void Main's m4a2mp3 v0.13 shell script
//Copyright (C) 2006 Daniel Collins, Calum, Void Main
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include
#include
#include
#include
#include
#include
#include
#include

#include
#include
#include

//Convert function
void m4a2mp3(std::string file) {
  //Check the source file exists and can be opened
  int test_open_return = open(file.c_str(), O_RDONLY | O_NONBLOCK | O_LARGEFILE);
  if(test_open_return == -1) {
    //Opening the file failed
    std::cerr << "Cannot open file " << file << ": " << strerror(errno) << std::endl;
    exit(1);
  }
  //We dont need the file to be open, so lets not waste an fd :)
  close(test_open_return);
 
  //Make a temporary wav file out of the m4a file
  std::string command = "faad -o \"" + file + ".wav\" \"" + file + "\"";
  int command_return = system(command.c_str());
  if(command_return != 0) {
    std::cerr << "Failed to convert m4a file to wav with `" << command << "`" << std::endl;
    std::cerr << "There was a problem with the conversion process!" << std::endl;
    exit(1);
  }
  //Convert the wav to an mp3
  command = "lame -h -b 192 \"" + file + ".wav\" \"" + file + ".m4a.mp3\"";
  command_return = system(command.c_str());
  if(command_return != 0) {
    std::cerr << "Failed to convert wav file to mp3 file with `" << command << "`" << std::endl;
    std::cerr << "There was a problem with the conversion process!" << std::endl;
    exit(1);
  }
  //Delete the temporary wav file
  std::string tmp_del = file + ".wav";
  int unlink_return = unlink(tmp_del.c_str());
  if(unlink_return == -1) {
    std::cerr << "Cannot delete temporary wav file: " << strerror(errno) << std::endl;
    exit(1);
  }
}

int main(int argc, char** argv) {
  //Not enough command line switches
  if(argc < 2) {
    std::cerr << "Syntax: " << argv[0] << " [--help|--file] " << std::endl;
    exit(1);
  }
 
  std::string mode = "1file";
  std::string file;
  //Check switches
  int argd = 1;
  while(argc > argd) {
    std::string args = argv[argd];
    if(args == "--help") {
      std::cout << "m4a2mp3 v0.14" << std::endl;
      std::cout << "Syntax: " << argv[0] << " [--help|--file] " << std::endl << std::endl;
      std::cout << "--help\tPrint this message to STDOUT and exit" << std::endl;
      std::cout << "--file\tParse a file containing a list of files to convert" << std::endl;
      std::cout << "\t\t(a listfile should contain a list of sourcefiles, one per line)" << std::endl;
      exit(0);
    }else if(args == "--file") {
      mode = "filelist";
    }else{
      file = args;
    }
    argd++;
  }
 
  if(mode == "1file") {
    m4a2mp3(file);
  }else if(mode == "filelist") {
    //Open the file list
    int list_fd = open(file.c_str(), O_RDONLY | O_NONBLOCK);
    if(list_fd == -1) {
      std::cerr << "Cannot open convert list: " << strerror(errno) << std::endl;
      exit(1);
    }
   
    //Read the list from the file descriptor list_fd, into the temporary char buffer
    char tmp_buffer[4096];
    int read_return = read(list_fd, tmp_buffer, 4096);
    if(read_return == -1) {
      std::cerr << "Cannot read convert list: " << strerror(errno) << std::endl;
      exit(1);
    }
    tmp_buffer[read_return] = '\0';
   
    //Copy the char buffer into a new std::string buffer and close the file
    std::string buffer = tmp_buffer;
    close(list_fd);
   
    //Remove any carridge returns incase user wrote the file in fucking notepad
    boost::algorithm::erase_all(buffer, "\r");
   
    //define boost split stuff
    typedef std::vector < boost::iterator_range < std::string::iterator > > find_vector_type;
    typedef std::vector < std::string > split_vector_type;
    find_vector_type FindVec;
    split_vector_type SplitOut;
   
    //Split buffer at newlines
    ifind_all(FindVec, buffer, "\n");
    boost::algorithm::split(SplitOut, buffer, boost::is_any_of("\n"));
   
    unsigned int lines_done = 0;
    while(SplitOut.size() > lines_done) {
      m4a2mp3(SplitOut[lines_done]);
      lines_done++;
    }
  }
}


You can compile it with `g++ -Wall -I/usr/local/include/boost_1_33_1 -o m4a2mp3 whateveryousavethisfileas.cpp`

You need the boost::algorithm headers to compile it, if you have boost 1.33.0 then change -I/usr/local/include/boost_1_33_1 to -I/usr/local/include/boost_1_33_0
-----BEGIN GEEK CODE BLOCK-----
 Version: 3.1
 GCS/CM d- s+:+ a--- C++ UL++++>$ P+ L+++ !E W++ !N !o !K-- w !O !M !V PS+ PE- !Y !PGP !t !5 !X !R tv b+ DI+ !D G e- h !r y-
 ------END GEEK CODE BLOCK------

mobrien_12

  • VIP
  • Member
  • ***
  • Posts: 2,138
  • Kudos: 711
    • http://www.geocities.com/mobrien_12
Re: wma2mp3 software
« Reply #9 on: 18 February 2006, 05:15 »
What happens when the WMA has drm crap on it?

Hypothetically speaking, of course.  Although I have no interest in file sharing or piracy (FUCK YOU RIAA), I am fully aware that bypassing DRM crap (which really has nothing to do with piracy) violates that stupid law called the DMCA (again  FUCK YOU RIAA).
In brightest day, in darkest night, no evil shall escape my sight....

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
Re: wma2mp3 software
« Reply #10 on: 19 February 2006, 15:46 »
hmm, well, the scripts don't have their own codecs, and only act as an interface between the user and the actual programs which do the real work of conversion between one format and the other. these programs, mplayer, lame, oggenc and so on use codecs to do the actual encoding and decoding. the codecs are libraries, and without the specific library telling the program how to do the conversion, it wouldn't be able to do it.

So what i mean in short is: if it becomes illegal to play certain audio files, and you make it so you are able to do so on your computer, using mplayer for instance, then you would also be able to use wma2mp3 and the rest to convert, even though it would be illegal. There's nothing in the scripts themselves though which would be illegal, what would be illegal would be having your system with those codecs installed in the first place.

secondly, it looks like the wma2mp3.501megs site is down to me, is this the case? that's not too good, i should do something about it unless it comes back online...

thirdly, solemnwarning, that's cool! :-D i will put that on the wma2mp3 site as well then. brilliant.
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism