LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   mencoder script help needed (https://www.linuxquestions.org/questions/linux-newbie-8/mencoder-script-help-needed-754618/)

mrgreaper 09-12-2009 07:31 AM

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?)

rayfordj 09-12-2009 08:29 AM

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


:study:

catkin 09-12-2009 08:54 AM

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


mrgreaper 09-12-2009 09:33 AM

Quote:

Originally Posted by rayfordj (Post 3679949)
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


:study:

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

mrgreaper 09-12-2009 08:51 PM

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


mrgreaper 09-13-2009 07:41 PM

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

catkin 09-14-2009 03:04 AM

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.

schneidz 09-14-2009 07:57 AM

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

mrgreaper 09-14-2009 08:18 AM

Quote:

Originally Posted by schneidz (Post 3682204)
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

i92guboj 09-14-2009 08:55 AM

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

mrgreaper 09-14-2009 09:09 AM

Quote:

Originally Posted by i92guboj (Post 3682261)
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 ?

i92guboj 09-14-2009 09:14 AM

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.

schneidz 09-14-2009 10:50 AM

Quote:

Originally Posted by mrgreaper (Post 3682214)
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 ?

catkin 09-14-2009 11:23 AM

Quote:

Originally Posted by i92guboj (Post 3682261)
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 ... ?

i92guboj 09-14-2009 12:13 PM

Quote:

Originally Posted by catkin (Post 3682436)
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.


All times are GMT -5. The time now is 10:47 PM.