Here is that new script I’ve been working on.  Basically the script turns VOB’s into xvid avi’s.  The script can process in the foreground, -F, or it can hand it off to the batch command, default. 

 

#!/bin/sh
#
# $Id: agk20,v 1.7 2006/07/07 01:53:25 jwhyche Exp jwhyche $
#
#
# $Log: agk20,v $
# Revision 1.7  2006/07/07 01:53:25  jwhyche
# more bugs
#
# Revision 1.6  2006/07/06 23:07:43  jwhyche
# added command line help -h and fixed some bugs about something
#
# Revision 1.5  2006/07/06 22:22:07  jwhyche
# Installed the framerate override code
# -f <0-5> where 0 is native fps
#                1 is 23.976 fps
#                2 is 24 fps
#                3 is 25 fps
#                4 is 29.970 fps
#                5 is 30 fps
#
# Revision 1.4  2006/07/06 21:35:47  jwhyche
# added default file sizing code
#
# Revision 1.3  2006/07/04 01:12:38  jwhyche
# Added aggressive demuxing using tcdecode.  Solves problem with some VOBs
# and audio sync.  Using mplayer to get video length
#
# Revision 1.2  2006/07/02 00:30:32  jwhyche
# Inital version of agk20 to replace the ageing 1.x scripts.  This version
# moves more of the processing into the main script and out of the subscript.
# While this slows the execution of the main script down some what,
# it makes the matanance of the code much easier.  Functionally this
# script is exactly the same as the original.
#
# Revision 1.1  2006/06/30 22:23:32  jwhyche
# Initial revision
#
#

# function script_write()
#
# function writes input parameters to temporary script to be
# handed off to batch command or optionally excuted in the
# foreground.
function script_write() {
            echo $1 >> $$.sh
}

# function show_help()
# function shows help options
function show_help() {
            echo "agk20 [options] [files....]
 -s <size> set the output file size of the avi
     (default output size is 10MB per minute of video)
 -b <bitrate> sets the mp3 bitrate to use for audio (default: 128)
 -F execute encoding in the Foreground instead of submitting it
    to the batch queue.
 -a <track> audio track to use for avi (default: 0)
 -A passes auto through untouched.  Use for including orginal
    5.1 sound track to avi
 -M <mode> Sets the demuxer mode for transcode.  Uses the same
    settings that transcode uses except takes 5 as a parameter to
    use tcdemux to build a nav map.   (default: 2)
 -f <0-5> where 0 is native fps
                1 is 23.976 fps
                2 is 24 fps
                3 is 25 fps
                4 is 29.970 fps
                5 is 30 fps
"
}

# function ts ()
#
# convert seconds to hours / minutes /seconds
function ts () {

seconds=$1
hours=$((seconds / 3600))
seconds=$((seconds % 3600))
minutes=$((seconds / 60))
seconds=$((seconds % 60))

echo "$hours hour(s) $minutes minute(s) $seconds second(s)"
}

# Parse command line options and set flags
#
# -s <size> set the output file size of the avi
#     (default output size is 10MB per minute of video)
# -b <bitrate> sets the mp3 bitrate to use for audio (default: 128)
# -F execute encoding in the Foreground instead of submitting it
#    to the batch queue.
# -a <track> audio track to use for avi (default: 0)
# -A passes auto through untouched.  Use for including orginal
#    5.1 sound track to avi
# -M <mode> Sets the demuxer mode for transcode.  Uses the same
#    settings that transcode uses except takes 5 as a parameter to
#    use tcdemux to build a nav map.   (default: 2)
# -f <0-5> where 0 is native fps
#                1 is 23.976 fps
#                                          2 is 24 fps
#                                          3 is 25 fps
#                                          4 is 29.970 fps
#                                          5 is 30 fps

OPTSTRING="s:b:Fa:AhM:f:h"
_progress_off="--progress_off"
_filesize=0
_audio_option="-s 2.738"
_audio_bitrate=128
_ag_demux=0
_frame_over=0

if [ $# -eq 0 ]
then
            echo "agk20 -h for options and commands"
            exit
fi

set -- `getopt ${OPTSTRING} $*`
while [ $1 != -- ]
do
      case $1 in
                  -s) _filesize=$2
                              shift; shift;
                              ;;
                  -F) _batch_mode=1
                              _progress_off=""
                              shift;
                              ;;
                  -A) _audio_option="-A -N 0x2000"
                     shift;
                         ;;
                  -a) _audio_track=$2
                              shift; shift;
                              ;;
                  -b) _audio_bitrate=$2
                              shift; shift;
                              ;;
                  -M) _demuxer=$2
                              [ $_demuxer = 5 ] && _ag_demux=1;
                              shift; shift;
                              ;;
                  -f) _frame_over=1;
                              _frc=$2;
                              shift; shift;
                              ;;
                  -h)
                              show_help;
                              exit;
                              ;;
            esac
done
shift;

#Determine output filesize in MB
((_filesize*=1024))

# for loop to begin processing files on command line
for _target in $*
do
       echo ${_target}
# Create output file name from input
      _outfile=`echo ${_target} | sed -e 's/.VOB$/.avi/g'`

