[MPlayer-dev-eng] [PATCH] wma2ogg
VMiklos
mamajom at axelero.hu
Wed Apr 14 14:42:57 CEST 2004
hi
Peter Simon mailed me his simple converter perl script: wma2ogg
it uses mplayer - of course ;-) and oggenc
it can convert wma to mp3 (bladeenc or lame), too
imho it could be placed in the TOOLS directory
patch attached
greetings
---
__________ VMiklos / FrugalWare & EL Team
____/__/___|___\__. E-mail: mamajom at axelero dot hu
O__O _ | | _ | Homepage: http://www.vmiklos.tk
'--`-(_)'---'--(_)-' gpg --keyserver pgp.mit.edu --recv-keys 03915096
-------------- next part --------------
diff -Naur main.orig/TOOLS/wma2ogg main/TOOLS/wma2ogg
--- main.orig/TOOLS/wma2ogg 1970-01-01 01:00:00.000000000 +0100
+++ main/TOOLS/wma2ogg 2004-04-14 14:19:42.000000000 +0200
@@ -0,0 +1,331 @@
+#!/usr/bin/perl
+
+#################################
+# wma converter 0.3.3 for Linux #
+#################################
+
+# Made by Peter Simon <simon.peter at linuxuser.hu>
+# License: GNU GPL
+#
+# Needed programs:
+#
+# Getopt::Long - Perl Module
+# Mplayer - http://www.mplayerhq.hu
+# BladeEnc - http://bladeenc.mp3.no
+# oggenc - http://www.vorbis.com
+# mp3info - http://www.ibiblio.org/mp3info
+
+# changelog:
+# 0.1.0
+# decoding all files to wav without any switches and encoders
+# 0.2.0
+# converting to mp3 or ogg with bitrate, delete options
+# 0.2.1
+# L.A.M.E. support for fanatics
+# Default output filetype: ogg
+# Some error warnings
+# 0.3.0
+# Reading the wma tags out and puting into the mp3 or the ogg tags. (What the MPlayer shows of those.)
+# Default output bitrate: the original bitrate
+# Simlink for the default encode mode (wma2ogg = ogg, wma2mp3 = mp3)
+# 0.3.1
+# Neglecting missing encoders if those are not in use.
+# 0.3.2
+# Using mp3info for the mp3 tags
+# 0.3.3
+# Convert more then one files in the start dir.
+
+# Why BladeEnc?
+# Eg.: The L.A.M.E.'s code isn't compatible for some hardwer-decoders. Makes noise and clashings.
+# I never met this trouble using BladeEnc.
+# That's it.
+
+use Getopt::Long;
+
+$ver="0.3.3";
+
+GetOptions("help|?",\&showhelp, 'a' => \$all, "file|f=s" => \@files,"t=s" => \$mtype, "lame" => \$needlame, "del" => \$delete, "br=i" => \$brate);
+
+print "\nwma2ogg $ver\nPeter Simon <simon.peter\@linuxuser.hu>";
+
+if (!$all && !@files) {
+ error ("There is no selected file!");
+}
+
+if ($0 =~/wma2mp3/ && !$mtype) {
+ $mtype="mp3";
+}
+
+if ($mtype eq "ogg") {
+ $ttype{"ogg"}="oggenc";
+ needed_prgs (oggenc, "http://www.vorbis.com");
+ #ch_needed();
+}
+
+if ($needlame && $mtype eq "ogg") {
+ error ("\nYou can not use L.A.M.E. & oggenc together!\n");
+}
+
+if (!$mtype && !$needlame) {
+ $mtype="ogg";
+ $ttype{"ogg"}="oggenc";
+ needed_prgs (oggenc, "http://www.vorbis.com");
+ #ch_needed();
+}
+
+
+if (!$needlame && $mtype eq "mp3") {
+ $ttype{"mp3"}="BladeEnc";
+ needed_prgs (BladeEnc, "http://bladeenc.mp3.no", mp3info, "http://www.ibiblio.org/mp3info");
+ #needed_prgs (mp3info, "http://www.ibiblio.org/mp3info");
+ #ch_needed();
+}
+
+if ($needlame) {
+ $mtype="mp3";
+ $ttype{"mp3"}="lame";
+ needed_prgs (lame, "http://lame.sourceforge.net", mp3info, "http://www.ibiblio.org/mp3info");
+ #needed_prgs (mp3info, "http://www.ibiblio.org/mp3info");
+ #ch_needed();
+}
+
+# Main program
+ print "\nThis program holds to BladeEnc for mp3!\n(See the source for more information!)\n";
+ ch_needed ();
+ ch_type ();
+ ch_files ();
+ decode();
+
+# the end.
+
+
+sub ch_type {
+ $o_type=$ttype{$mtype};
+
+ if ($mtype ne "wav") {
+ $def_path=$ENV{PATH};
+ @exec_path=split /\:/, $def_path;
+ foreach $temp_path (@exec_path) {
+ if (-d $temp_path && !$enc_ok) {
+ $enc_ok=`find $temp_path -name $o_type -type f -maxdepth 1 2>/dev/null`;
+ chomp ($enc_ok);
+ }
+ }
+ }
+ if ((!$o_type || !$enc_ok) && $mtype ne "wav") {
+ error("Unknown encoder.");
+ }
+}
+
+sub ch_br {
+ if (((!$brate || $brate<32 || ($brate>350 && $mtype eq "mp3") || ($brate>500 && $mtype eq "ogg")) && $mtype ne "wav") || ($mtype eq "wav" && $brate)) {
+ error("Invalid, missing or redundant bitrate.");
+ }
+}
+
+sub ch_files {
+ if ($all && @files) {
+ error ("Unambiguously allotted files. (You've selected the all and other files too!)");
+ }
+
+ if ($all) {
+ @enc_files=`ls | grep '.wma'\$`;
+ foreach (@enc_files) {
+ chomp $_;
+ }
+ }
+
+ if (@files) {
+ @enc_files=@files;
+ }
+
+}
+
+sub showhelp {
+print "\n\nUsage: wma2ogg [OPTIONS] (-f FILE1 | -f FILE2 ... | -a)\n
+-f, -file filename
+-a convert all wma files in start directory\n
+OPTIONS:
+-t output filetype (ogg, mp3) [default=ogg]
+-lame I wanna use L.A.M.E. sure enough!
+-br bitrate (kb/s) [default=from the wma]
+-del remove wma file(s) after the encoding\n";
+print $miss_text;
+print "\n$errtext\nExiting program.\n\n";
+}
+
+sub error {
+ $errtext=@_[0];
+ showhelp ();
+
+}
+
+sub missing_prg {
+ $what=$keys;
+ $that=$needed{$keys};
+ $miss_text.="\nThe needed \'$what\' program is missing, see: $that!";
+}
+
+sub ch_needed {
+
+ `perl -e 'use Getopt::Long;' 2>./err`;
+ open (FILE, "<./err");
+ while ($sor=<FILE>) {
+ if ($sor =~ /Can\'t locate/) {
+ missing_prg ("Getopt::Long", ": your Perl is too old... (uhhh... Get a new one!)");
+ }
+ }
+ `rm ./err`;
+
+
+ foreach $keys (keys %needed) {
+ `$keys 2>./err`;
+ open (FILE, "<./err");
+ while ($sor=<FILE>) {
+ if ($sor =~ /$keys\: command not found/) {
+ missing_prg ();
+ $error=1;
+ }
+ }
+ `rm ./err`;
+ }
+
+ close FILE;
+ if ($error) {
+ showhelp ();
+ exit;
+ }
+}
+
+sub get_tags {
+ my $outfile;
+ open (FILE, "<./1");
+ while ($sor=<FILE>) {
+ $outfile.=$sor;
+ }
+ close FILE;
+
+ $outfile=~ s/\((\d+\,\d+)\ kbit\)/$1/e;
+ print "\noriginal bitrate: $1";
+ $kept_orig_brate=$1;
+ $kept_orig_brate=~ s/(\d+)/$1/e;
+ $kept_orig_brate=$1;
+
+ if (!$brate) {
+ $brate=$kept_orig_brate;
+ print " (kept as default)";
+ } else {
+ print " (new: $brate,0)";
+ }
+
+ ch_br ();
+
+ `rm ./1`;
+ my @temp_info=split /Clip\ info\:/, $outfile;
+ my @temp2_info=split /\n/, @temp_info[1];
+ my @temp_title=split /\ /, $temp2_info[1],3;
+ my @temp_author=split /\ /, $temp2_info[2],3;
+ my @temp_copyright=split /\ /, $temp2_info[3],3;
+ my @temp_comments=split /\ /, $temp2_info[4],3;
+ return ($temp_title[2], $temp_author[2], $temp_copyright[2], $temp2_comments[2]);
+}
+
+sub needed_prgs {
+ %needed=(
+ $_[0]=>$_[1],
+ $_[2]=>$_[3],
+ mplayer=>"http://www.mplayerhq.hu",
+ );
+}
+
+sub mp3_info {
+ if ($title) {
+ $infofile=" -t '$title'";
+ }
+ if ($author) {
+ $infofile.=" -a '$author'";
+ }
+ if ($comments) {
+ $infofile.=" -c '$comments'";
+ }
+
+ `mp3info "$p_name.$mtype" $infofile`;
+
+ undef ($infofile);
+}
+
+sub decode {
+ foreach (@enc_files) {
+ $wav_name=$_;
+ $wav_name=~ s/(.+)\./$1/e;
+ $p_name=$1;
+ $wav_name=$p_name.".wav";
+ $pwd=`pwd`;
+ chomp $pwd;
+ $pwd.="/t2";
+ print "\nConverting $_ to \"wav\" file.\n";
+ print "Using MPlayer...\n";
+
+ `mplayer "$_" -ao pcm -input conf="$pwd" 2>/dev/null >./1`;
+ `mv "audiodump.wav" "$wav_name"`;
+
+ undef $brate;
+ @tags=get_tags ();
+
+ $title=$tags[0];
+ print "\ntitle: $title";
+ $author=$tags[1];
+ print "\nauthor: $author";
+ $copyright=$tags[2];
+ print "\ncopyright: $copyright";
+ $comments=$tags[3];
+ print "\ncomments: $comments";
+
+ $comments=$copyright." ".$comments."Transcoded by wma2ogg";
+
+ print "\n\nConverting $wav_name to \"$mtype\" file.";
+
+ print "\nUsing $o_type...";
+
+ if ($mtype eq "ogg") {
+ $br_sw="b";
+ if ($title) {
+ $infofile=" -t '$title'";
+ }
+ if ($author) {
+ $infofile.=" -a '$author'";
+ }
+ if ($comments) {
+ $infofile.=" -c COMMENT='$comments'";
+ }
+
+ `"$o_type" "-$br_sw" "$brate" "-Q" "./$wav_name" $infofile "-o" "$p_name.$mtype"`;
+ `rm -f "$wav_name"`;
+ }
+ if ($mtype eq "mp3" && !$needlame) {
+ $br_sw="br";
+ `"$o_type" "$wav_name" "$p_name.$mtype" "-$br_sw" "$brate" 2>/dev/null >/dev/null`;
+
+ mp3_info ();
+
+ `rm -f "$wav_name"`;
+ }
+ if ($mtype eq "mp3" && $needlame) {
+
+ $br_sw="b";
+ `"$o_type" "-$br_sw" "$brate" "-f" "$wav_name" "$p_name.$mtype" 2>/dev/null >/dev/null`;
+
+ mp3_info ();
+
+ `rm -f "$wav_name"`;
+ }
+ if ($delete) {
+ `rm -f "$_"`;
+ }
+ if (-e "./err") {
+ `rm ./err`;
+ }
+ }
+ print "\n\nDone.\n\n";
+}
+
More information about the MPlayer-dev-eng
mailing list