I am trying to run a command line utility which converts a wma file to
a mp3 (i want to be able to do this for batch files) using FFMpeg &
LAME. I am trying to run the following command from ruby:
“C:\Documents and Settings\dt\Desktop\my stuff\songs\wma\ffmpeg.exe” -
i “C:\Documents and Settings\dt\Desktop\my stuff\songs\Who The
\Quadrophenia\07-0 - Who The - Love Reign O’er Me.wma” -vn -f wav - |
“C:\Documents and Settings\dt\Desktop\my stuff\songs\wma\lame.exe” -V
6 - “C:\Documents and Settings\dt\Desktop\my stuff\songs\Who The
\Quadrophenia\07-0 - Who The - Love Reign O’er Me.mp3”
It works perfect from the command line, but no matter how i try it
(with double quotes, single quotes, backticks, etc) it doesnt seem to
want to work from ruby
Here is an example of the code I have
ffmpeg = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\ffmpeg.exe”’
lame = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\lame.exe”’
newFile = child.sub(‘wma’, ‘mp3’)
#cmd = ffmpeg + " -i " + child + " -vn -f wav - | " + lame + " -V 6 -
" + newFile
cmd1 = “#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 -
#{newFile}”
puts cmd1
system(cmd1)
NOTE: child points to the same file wma file as above.
If i copy and paste the output of the puts command above into a
command window, it works fine…but from ruby, it seems to ignore the
pipe (|) command. I dont know if this is a windows issue, or if i am
missing something obvious. Any help is greatly appreciated.
ffmpeg = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\ffmpeg.exe”’
lame = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\lame.exe”’
newFile = child.sub(‘wma’, ‘mp3’)
#cmd = ffmpeg + " -i " + child + " -vn -f wav - | " + lame + " -V 6 -
" + newFile
cmd1 = “#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 -
#{newFile}”
puts cmd1
system(cmd1)
NOTE: child points to the same file wma file as above.
If i copy and paste the output of the puts command above into a
command window, it works fine…but from ruby, it seems to ignore the
pipe (|) command. I dont know if this is a windows issue, or if i am
missing something obvious. Any help is greatly appreciated.
I have no idea if this was intentional or not but…
#cmd = ffmpeg + " -i " + child + " -vn -f wav - | " + lame + " -V 6 -
" + newFile
The # in front of cmd comments that entire line out…once again i have
no idea if you were just putting that there to make a point in your post
so I’m just making sure.
Hi Mac,
That commented line was a previous attempt at formatting the ‘cmd’
differently. I tried many different formats and varations, none of
which seemed to work.
Thanks
-d
Hi Mac,
Thanks for taking the time to help me on this. I wasnt aware that
there was a way to load executables into ruby, but the weird thing, is
that if I remove the pipe (|), or separate the commands, those files
are executed. Which is why I am lead to believe that my problem is the
result of the pipe. But here is my program:
(I slightly modified it to simplify things, but you should get the
idea)
def convert2MP3(path)
raise ArgumentError unless File.directory?(path)
ffmpeg = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\ffmpeg.exe”’
lame = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\lame.exe”’
Dir.entries(path).each do |child|
if File.basename(child) =~ /wma$/
puts “converting to mp3”
child = path + File::SEPARATOR + child
child = child.gsub(’/’, “\”)
child = child.gsub(’\\’, “\”)
child = ‘"’ + child + ‘"’
newFile = child.sub(‘wma’, ‘mp3’)
#cmd = ffmpeg + " -i " + child + " -vn -f wav - | " + lame + " -V
6 - " + newFile
cmd1 = “#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 -
#{newFile}”
#cmd2 = #{lame} -V 6 - #{newFile}
puts cmd1
system(cmd1)
if File.exists?(child)
#File.delete(child)
end
end
end
end
startingDir = “C:/Documents and Settings/dt/Desktop/my stuff/songs//
Who The/Quadrophenia/”
convert2MP3(startingDir)
-d
[email protected] wrote:
“C:\Documents and Settings\dt\Desktop\my stuff\songs\wma\ffmpeg.exe” -
i “C:\Documents and Settings\dt\Desktop\my stuff\songs\Who The
\Quadrophenia\07-0 - Who The - Love Reign O’er Me.wma” -vn -f wav - |
“C:\Documents and Settings\dt\Desktop\my stuff\songs\wma\lame.exe” -V
6 - “C:\Documents and Settings\dt\Desktop\my stuff\songs\Who The
\Quadrophenia\07-0 - Who The - Love Reign O’er Me.mp3”
It works perfect from the command line, but no matter how i try it
(with double quotes, single quotes, backticks, etc) it doesnt seem to
want to work from ruby
Here is an example of the code I have
ffmpeg = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\ffmpeg.exe”’
lame = ‘“C:\Documents and Settings\dt\Desktop\my stuff\songs
\wma\lame.exe”’
newFile = child.sub(‘wma’, ‘mp3’)
#cmd = ffmpeg + " -i " + child + " -vn -f wav - | " + lame + " -V 6 -
" + newFile
cmd1 = “#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 -
#{newFile}”
puts cmd1
system(cmd1)
NOTE: child points to the same file wma file as above.
If i copy and paste the output of the puts command above into a
command window, it works fine…but from ruby, it seems to ignore the
pipe (|) command. I dont know if this is a windows issue, or if i am
missing something obvious. Any help is greatly appreciated.
Alright lets approach this from a different perspective. First, the
reason that lame or ffmpeg arnt working is because its loading them as
strings into ruby, instead of loading the exe’s. There should be a gem
or lib in ruby that loads exe’s into memory but i havnt had the time
today to fumble around the net for it. Using a gem to convert these
files would be alot better than loading exes into memory. If you were on
linux you could do all this with some bash scripting but
we’ll find
another way.
cmd1 = “#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 -
#{newFile}”
the reason this isnt working is because Ruby doesnt take command line
arguements like Windows cmd.exe or command.com does. Ruby interprets
these as minus signs and negative signs. I would imagine running this
gives you some outrageous errors. If you could post your entire program
and we’ll see if we cant find a gem or lib that will do this.
On Oct 25, 3:58 pm, “[email protected]” [email protected] wrote:
If i copy and paste the output of the puts command above into a
command window, it works fine…but from ruby, it seems to ignore the
pipe (|) command. I dont know if this is a windows issue, or if i am
missing something obvious. Any help is greatly appreciated.
As far as I can tell, this is due to the way the Windows command
interpreter handles double-quotes when a pipe is present along with
the way Ruby’s #system method calls the interpreter.
From a few tests I did, it seemed the leading double-quote was being
stripped from the command line, but adding another did not fix the
problem. I think you could fix it by either relocating your
executables to a path with no spaces or using a temp file rather than
a pipe. Maybe not optimal, but, like you, I fiddled with all sorts of
single/double quotes and escaping and it didn’t like any of it.
Alright lets start this program over and build up from the basics using
a gem.
require ‘rubygems’
require ‘r2mp3’
print "File Path: "
path = gets.chomp
Converter.new(:convert=>:wma,:file=>"#{path}"){|f| f.to_mp3 }
##########
Keep in mind you will have to install the r2mp3 gem via command line -
gem install r2mp3
This SHOULD work, i dont have any resources in front of me right now so
i cant double check, but let me know if you need any additions to the
code above.
I don’t like the idea of relocating variables, as I would like this
script to be as generic as possible…and I have thought of using a
temporary file, but not a big fan of it either.
None the less, thanks for trying to take a look at it. I don’t much
understand why this doesnt work…and i will try to continue to play
around with it and see if i can come up with a combination which
works.
thanks again!
Hi Mac,
I wasnt aware of a wma to mp3 converter in ruby…i don’t have time
today, but tomorrow I will give this a try and let you know how it
goes.
On Oct 29, 11:21 am, “[email protected]” [email protected] wrote:
Keep in mind you will have to install the r2mp3 gem via command line -
gem install r2mp3
This SHOULD work, i dont have any resources in front of me right now so
i cant double check, but let me know if you need any additions to the
code above.
- Mac
–
Posted viahttp://www.ruby-forum.com/.
Just so you know, r2mp3 uses temp files for conversion so if that’s an
actual problem rather than a preference, you might need something else.
Just as an update, I ended up splitting the commands up into 2
separate commands, and using a temporary file. Its not the ideal
solution, but I havent been able to figure out why the pipe doesnt
want to work (probably a windows thing).
Thanks again for all your help!