Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: bash script

  1. #1
    Join Date
    Jun 2007
    Beans
    11

    bash script

    Hi does anyone know how to get the zenity progress bar to work with mencoder.I'm trying to write a video converter script but haven't got the knowledge to get the progress bar to work as i'm still a newb.

  2. #2
    Join Date
    Jun 2007
    Beans
    11

    Re: bash script

    I used this line of code after mencoder but the progress bar stops half way through.
    2>&1 | awk -vRS='\r' '$1 ~ /Pos/ {gsub(/f/," ");gsub(/%)/," ");gsub(/ \(/," ");if ($4>0)print $4; fflush();}'| zenity --progress --percentage=0 --auto-close --auto-kill --title="Converting" --text="Running..."

  3. #3
    Join Date
    Jun 2007
    Beans
    11

    Re: bash script

    I've worked it out it was when the output from mencoder was getting to 1000s when it was going wrong,here's the finished script.
    Before you tell me its rubbish this is my first script and i'm only learning.
    Code:
      #!/bin/bash
    
    
    #Choose video file to use
     zenity --info \
              --text="video converter."
                    
    
    FILE=`zenity --file-selection --title="Select a File"`
    
            case $? in
                     0)
                            echo "\"$FILE\" selected.";;
                     1)
                            echo "No file selected.";;
                    -1)
                            echo "No file selected.";;
            esac
    
    
    
    
    #Check video type
    vid()
    
    {
    file -i "$FILE" | echo $1 | grep -i '\.avi$'
    }
    
    if ( vid "$FILE")
            then
    	avi="1"
    fi	
    
    if [ $avi -eq "1" ]; then
    	zenity --info \
              --text="You have selected the correct video type."
    	else
    	zenity --error --title="Error" --text="You have not selected a correct type of file." 
    	exit 
    fi
    
    
    
    
    #Choose a destination for your project
    dir=`zenity --file-selection --directory --title="Select a project destination"`
    
            case $? in
                     0)
                            echo "\"$dir\" selected.";;
                     1)
                            echo "No file selected.";;
                    -1)
                            echo "No file selected.";;
            esac
    cd "$dir"
    
    
    
    
    #Choose bitrate
    BITRATE=$(zenity --scale --text "Choose video bitrate" --min-value=1000 \
    --max-value=5000 --value=1000 --step=10);echo $BITRATE
    
    
    
    
    
    #Encode using mencoder
    mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
      -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 \
      -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=$BITRATE:\
    keyint=15:vstrict=0:acodec=ac3:abitrate=128:aspect=16/9 -ofps 25 \
    -o movie.mpg "$FILE" 2>&1 | awk -vRS="\r" '$1 ~ /Pos/ {gsub(/Pos:/,"  ");gsub(/%\)/," ");gsub(/ \(/," ");print $3"\n#Position :\\t"$1"\\nFrame :\\t"$2"\\nPercentage :\\t"$3"%\\nFrame Rate :\\t"$4"\\nTime Remaining :\\t"$6; fflush();}' | zenity --progress --auto-kill --auto-close
    
    
    
    #Create an xml file for dvdauthor 
    echo '<dvdauthor dest="DVD">
      <vmgm />
       <titleset>
         <titles>
           <pgc>
             <vob file="movie.mpg" chapters="0,15:00,30:00,45:00,1:00:00"/>
           </pgc>
          </titles>
       </titleset>
     </dvdauthor>' > dvdauthor.xml
    
    
    
    
    #Create dvd file structure
    dvdauthor -x dvdauthor.xml 2>&1 | awk '{ print $1; fflush() }'| zenity --progress --pulsate --auto-close \
    --text "Creating dvd file structure"
    
    
    
    
    #Burn to dvd or create an iso
    
    ans=$(zenity  --list --text "do you want to burn straight to dvd or create an iso?" --radiolist  --column "Pick" --column "Opinion" TRUE 'Create an iso'  FALSE 'Burn straight to dvd (please insert dvd)'); 
     
     if [ "$ans" = "Burn straight to dvd (please insert dvd)" ]
    
     then 
            dvd+rw-mediainfo /dev/dvd
    fi
    
    if [ $? -eq 0 ]
      then dev=/dev/dvd
      
      else dev=/dev/dvd1
    fi
    
    
    if [ "$ans" = "Burn straight to dvd (please insert dvd)" ]
    
     then
    
       growisofs -Z "$dev" -dvd-compat \
    "$dir"'/DVD'  2>&1 | awk '{ print $1; fflush() }' | zenity --progress --auto-close \
    --text "Burning DVD" && eject "$dev"
    
    
     else
         mkisofs -dvd-video -v -o dvd.iso "$dir"'/DVD' 2>&1 | awk '{ print $1; fflush() }' | zenity --progress --auto-close \
    --text "Creating iso file"
    
    fi
    
    
    
    
    #cleanup 
    zenity --question --text "Do you want to delete temporary files?"; 
    
    if [ $? -eq 0 ]
       then 
       rm "$dir"'/dvdauthor.xml' & rm "$dir"'/movie.mpg' & rm -r "$dir"'/DVD'
    fi
     zenity --info \
              --text="Enjoy your film."
    exit
    Last edited by prophet73; November 20th, 2007 at 09:18 PM.

  4. #4
    Join Date
    Feb 2006
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: bash script

    Nice example.

  5. #5
    Join Date
    Jun 2007
    Beans
    11

    Re: bash script

    Thank you.

  6. #6
    Join Date
    Sep 2005
    Location
    Portugal
    Beans
    19
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: bash script

    Excelent work on the awk arguments!!!
    Thanks a million!

  7. #7
    Join Date
    Jan 2008
    Location
    UK
    Beans
    286
    Distro
    Ubuntu Development Release

    Re: bash script

    Quote Originally Posted by prophet73 View Post
    I've worked it out it was when the output from mencoder was getting to 1000s when it was going wrong,here's the finished script.
    Hi,
    Just a couple of things which could make this a tiny bit better. Perhaps consider these for future scripts.

    1) 'if' does something if the result is true (ie. exit 0), so instead of

    Code:
    FILE=`zenity --file-selection --title="Select a File"`
    
            case $? in
                     0)
                            echo "\"$FILE\" selected.";;
                     1)
                            echo "No file selected.";;
                    -1)
                            echo "No file selected.";;
            esac
    you could just do

    Code:
    if FILE=$(zenity --file-selection --title="Select a File")
            then echo "\"$FILE\" selected."
            else echo "No file selected."
            fi
    you could also do the same for the bit further down.

    Code:
    #Choose a destination for your project
    if dir=$(zenity --file-selection --directory --title="Select a project destination")
    
            then echo "\"$dir\" selected."
            else echo "No file selected."
    fi
    cd "$dir"
    2) Also notice that I changed the backticks `somecommand` to $(somecommand). Backticks are now deprecated, so $(...) is the alternative and should be used.

    3) Replace

    Code:
    vid()
    
    {
    file -i "$FILE" | echo $1 | grep -i '\.avi$'
    }
    
    if ( vid "$FILE")
            then
    	avi="1"
    fi	
    
    if [ $avi -eq "1" ]; then
    with

    Code:
    if [[ $FILE = *.avi ]]; then
    All you are doing is finding the filename ends in .avi.

    4) You can tidy up the #Burn to dvd or create an iso and #cleanup section a bit too.

    Code:
    #Burn to dvd or create an iso
    
    ans=$(zenity  --list --text "do you want to burn straight to dvd or create an iso?" --radiolist  --column "Pick" --column "Opinion" TRUE 'Create an iso'  FALSE 'Burn straight to dvd (please insert dvd)')
    
    if [ "$ans" = "Burn straight to dvd (please insert dvd)" ]
    
     then
    
      if dvd+rw-mediainfo /dev/dvd
       then dev=/dev/dvd
       else dev=/dev/dvd1
      fi  
    
      growisofs -Z "$dev" -dvd-compat \
    "$dir"'/DVD'  2>&1 | awk '{ print $1; fflush() }' | zenity --progress --auto-close \
    --text "Burning DVD" && eject "$dev"
    
     else
      mkisofs -dvd-video -v -o dvd.iso "$dir"'/DVD' 2>&1 | awk '{ print $1; fflush() }' | zenity --progress --auto-close \
    --text "Creating iso file"
    
    fi
    
    
    #cleanup 
    if zenity --question --text "Do you want to delete temporary files?"; 
    
       then 
       rm "$dir"'/dvdauthor.xml' & rm "$dir"'/movie.mpg' & rm -r "$dir"'/DVD'
    fi
     zenity --info \
              --text="Enjoy your film."
    I hope this is more helpful than critical, and may you continue scripting !

  8. #8
    Join Date
    Nov 2007
    Location
    SLC
    Beans
    200
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: bash script

    Quote Originally Posted by ezramorris View Post
    Hi,
    Just a couple of things which could make this a tiny bit better. Perhaps consider these for future scripts.



    [CODE]
    growisofs -Z "$dev" -dvd-compat \
    "$dir"'/DVD' 2>&1 | awk '{ print $1; fflush() }' | zenity --progress --auto-close \
    --text "Burning DVD" && eject "$dev"
    I am having some trouble making the progress dialog display the actual progress of the process. The code I am using:

    Code:
    growisofs -Z $drive -allow-limited-size $file 2>&1 | awk '{ print $1; fflush() }' |zenity --progress --percentage=0 --auto-close --text="Burning..." --title="BurnBIG Progress"
    This is all I get:



    Any idea what the problem might be?

    Thanks

  9. #9
    Join Date
    Jun 2007
    Beans
    11

    Re: bash script

    This part " |zenity" should be "| zenity" you missed a space out between the pipe and the zenity command mate. It should work now.
    Last edited by prophet73; September 20th, 2008 at 11:29 PM.

  10. #10
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: bash script

    Quote Originally Posted by prophet73 View Post
    This part " |zenity" should be "| zenity" you missed a space out between the pipe and the zenity command mate. It should work now.
    That has nothing to do with it. I like to have spaces around my pipes for readability, but spaces aren't required. Try it.
    Quote Originally Posted by davidryder View Post
    Code:
    growisofs -Z $drive -allow-limited-size $file 2>&1 | awk '{ print $1; fflush() }' |zenity --progress --percentage=0 --auto-close --text="Burning..." --title="BurnBIG Progress"
    Try omitting zenity from the pipeline and see if the correct values are being printed.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •