#!/bin/bash
############################################################
# /usr/local/contovob (convert to vob) rm20060611
#
# I use this file to prepare mpeg-ps files for burning to a
# video dvd that can be played on any old set top dvd player.
# Th resulting video will be mpeg-ps and audio wil be ac3 
# a.k.a a52.
#
# I am normally converting mpeg-ps files that have been edited
# in Gopdit and saved with the following postprocessing command:
#
#   mencoder -of mpeg -mpegopts format=dvd:vbitrate=9000 \
#   -o "%s" -oac copy -ovc copy - &> /dev/null
#
# Working with videos saved with my DVB-T cards that have
# been edited and post processed via gopdit, this script
# script will improve video quality, convert the mp3 audio 
# to ac3 (mp3's won't work on most set top dvd players and  
# quite possibly reduce the size of the resulting file.
#
# I've also found that while I may have trouble with audio/video
# sync after resizing my video file using tcextract and replex,
# I usually don't experience that problem working with a file 
# that has first been processed with this script.
#
# You will have to have mplayer installed to have mencoder
# available. There may be other libraries and programs required
# by mencoder to do this job. You will have to watch standard out
# for dependency errors. I don't know what you have installed on
# your box but I know this works on mine.
#
############################################################

INPUT_FILE=$1
OUTPUT_FILE=$2

test -n "$INPUT_FILE"
  if [ $? -eq 1 ]; then
    echo -e "\nUsage: contovob [input file] [output file]\n"
    exit
  fi

test -n "$OUTPUT_FILE"
  if [ $? -eq 1 ]; then
  echo -e "\nUsage: contovob [input file] [output file]\n"
  exit
  fi


mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd \
-vf scale=720:576,harddup -srate 48000 -lavcopts \
vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192:aspect=16/9 \
-ofps 25 $INPUT_FILE -o $OUTPUT_FILE

#end of script