LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-12-2009, 07:31 AM   #1
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Rep: Reputation: 15
mencoder script help needed


ok this is my post script i use for sabnzbd that i need to adapt slightly

the script is

Code:
dir=$1
cd "$dir"
file="$(ls -1S *.avi | head -n 1)" ; echo $file >> /home/mrgreaper/conv.text

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi
now at them moment it converts the biggest avi it finds in the folder for my archos to use at work, i need it to convert all avis in the folder

im guessing its not as simple as replacing "$file" with "*.avi" or is it? (and changing the end to *_done.avi to insure the end file is named correctly?)

Last edited by mrgreaper; 09-12-2009 at 07:33 AM.
 
Old 09-12-2009, 08:29 AM   #2
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
test it out to be sure, but something like this might do the trick...

Code:
dir=$1
cd "$dir"

for i in $(ls -1 *.avi)
do
file="${i}" ; echo $file >> /home/mrgreaper/conv.text

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi

done

 
Old 09-12-2009, 08:54 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
How about this
Code:
IFS='
' files=( $(/bin/ls -1 '--ignore=*_done.avi' *.avi) )
for (( i = 0; i < ${#files[*]}; i++ ))
do
   file="${files[$i]}"
   <commands>
done
 
Old 09-12-2009, 09:33 AM   #4
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rayfordj View Post
test it out to be sure, but something like this might do the trick...

Code:
dir=$1
cd "$dir"

for i in $(ls -1 *.avi)
do
file="${i}" ; echo $file >> /home/mrgreaper/conv.text

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi

done

i triedmaking a bash script but got ./bash is a director lnux really ant my strong point lol

but have amended a new conversion post processing script and am trying it out , i wont know for a few hours if its worked (well if it errors fully ill know in a few minutes lol)

Thank you in advance ill post how it goes when its done

***edit***
while i tried to find sabnzbds script folder episode butler (i use this rather then a vcr so i can watch my programs at work lol, as far as i know nothing illeagel is going on after all its the same as taping it) picked up some programs fed them into sabnzbd which then downloaded and is running post processing scripts on them (it does them one at a time in order) so i wont know if that script has worked for a very long time (the new one that is) oh well fingers crossed

Last edited by mrgreaper; 09-12-2009 at 09:42 AM.
 
Old 09-12-2009, 08:51 PM   #5
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
well rayfodj script didnt work

but catkins did thnx catkin

so far only tested as a script inside a folder of test avi files but i see no reason why it wouldnt work in a $dir
here it is
Code:
dir=$1
cd "$dir"
IFS='
' files=( $(/bin/ls -1 '--ignore=*_done.avi' *.avi) )
for (( i = 0; i < ${#files[*]}; i++ ))
do
   file="${files[$i]}"

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi

done
 
Old 09-13-2009, 07:41 PM   #6
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
pardon the triple post but it serves a purpose of bumping the thread to get noticed and this is a new winkle and editing would mean it would go un noticed.

ok the script as
Code:
IFS='
' files=( $(/bin/ls -1 '--ignore=*_done.avi' *.avi) )
for (( i = 0; i < ${#files[*]}; i++ ))
do
   file="${files[$i]}"

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi

done
and run by ./conv3 from inside the folder full of avi files (providing the conv3 file is in the folder too) works great it works perfectly

but the post processing script as
Code:
dir=$1
cd "$dir"

IFS='
' files=( $(/bin/ls -1 '--ignore=*_done.avi' *.avi) )
for (( i = 0; i < ${#files[*]}; i++ ))
do
   file="${files[$i]}"

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi

done
generates the following error
/home/mrgreaper/sabnzbd/script/conv3: 5: Syntax error: "(" unexpected

both have been chmod 777

i just dont get it

a possible solution springs to mind if i could make conv3 executable from anywhere (is that possible? ie being able to ./conv3 with out the file being in the folder im in and it still converting all the files of the folder im looking at?)
if thats possible i could do this
Code:
dir=$1
cd "$dir"
./conv3
the $1 is the completed folder directory passed on by sabnzbd and works fine in the first example i gave in the first post

if thats not possible the only other thing i can think of is this;

Code:
dir=$1
cd "$dir"

copy file command (im sure i can find that on google lol) /home/mrgreaper/sabnzbd/script/conv3 to "$dir" 
./conv3
i wish i had the time and patience to really learn linux cos it just makes no sense that inside a terminal window the script works but as a post script (which is just being activated in a terminal as far as i can tell) it errors arghhhhhhhhhhhhhhhh
 
Old 09-14-2009, 03:04 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
No problem with posting again in the same thread -- it's the same problem and isn't solved yet.

"/home/mrgreaper/sabnzbd/script/conv3: 5: Syntax error: "(" unexpected" is a syntax error, nothing to do with permissions on the script file.

Perhaps the script is running in a different shell when it is run as a post-processing script. Do you know and can you post details of how it is being launched?

Try setting the first line of the script to this (if it is not already); It may force the script to be executed by bash.
Code:
#!/bin/bash
You can run the script regardless of which directory you are in by specifying it with a full path, for example as
Code:
/home/<your user name>/bin/conv3.sh
Here "bin" is a common convention for a directory name to put executables in and the extension .sh is a common convention for shell scripts.

To copy files, use the cp command, details by running
Code:
man cp
or by netsearching.

Last edited by catkin; 09-14-2009 at 03:04 AM. Reason: Missing /
 
Old 09-14-2009, 07:57 AM   #8
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,849

Rep: Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592
Code:
dir=$1
cd "$dir"
for file in *.avi
do
 mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi
done
by and by, which archos do you have. i have an archos av500 dvr and the video recording is horrible (mite be because it is a hand me down). does yours record fairly decently ?

also post #2 mite help here:
http://www.linuxquestions.org/questi...light=mencoder

Last edited by schneidz; 09-14-2009 at 08:02 AM.
 
Old 09-14-2009, 08:18 AM   #9
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by schneidz View Post
Code:
dir=$1
cd "$dir"
for file in *.avi
do
 mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi
done
by and by, which archos do you have. i have an archos av500 dvr and the video recording is horrible (mite be because it is a hand me down). does yours record fairly decently ?

also post #2 mite help here:
http://www.linuxquestions.org/questi...light=mencoder
av700 tv (tv part is good when hooked into an arial as its a digibox but the portable arial doesnt work at work (but then i guard a carpark and am surrounded by steal and concreate lol)
the recording on it is oversized and blocky so i use episode butler to get my tv programmes for me (again as far as i can see thats no different then setting a vcr up except its in a format i can do something with lol)
i then use mencoder to put it into a smaller file size and make sure the audio is the right codec etc

as for the change of script i added the bash bit (gedit automaticly changed the colours of some of the words, i guess to make scripting easier) tested it on a 1 avi file folder and it worked now just have to wait for it to work on a multi avi link (my net is being slow at mo (i norm 5000+k per second (around 5meg a sec actual) im getting 1200 k per sec
 
Old 09-14-2009, 08:55 AM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
To use a matrix here is completely non-required, even more, you shouldn't be parsing the ls output, for a number of reasons.

Use schneidz's way instead, which is not only easier and more efficient but also more solid.

However, if
 
Old 09-14-2009, 09:09 AM   #11
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
To use a matrix here is completely non-required, even more, you shouldn't be parsing the ls output, for a number of reasons.

Use schneidz's way instead, which is not only easier and more efficient but also more solid.

However, if
catkin's method does seem to be working now i added the bash bit so im loathed to change it plus if i make file = *.avi would that not just make file = test.avitest2.avitest3.avi ?
 
Old 09-14-2009, 09:14 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
The for loop will work *always*. Just read that link I gave you to see why using the ls output as your source is not reliable. ls wasn't designed for that purpose, though it's a common practice for I don't know what reason, that doesn't make it any more correct.
 
Old 09-14-2009, 10:50 AM   #13
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,849

Rep: Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592
Quote:
Originally Posted by mrgreaper View Post
av700 tv (tv part is good when hooked into an arial as its a digibox but the portable arial doesnt work at work (but then i guard a carpark and am surrounded by steal and concreate lol)
the recording on it is oversized and blocky so i use episode butler to get my tv programmes for me (again as far as i can see thats no different then setting a vcr up except its in a format i can do something with lol)
i then use mencoder to put it into a smaller file size and make sure the audio is the right codec etc
...
for me my av500 dvr gives a low screach when connected to my tv thru rca a/v composite and the output looks wavy (like bad uhf/ vhf)
but again mite be because i got this from a freind after he got it from a friend. (the outer casing is missing some small screws. the battery/ harddrive compartment is taped shut.)
i am wondering if buying a new unit will solve that ?
 
Old 09-14-2009, 11:23 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by i92guboj View Post
To use a matrix here is completely non-required, even more, you shouldn't be parsing the ls output, for a number of reasons.

Use schneidz's way instead, which is not only easier and more efficient but also more solid.

However, if
Thanks i92guboj, that's a very useful link

I guess most of us use ls because we are scripting using a toolset we use interactively. About the final recommendation
Code:
find . -type f -print0 | while IFS= read -r -d '' filename; do
  ...
done
Presumably the "IFS=" is defensive, in case IFS has been set to a non-standard value, and so is redundant in most cases.

The "-d ''" is intriguing; it looks like an empty string but must mean NULL to read ... ?
 
Old 09-14-2009, 12:13 PM   #15
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Quote:
Originally Posted by catkin View Post
Thanks i92guboj, that's a very useful link

I guess most of us use ls because we are scripting using a toolset we use interactively. About the final recommendation
Code:
find . -type f -print0 | while IFS= read -r -d '' filename; do
  ...
done
Presumably the "IFS=" is defensive, in case IFS has been set to a non-standard value, and so is redundant in most cases.
It's not redundant, the standard value of IFS is blank/tab/LF, this serves the purpose of setting the internal field separator to null. This is important because spaces, tabs and LF characters can be part of a file name, but null can't. This is *the only way* to ensure that your script will always behave OK; with independence on how odd your file names are

That's the purpose of the -print0 statement as well. This instructs find to use the null character to separate the elements of the list.

This is why you use IFS=, or xargs -0 in conjunction with the find -print0 option.
 
  


Reply

Tags
archos, batch, mencoder


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch script for Mencoder??? JungMin Linux - Software 11 11-21-2011 03:34 AM
Script help needed! Atif_Khan Linux - Software 25 09-03-2007 12:51 AM
script help needed: patilvidya Linux - Software 2 08-29-2007 08:53 AM
Help making a simple script for mencoder. joney_bravo Programming 3 01-01-2007 06:28 PM
little script help needed abisko00 Programming 7 07-11-2005 08:37 AM


All times are GMT -5. The time now is 08:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration