Tovid Wiki
Advertisement

Sorry if you are looking for GUI for tovid. I caught you. :) You might want Using the tovid GUI instead.


Gnome nautilus-script User Interface to tovid[]

Using the capability of Gnome 2.14's nautilus-scripts, I now could complete the whole process of detecting/specifying crop, preview crop, encoding, adjust audio delay, create dvd, preview it, and burn the dvd all without touching any command line. Not quite GUI interface but good enough for me while waiting for the development folks to finish cooking the real GUI application.

The system is built using the filename as a means of passing parameters and display process status.

OK before you start to download these 7 scripts to mess around with your Gnome desktop, let me try to show you how I use them. If you have read the MyWorkFlow, you may know how to use these scripts already. In anycase let have a breif run down....


Workflow[]

The 7 scripts are named with a number prefix so that they appear on the right click Script menu of nautilus file manager in order of my workflow. The following are the scripts name and their function.

  • 1.ns-cropdetect - detect those black bars to be crop out from the selected file. (optional) -mplayer frontend-
  • 2.ns-viewcrop - view the cropped result from the selected file. (optional) -mplayer frontend-
  • 3.ns-encode - encode the selected file(s). -tovid frontend-
  • 4.ns-adjust - adjust the audio/video sync from the selected file. (optional) -postproc frontend-
  • 5.ns-create - create a dvd file system from the selected file(s). -todisc frontend-
  • 6.ns-preview - preview the dvd filesystem. -xine frontend-
  • 7.ns-burn - burn a dvd from a selected dvd file system. -makedvd front-end-


How they work[]

All the script work like this....

  • First I pick a file, right click to select Script, choose the script and go.
  • The script will take over, a log file with a process id appended to it will be used to store the log and provide feedback to user.
  • The result mpg files will be created in target folder of /usr/dvd.

Script 1 2 and 4 are optional for the workflow.


Example: Simple Workflow[]

Let play with a workflow that use just 4 scripts (less the 3 optional one). The sources is name mytestvideo.avi, the encoded mpg will be myvideofile.mpg, the output dvd file system will be mydvd.


  • 3.ns-encode - Select mytestvideo.avi, Right click, Select Script, choose 3.ns-encode. The script will take over, kicking off tovid to encode the video. While encoding is going on I can view the log file mytestvideo.avi.12345 any time I want. As soon as the log file turn in to mytestvideo.avi.12345.done I know that the encoding work is completed. I should find my result file mytestvideo.mpg in the output folder /usr/dvd. I can pick multiple files and kick off the script in one go. The script know how to process all the selected files, one file at a time.


  • 5.ns-create - Select the mytestvideo.mpg, right click, select Script, choose 5.ns-create to kick it off. The script will fire off todisc to create the dvd file system, name mydvd for me. Same thing I can review the progress by looking into the log file 5.ns-create.12345. When it turn 5.ns-create.12345.done, I know it is done. When I see 5.ns-create.12345.done.err I know there is an error somewhere. Oh! yes. todisc will pop up a preview window show us the preview menu. Just kill the window so that the processing can continue. The result is named mydvd. I can pick multiples mpg files to be included in the dvd. Just use control-click to select files. Nautilus will total up the size for me as I pick. Keep the total within 4.3gb to be on the safe side. The result dvd file system will be created in /usr/dvd/mydvd.


  • 6.ns-preview - this script allow me to preview the dvd using xine. Just select mydvd, right click, select Script, choose 6.ns-preview. xine will be up previewing the dvd. Just kill the windows when done.


  • 7.ns-burn - this script will burn the selected mydvd to dvd. No more, no less.