# Use code from Phil Ehrens <[EMAIL PROTECTED]> mplayerprobe.sh
# to determine incoming VOB's resolution, frame rate, and
# Aspect Ratio.
#
# Thanks Phil
#

# run mplayer in -identify mode
      foo=`mplayer -identify -frames 0 -vo null -ao null\
                   ${_target} 2> /dev/null | grep ID_VIDEO`
      eval "$foo";
     
      # Parsing Parsing Parsing
      geometry=${ID_VIDEO_WIDTH}x${ID_VIDEO_HEIGHT};
      asr=0;
      framerate=$ID_VIDEO_FPS;
      index=0;
      [ $framerate = 23.976 ] && index=1;
      [ $framerate = 25     ] && index=3;
      [ $framerate = 29.970 ] && index=4;

      # Use bc to calculate asr
      asr=`bc -l << _EOF
  define asr(w,h) { 
  if (w/h >= 2.0) return (4);
  if (w/h >= 1.6) return (3);
  if (w/h >= 0.0) return (2);
  }
  asr($ID_VIDEO_WIDTH,$ID_VIDEO_HEIGHT)
_EOF
`
      _framerate="-f ${framerate},${index}";

      #frame rate code
      if [ ${_frame_over} -eq 1 ]
  then
                  [ $_frc = 0 ] && _framerate=;
                  [ $_frc = 1 ] && _framerate="-f 23,976,1";
                  [ $_frc = 2 ] && _framerate="-f 24,2";
                  [ $_frc = 3 ] && _framerate="-f 25,3";
                  [ $_frc = 4 ] && _framerate="-f 29.970,4";
                  [ $_frc = 5 ] && _framerate="-f 30,4";
      fi

      # Use mplayer to probe VOB to get video length and store it
      audio_foo=`mplayer -identify -frames 0 -vo null -ao null\
                   ${_target} 2> /dev/null | grep ID_LENGTH`
      eval "$audio_foo";
      _length=${ID_LENGTH};

      # Create default file size if -s is not specified
      [ ${_filesize} -eq 0 ] && ((_filesize=((${ID_LENGTH}/60) * 10) * 1024 ))
     
      # Get audio bit rate for AC3 audio
      if [ "${_audio_option}" == "-A -N 0x2000" ]
      then
                  _audio_bitrate=`
       tcextract -i ${_target} -t vob -x ac3 -a ${_audio_track:-0}|\
        tcscan -x ac3 | head -1 | awk '{print $8}'`
      fi
 
  # Get the bitrate for the correct filesize using bc
  # ({S}ize - ({A}udio x {L}ength)) / {L}enght = {V}ideo Bitrate
  # {S} Size of output file in KM
  # {A} Audio bitrate in KB/s (note 224 kbits/s = 224 / 8 = 28 KB/s)
  # {L} Lenght of Video Clip in Seconds
  # {V} Video bitrate in KB/s, to get kbit/s multiply 8
      vid_bitrate=`bc <<EOF
((${_filesize}-((${_audio_bitrate}/8)*${_length}))/${_length})*8
EOF
`
     
      # Lay down option -M 5 and nav.log using tcdemux
      if [ ${_ag_demux} -eq 1 ]
      then
                  _demuxer=2;
                 
                  script_write "tcdemux -i ${_target} -W > ${_target}.log"
                  _nav_option="-H 10 --psu_mode --nav_seek ${_target}.log --no_split"
      fi
      # First Pass
      script_write "transcode -a ${_audio_track:-0} \
                  -x vob \
                  -i ${_target} \
                  -w ${vid_bitrate},50 \
                  -b ${_audio_bitrate:-128},0,0 \
                  ${_audio_option} --a52_drc_off \
                  -g ${geometry} \
                  ${_framerate}\
                  -M ${_demuxer:-2} -R 1,$$.log \
                  -y xvid4,null \
                  -o /dev/null \
      --nice 2 ${_nav_option} \
      -J 32detect=force_mode=3  --print_status 20 ${_progress_off} &&"

#                 --import_asr ${asr} \
#                 --import_asr ${asr} \

      # Second Pass
      script_write "transcode -a ${_audio_track:-0} \
                  -x vob \
                  -i ${_target} \
                  -w ${vid_bitrate},50 \
                  -b ${_audio_bitrate:-128},0,0 \
                  ${_audio_option} --a52_drc_off \
                  -g ${geometry} \
                  ${_framerate}\
      -M ${_demuxer:-2} -R 2,$$.log \
                  -y xvid4, \
                  -o ${_outfile} \
      --nice 2 ${_nav_option} \
                  -J 32detect=force_mode=3 --print_status 20 ${_progress_off}"
     
       # Fix 6 Channel Surround Sound in AVI files with it
      if [ ${_audio_bitrate} -eq 448 ]
      then
                  script_write "avifix -i ${_outfile} -e 48000,16,6 -a ${_audio_track:-0}"
      fi
      mv $$.sh ${_target}.sh

  # Excute in the forground or submit it to batch command
      if [ ! ${_batch_mode} ]
      then
                  echo ${_target} >> batch.log
                  batch -f ${_target}.sh >> batch.log 2>&1
      else
                  /bin/sh ${_target}.sh
      fi
done

 

Reply via email to