LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   trouble with my first bash script (https://www.linuxquestions.org/questions/programming-9/trouble-with-my-first-bash-script-769761/)

rootoutcast 11-17-2009 03:24 PM

trouble with my first bash script
 
Hi I am righting a script to use mencoder to convert videos the menu is giving my trouble it runs throw the menu options and closes the script



#!/bin/bash
VAR="files.txt"
DIR="srcdir"


clear
echo "Make The TV"
echo "********************************"
echo "MENU "
echo "*******************************"
echo "1. Video to xvid (1 pass )"
echo "2. wmv two xvid (2 pass encoding)"
echo "3. Video to flv (for the web)"
echo "4. Video to NTSC_DVD "
read yourch
echo "$yourch"
echo "Enter Video Directory"
read $srcdir
cd "$srcdir"
touch $VAR
find $srcdir > $VAR



case $yourch in

"$yourch != 1" )
xvid
;;

"$yourch != 2" )
wmv
;;
"$yourch != 3" )
flv
;;

"$yourch != 4" )
dvd
;;

esac


xvid () {
# Collect the files in the current directory
cat $VAR | while read line; do
# Loop read the filenames from the file
INPUT=$(echo ${line})
# Grab the nxt new filename
OUTPUT=${INPUT%.*i}
# Append new extension
OUTPUT+=".avi1"
# Convert files
mencoder "$INPUT" -ovc xvid -oac mp3lame -xvidencopts fixed_quant=4 -o "$OUTPUT"
done

}


wmv () {
# Collect the files in the current directory
cat $VAR | while read line; do
# Loop read the filenames from the file
INPUT=$(echo ${line})
# Grab the nxt new filename
OUTPUT=${INPUT%.*i}
# Append new extension
OUTPUT+=".avi1"
# Convert files
mencoder "$INPUT" \
-ofps 23.976 \
-oac mp3lame \
-ovc xvid \
-xvidencopts pass=1 -o /dev/null

mencoder "$INPUT" \
-ofps 23.976 \
-oac mp3lame \
-ovc xvid \
-xvidencopts pass=2:bitrate=250 \
-o "$OUTPUT"

done

}


flv () {
# Collect the files in the current directory
cat $VAR | while read line; do
# Loop read the filenames from the file
INPUT=$(echo ${line})
# Grab the nxt new filename
OUTPUT=${INPUT%.*v}
# Append new extension
OUTPUT+=".flv"
# Convert files
ffmpeg -i "$INPUT" -ab 256 "$OUTPUT"
done

}


dvd () {
# Collect the files in the current directory
cat $VAR | while read line; do
# Loop read the filenames from the file
INPUT=$(echo ${line})
# Grab the nxt new filename
OUTPUT=${INPUT%.*g}
# Append new extension
OUTPUT+=".mpg"
# Convert files
ffmpeg -i "$INPUT" -target ntsc-dvd "$OUTPUT"
done

}

#clean up after the script has run
rm $VAR # Remove the text file with the file names

pixellany 11-17-2009 03:52 PM

The first thing I notice is "$" where it does not belong....

For variables:

read name
echo $name

For files:
touch filename
echo "stuff" > filename

Please put code into [code] tags for better readability

rootoutcast 11-17-2009 04:13 PM

ok thanks

rootoutcast 11-17-2009 11:17 PM

Hi I finished the script for the most part when I convert wmv files to xvid I get audio skipping and sync problems any ideas?

Code:



#!/bin/bash
VAR="files.txt"
DIR="srcdir"


xvid () {
touch $VAR
ls *.avi | sort > $VAR
# Collect the files in the current directory
cat $VAR | while read line; do 
# Loop read the filenames from the file
  INPUT=$(echo ${line})
# Grab the nxt new filename
  OUTPUT=${INPUT%.*i}
# Append new extension
  OUTPUT+=".avi1"
# Convert files
mencoder "$INPUT" -ovc xvid -oac mp3lame -xvidencopts fixed_quant=4 -o "$OUTPUT"
done

}


wmv () {
touch $VAR
ls *.wmv | sort > $VAR
# Collect the files in the current directory
cat $VAR | while read line; do
# Loop read the filenames from the file
  INPUT=$(echo ${line})
# Grab the nxt new filename
  OUTPUT=${INPUT%.*i}
# Append new extension
  OUTPUT+=".avi1"
  # Convert files

mencoder "$INPUT" -ovc xvid -oac mp3lame -xvidencopts fixed_quant=4 -o "$OUTPUT"

done

}


flv () {
touch $VAR
ls *.avi | sort > $VAR
# Collect the files in the current directory
cat $VAR | while read line; do
# Loop read the filenames from the file
  INPUT=$(echo ${line})
# Grab the nxt new filename
  OUTPUT=${INPUT%.*v}
# Append new extension
  OUTPUT+=".flv"
  # Convert files
ffmpeg -i "$INPUT" -ab 256 "$OUTPUT"
done

}


dvd () {
touch $VAR
ls *.avi | sort > $VAR
# Collect the files in the current directory
cat $VAR | while read line; do
# Loop read the filenames from the file
  INPUT=$(echo ${line})
# Grab the nxt new filename
  OUTPUT=${INPUT%.*g}
# Append new extension
  OUTPUT+=".mpg"
  # Convert files
ffmpeg -i "$INPUT" -target ntsc-dvd "$OUTPUT"
done

}



clear
echo "************************"
echo "* Mike The TV *"
echo "************************"
echo "* [a] Video to xvid (1 pass ) *"
echo "* [b] wmv to xvid (2 pass ) *"
echo "* [c] Video to flv (for the web) *"
echo "* [d] Video to NTSC_DVD  *"
echo "************************"
echo -n "Enter your menu choice [a-d]: "
read yourch
case $yourch in
a) xvid ;;
b) wmv  ;;
c) flv  ;;
d) dvd  ;;

esac


#clean up after the script has run
rm $VAR # Remove the text file with the file names


xaler 11-17-2009 11:25 PM

No...no....

Add it this way...

"[-code-]"
some shell script code in between...
"[-/-CODE-]"
(Remove the 4 quotes and the 5 hyphens above)

when you click on "reply with quote", click on the icon with the hash symbol...hope u get it...


All times are GMT -5. The time now is 09:46 AM.