Example: cropping[]

  • 1.ns-cropdetect - If the file letterbox.avi has a black bar on top and bottom that I want to crop out. I would pick it, right click, select script, choose 0-ns-cropdetect. The script will kick off mplayer, let mplayer play a few sec. and kill the window. A symbolic link file letterbox.avi=crop=368:208:8:40 will be created, for example. Basically, the script place the detected crop infomation in a filename and link it to the original video for me. Also, the log file letterbox.avi=crop=360:240:0:30.log has more crop detect info if I need it. Actually, by just looking at the crop=368:208:8:40 alone I can tell that the original resolution of letterbox.avi is 384x288 (368+8+8 x 208+40+40). The mplayer crop detect always take an equal size from left and right, top and bottom.


  • 2.ns-viewcrop - To view the cropped result just pick the letterbox.avi=crop=368:208:8:40, righ click, select scripts, choose 2.ns-viewcrop. The script will fire off mplayer with crop range to preview the video. I can edit the filename to adjust the crop if necessary. By the way if there isn't any black bar on the video crop detect will return letterbox.avi=crop=384:288:0:0. Encoding this file is the same as encoding just the letterbox.avi. I can also edit it to letterbox.avi=crop=384:208:0:80 to just cut the top 80 pixels off. But letterbox.avi=crop=384.208:0:81 will fail since there isn't enough to make a 384x208 frame, 1 pixel short.
  • 3.ns-encode - If I encode letterbox.avi=crop=368:208:8:40 instead of letterbox.avi, the script will encode the video with the -crop parameters. I will remove the log file but normally keep the link file just in case I want to encode it again, since the link file is small.


Example: Adjust Audio delay[]

  • 4.ns-adjust - If the resulting letterbox.mpg has audio/video sync problem. I would use mplayer to find out the delay in ms. Use + and - to adjust the delay while video is playing. Let say I get -300ms to get them in sync, I can rename the letterbox.mpg to A=-300=letterbox.mpg, select it, right click, select Script, choose 4.ns-adjust. This script will call postproc with a -audiodelay of -300 pass in. The result out put will be letterbox.mpg.


Example: Title[]

  • 5.ns-create - by default mpg name will be used as its title. I would specify a short name instead of using the default first 12 chars of filename. For example, T=LetterBox=letterbox.mpg. By adding a T=ShortTitle= to each file, I could get the system to put the right title size on the thumbnail.


Example: additional parameters for encoding[]

  • 3.ns-encode - I can pass additional parameters and switches for encoding by simply making a symbolic link to the video file, edit the filename of the link with some parameter. For example, letterbox.avi=R=2200=S=95=P=high=A=wide=A=pal will instruct tovid to encode at vbitrate of 2200, safe area of 95, high priority, 16x9 and PAL format.
  • Note: By the way these features are added for fun. I have my preference of these parameters in the script itself. Hence I hardly use them. I.e. they are not fully tested. Some combination might fail.


Install instruction[]

