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.
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.
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..."
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.
Nice example.
Thank you.
Excelent work on the awk arguments!!!
Thanks a million!
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
you could just doCode: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 also do the same for the bit further down.Code:if FILE=$(zenity --file-selection --title="Select a File") then echo "\"$FILE\" selected." else echo "No file selected." fi
2) Also notice that I changed the backticks `somecommand` to $(somecommand). Backticks are now deprecated, so $(...) is the alternative and should be used.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"
3) Replace
withCode:vid() { file -i "$FILE" | echo $1 | grep -i '\.avi$' } if ( vid "$FILE") then avi="1" fi if [ $avi -eq "1" ]; then
All you are doing is finding the filename ends in .avi.Code:if [[ $FILE = *.avi ]]; then
4) You can tidy up the #Burn to dvd or create an iso and #cleanup section a bit too.
I hope this is more helpful than critical, and may you continue scripting !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 am having some trouble making the progress dialog display the actual progress of the process. The code I am using:
This is all I get: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"
Any idea what the problem might be?
Thanks
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.
Bookmarks