[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Looping through files using exec

Jason Cameron

1/18/2006 4:09:00 AM

I'm trying to do a mass encode of a large directory of media files but
I'm not having much luck. I tried to use bash but it doesn't like
filenames with spaces so now I'm trying to do it with ruby but using the
exec command it executes the first line then finishes. Here's what I've
done in the IRB.

Dir["*.avi"].each {|x| exec ("mencoder \"" + x + "\" -vf scale=320:240
-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
vbr=3:br=64 -o \"Done\\" + x + "\"") }

It would be sweetness on a stick if it worked but unfortunately it stops
after the first one. Can anyone tell me what I'm doing wrong and more
importantly what I need to do to make this work?

Thanks in advance,

I

--
Posted via http://www.ruby-....


5 Answers

x1

1/18/2006 4:42:00 AM

0

You said bash...

Does "Done" represent a directory? and.. does Done\#{filename} work
with this option? I would have thought that in *nix, it would be
Done/#{filename}

Not exactly sure what this app is supposed to do but the loop looks ok..

irb(main):004:0> puts "mencoder \"" + x + "\" -vf scale=320:240 -ovc
lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
vbr=3:br=64 -o \"Done\\" + x + "\""
mencoder "pron.avi" -vf scale=320:240 -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64 -o
"Done\pron.avi"

On 1/17/06, Jason Cameron <luxen124012x1@rogers.com> wrote:
> I'm trying to do a mass encode of a large directory of media files but
> I'm not having much luck. I tried to use bash but it doesn't like
> filenames with spaces so now I'm trying to do it with ruby but using the
> exec command it executes the first line then finishes. Here's what I've
> done in the IRB.
>
> Dir["*.avi"].each {|x| exec ("mencoder \"" + x + "\" -vf scale=320:240
> -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
> vbr=3:br=64 -o \"Done\\" + x + "\"") }
>
> It would be sweetness on a stick if it worked but unfortunately it stops
> after the first one. Can anyone tell me what I'm doing wrong and more
> importantly what I need to do to make this work?
>
> Thanks in advance,
>
> I
>
> --
> Posted via http://www.ruby-....
>
>


Jason Cameron

1/18/2006 5:03:00 AM

0

vrtwo lastname wrote:
> You said bash...
>
> Does "Done" represent a directory? and.. does Done\#{filename} work
> with this option? I would have thought that in *nix, it would be
> Done/#{filename}
>
> Not exactly sure what this app is supposed to do but the loop looks ok..
>
> irb(main):004:0> puts "mencoder \"" + x + "\" -vf scale=320:240 -ovc
> lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
> vbr=3:br=64 -o \"Done\\" + x + "\""
> mencoder "pron.avi" -vf scale=320:240 -ovc lavc -lavcopts
> vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64 -o
> "Done\pron.avi"

If I replace exec with puts it lists the commands fine. My problem is
that when I use exec it runs the first command fine then exits ignoring
all the other files. For example if I have a directory that has the
files:

bar1.avi
bar2.avi
bar3.avi

and I use the following in IRB:

Dir["*.avi"].each {|x| puts ("mencoder \"" + x + "\" -vf scale=320:240
-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
vbr=3:br=64 -o \"Done\\" + x + "\"") }

I get the following output:

mencoder "\bar1.avi" -vf scale=320:240 -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64 -o
"Done\bar1.avi"
mencoder "\bar2.avi" -vf scale=320:240 -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64 -o
"Done\bar2.avi"
mencoder "\bar3.avi" -vf scale=320:240 -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64 -o
"Done\bar3.avi"

but if I do:

Dir["*.avi"].each {|x| puts ("mencoder \"" + x + "\" -vf scale=320:240
-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
vbr=3:br=64 -o \"Done\\" + x + "\"") }

It will only execute:
mencoder "\bar1.avi" -vf scale=320:240 -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64 -o
"Done\bar1.avi"


--
Posted via http://www.ruby-....


Nakada, Nobuyoshi

1/18/2006 5:04:00 AM

0

Hi,

At Wed, 18 Jan 2006 13:09:23 +0900,
Jason Cameron wrote in [ruby-talk:176073]:
> I'm trying to do a mass encode of a large directory of media files but
> I'm not having much luck. I tried to use bash but it doesn't like
> filenames with spaces so now I'm trying to do it with ruby but using the
> exec command it executes the first line then finishes. Here's what I've
> done in the IRB.

exec replaces current process with invoked command, use system
instead.


> Dir["*.avi"].each {|x| exec ("mencoder \"" + x + "\" -vf scale=320:240
> -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
> vbr=3:br=64 -o \"Done\\" + x + "\"") }

And also bash should work if you quote names properly:

opts="-vf scale=320:240 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64"
for x in *.avi; do
mencoder "$x" $opts -o "Done \"$x\""
done

--
Nobu Nakada


Nakada, Nobuyoshi

1/18/2006 5:08:00 AM

0

Hi,

At Wed, 18 Jan 2006 14:03:36 +0900,
nobuyoshi nakada wrote in [ruby-talk:176077]:
> > Dir["*.avi"].each {|x| exec ("mencoder \"" + x + "\" -vf scale=320:240
> > -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
> > vbr=3:br=64 -o \"Done\\" + x + "\"") }

Sorry, misread the command.

> And also bash should work if you quote names properly:
>
> opts="-vf scale=320:240 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts vbr=3:br=64"
> for x in *.avi; do
mencoder "$x" $opts -o "Done/$x"
> done

--
Nobu Nakada


Jason Cameron

1/18/2006 5:33:00 AM

0

nobuyoshi nakada wrote:
> Hi,
>
> At Wed, 18 Jan 2006 13:09:23 +0900,
> Jason Cameron wrote in [ruby-talk:176073]:
>> I'm trying to do a mass encode of a large directory of media files but
>> I'm not having much luck. I tried to use bash but it doesn't like
>> filenames with spaces so now I'm trying to do it with ruby but using the
>> exec command it executes the first line then finishes. Here's what I've
>> done in the IRB.
>
> exec replaces current process with invoked command, use system
> instead.
>
>
>> Dir["*.avi"].each {|x| exec ("mencoder \"" + x + "\" -vf scale=320:240
>> -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150 -oac mp3lame -lameopts
>> vbr=3:br=64 -o \"Done\\" + x + "\"") }
>
> And also bash should work if you quote names properly:
>
> opts="-vf scale=320:240 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=150
> -oac mp3lame -lameopts vbr=3:br=64"
> for x in *.avi; do
> mencoder "$x" $opts -o "Done \"$x\""
> done

Sweetness! Thanks! Actually now it seems that all my created files are
in the same directory prefaced by '\Done\' instead of going in the Done
directory. Go figure. Oh well. At least I can encode en masse! Good
thing too. I've got a 50+ files to re-encode (a series) for my
pocketpc. When you can stuff 15 hours of video on a 1gb sd card that's
a good thing(tm).

My bash script was similar but I didn't have the quotes.

Thanks again!

J

--
Posted via http://www.ruby-....