Note that these set of script is tested and work for SVN 946 and up or pre0.29 version of tovid. So I would just put them all in a folder name 0.29 and drop it in the nautilus-scripts folder.

  • Check to make sure you have Gnome 2.14 before you start
  • Create folder ~/.gnome2/nautilus-scripts/0.29/
  • copy all scripts in there,
  • chmod +x ~/.gnome2/nautilus-scripts/0.29/*
  • Logout and log back in
  • we are ready.


The scripts[]

The scripts here are for showing the concept. As I'm still tuning the script here and there I will include a link to the current version later here.

1.ns-cropdetect[]

#!/bin/bash
# ns-cropdetect - nautilus-script frontend to mplayer to do crop detect
#                  to get -mplayeropts -vf crop=w:h:x:y for tovid 
# by oh July20,2006 updated:July21,2006
#
mplayer -vf cropdetect $1           > crop.$$
vf=$(tail -10 crop.$$ | grep CROP -m 1 | cut -f2 -d"(" | cut -f1 -d")")
Crop=$(echo $vf | cut -f2 -d" ")
#mplayer -vf $Crop $1
mv crop.$$ "$1=$Crop.log"
ln -s $PWD/$1 "$1=$Crop"
exit
#END#

2.ns-viewcrop[]

#!/bin/bash
# ns-viewcrop - nutilus-scripts frontend to mplayer preview crop
# oh July21,2006 updated:July27,2006
#
CMD=$(basename $0)
[ "X$1" = "X" ] && { echo "Usage: $CMD <file> [<file> <file...>]" ; exit ; }
[ "$(echo "$1" | cut -f2 -d=)" = "crop" ] || { echo "$1 Not enough info on file." ; exit ; }
Crop="$(echo "$1" | cut -f2-3 -d=)"
mplayer -vf-pre $Crop $1 
exit
#END#

3.ns-encode[]

#!/bin/bash
# ns-encode - Gnome Nautilus-scripts frontend to tovid 
# oh June24,2006 updated:July22,2006
#
CMD=$(basename $0)
[ "X$1" = "X" ] && { echo "Usage: $CMD <file> [<file> <file...>]" ; exit ; }
# user's parameters-------------------------------------------------------------
VBitRate=3000                             #normal 5000 - keep low for lowres avi
Type="live"                               #live|animation|bw not for dvd now?
Filters="none"                            #none|contrast|both|denoise
Amplitude=0.4                             #0.4 good for toshiba dvd player
Priority="low"                            #since run behind gnome, keep low
Safe=100                                  #my toshiba 32WL58 at 93
OutDir="/usr/dvd"                         #default output folder name
AddOpts="-bdvd"                           #bdvd produce smaller output file
# start processing--------------------------------------------------------------
[ ! -z "$1" ] && list="$@";
for file in $list ;
do
  StartTime=$(date)
  log=$file.$$
  echo "$CMD - Nautilus-scripts frontend to tovid for encoding." >  $log 2>&1
  echo "-------------------------------------------------------" >> $log 2>&1
  if [ ! -f "$file" ];                    #for commandline to trap keyin
  then
    echo "$file not found!" 
  else
    rm $file.log                                          >/dev/null 2>&1
    F0=$(echo $file | cut -f1 -d=)        #pick the original filename
    # strip the .avi, .mkv, .mov, mp4, or .ogm extension.
    name=`echo $F0 | sed -e 's/\.[amow][vkgopm][ivm4g]$//'`
    ext=`echo $F0 | sed -e 's/^.*\.//'`   #ext is not used in this script
    Tname="T=$(echo $name | cut -c1-12)=$name"    #add T=12chars= for to-create
    list="$(echo $file | cut -f2- -d=)" 
    [ "X$F0" = "X$list" ] && { list="" ; }
    # if list not empty check and pick up additional parameters---------------
    while [ ! "X$list" = "X" ]; do
      F1=$(echo $list | cut -f1 -d=)
      F2=$(echo $list | cut -f2 -d=)
      list=$(echo $list | cut -f3- -d=)
      case $F1 in
          "A" | "add" | "addoptions" )
	        [ "X$(echo $F2 | cut -c1)" = "X-" ] || { F2="-$F2" ; }
                AddOpts="$AddOpts $F2"
                ;;
          "C" | "crop" )        #put crop as AddOpts cause no default values.
                AddOpts="$AddOpts -crop $F2"
                ;;
          "R" | "V" | "rate" | "vbitrate" )
                VBitRate=$F2
                ;;
          "P" | "priority" )
                Priority=$F2
                ;;
          "T" | "type" )
                Type=$F2
	        ;;
          "F" | "filter" | "filters" )
                filter=$F2
	        ;;
          "S" | "safe" )
                Safe=$F2
	        ;;
          * )
	        echo "Invalid option $F1=$F2 ignored." >> $log 2>&1
                ;;
      esac
    done
    Options="-type $Type -vbitrate $VBitRate -priority $Priority"
    Options="$Options -safe $Safe -amplitude $Amplitude -force"
    eval tovid $Options -in $file -out $OutDir/$name $AddOpts      >> $log 2>&1
  fi
  echo "---------------------------------------------------------" >> $log 2>&1
  echo "==$CMD   ended $(date)=="    >> $log 2>&1
  echo "==$CMD started $StartTime==" >> $log 2>&1
  echo "---------------------------------------------------------" >> $log 2>&1
  if [ "X$(grep "error" $log)" = "X" ];
  then
    mv $log $log.done
  else
    mv $log $log.done.err
  fi
done
exit
#END#

4.ns-adjust[]

#!/bin/bash
# ns-adjust - Nautilus-scripts frontend to tovid postproc to adjust audiodelay
# oh June26,2006 updated:July27,2006
#
CMD=$(basename $0)
[ "X$1" = "X" ] && { echo "Usage: $CMD <file> [<file> <file...>]" ; exit ; }
StartTime=$(date)
log=$1.$$
# check special filename and pick up adjustment parameters------------------
[ "X$(echo $1 | cut -f1 -d=)" = "XA" ] || { echo "Nothing to do." ; exit ; }
AudioDelay=$(echo $1 | cut -f2 -d=)
Filename=$(echo $1 | cut -f3- -d=)
[ -f $Filename ] && { $Filename="$Filename-A" ; }   #do not overwrite original
echo "$CMD nautilus-scripts front-end to tovid postproc" > $log 2>&1
echo "-----------------------------------------------------------" >> $log 2>&1
eval postproc -audiodelay $AudioDelay $1 $Filename                 >> $log 2>&1
echo "-----------------------------------------------------------" >> $log 2>&1
echo "==$CMD   ended $(date)=="    >> $log 2>&1
echo "==$CMD started $StartTime==" >> $log 2>&1
echo "-----------------------------------------------------------" >> $log 2>&1
if [ "X$(grep "error" $log)" = "X" ];
then
    mv $log $log.done
else
    mv $log $log.done.err
fi
exit
#END#

5.ns-create[]

#!/bin/bash
# ns-create - nautilus-scripts frontend todisc v915/0.29 and up
# by oh July17,2006 updated:July22,2006
# 
CMD=$(basename $0)
OUTDIR="/usr/dvd"                            #default output folder name
AddOpts="-static -chain-videos"              #my preference 
log=$CMD.$$
StartTime=$(date)
[ "X$1" = "X" ] && { echo "Usage: $CMD <file> [<file> <file...>]" ; exit ; }
F="" ; T="" 
[ ! -z "$1" ] && list="$@";
for file in $list ;
do
  ext="mpg"                                  
  name=`basename $file ".mpg"`           #remove .mpg from filename file.mpg
  if [ ! -f "$name.$ext" ];              #and put it back
  then
    echo "File '$name.$ext' doesn't exist" >>$log 2>&1   #reject non-mpg file
  else
    F="$F $name.$ext" ; T="$T $(echo $name | cut -f2 -d=)" 
  fi
done
FileAndTitles="-files $F -titles $T"
echo "$CMD - Nautilus-scripts frontend tovid for encoding"          > $log 2>&1
echo "-----------------------------------------------------------"  >>$log 2>&1
eval todisc $FileAndTitles -out $OUTDIR/mydvd $AddOpts  -noask      >>$log 2>&1 
echo "-----------------------------------------------------------"  >>$log 2>&1
echo "$CMD   ended $(date)"    >> $log 2>&1
echo "$CMD started $StartTime" >> $log 2>&1
echo "-----------------------------------------------------------"  >>$log 2>&1
if [ "X$(grep "error" $log)" = "X" ] ;
then
  mv $log $log.done ; rm yes ; rm todisc.log
else
  mv $log $log.done.err ; rm yes
fi
exit
#END#

6.ns-preview[]

#!/bin/bash
# ns-preview - nautilus-scripts frontend mplayer to preview dvd
# by oh July17,2006 updated:July18,2006
# 
CMD=$(basename $0)
log="$0.$$"
[ "X$1" = "X" ] && { echo "Usage: $CMD <DIR>" ; exit ; }
[ ! -d "$1/VIDEO_TS" ] &&  { echo "$1/VIDEO_TS not found" ; exit ; }
xine dvd:$PWD/$1 
exit
#END#

7.ns-burn[]

#!/bin/bash
# ns-burn - nautilus-scripts frontend makedvd to just burn disc
# by oh July17,2006 updated:July21,2006
# 
CMD=$(basename $0)
log=$CMD.$$
DEVICE=/dev/dvd                             #change this if necessary
StartTime=$(date)
[ "X$1" = "X" ] && { echo "Usage: $CMD <DIR>" ; exit ; }
[ ! -d "$1/VIDEO_TS" ] &&  { echo "$1 is a good dvd file system." ; exit ; }
echo "$CMD - Nautils-script frontend tovid makedvd to burn disc"   > $log 2>&1
echo "---------------------------------------------------------"   >>$log 2>&1
echo "makedvd -brun -device $DEVICE $1"                >>$log 2>&1
makedvd -burn -device $DEVICE $1                       >>$log 2>&1 
echo "---------------------------------------------------------"   >>$log 2>&1
echo "$CMD   ended $(date)"    >> $log 2>&1
echo "$CMD started $StartTime" >> $log 2>&1
echo "---------------------------------------------------------"   >>$log 2>&1
if [ "X$(grep "error" $log)" = "X" ];
then
  eject
  mv $log $log.done 
else
  mv $log $log.done.err
fi
exit
#END#


Credits[]

  • Thanks to Mac North, grepper and wapcaplet for quick implementation of -amplitude, -chain-videos and -crop feature to help this workflow.
  • Hey how about -start/-end for tovid and -nopreview for todisc? :)

Thanks folks.


//oh.July2006

Advertisement