--- src/makempg	2010-05-18 22:31:35.000000000 -0400
+++ src/makempg.new	2010-09-13 11:26:04.000000000 -0400
@@ -202,6 +202,7 @@
 ID_VIDEO_HEIGHT="0"
 ID_VIDEO_FPS="0.000"
 V_DURATION="0"
+ID_AUDIO_BITRATE="0"
 # mplayer executable to use
 MPLAYER="mplayer"
 # No custom mplayer opts
@@ -287,12 +288,7 @@
 # ******************************************************************************
 # Execute the given command-line string, with appropriate stream redirection
 # Args: $@ == text string containing complete command-line
-# To filter/prettify the subprocess output before writing it to the log file,
-# set the LOG_FILTER variable before calling this function, to e.g.
-#    LOG_FILTER="gsed {s/\r/\n/g}"    # Replace LF with CR/LF
 # ******************************************************************************
-CRLF="gsed {s/\r/\n/g}"  # Turn carriage-returns into newlines
-FOLD="fold -bs"
 function cmd_exec()
 {
     if $FAKE; then
@@ -301,8 +297,7 @@
         yecho
         return
     else
-        LOG_FILTER="$CRLF"
-        eval "$@" 2>&1 | $LOG_FILTER >> "$LOG_FILE" &
+        eval "$@" 2>&1 | strings >> "$LOG_FILE" &
         PIDS="$PIDS $!"
     fi
 }
@@ -652,7 +647,7 @@
             yecho
             yecho "Do you want to keep the temporary files that were created ?"
             yecho "Please type \"yes\", or else they will be deleted"
-            yecho "(add '-noask' to your ~/.tovid/makempg.config to avoid"
+            yecho "(add '-noask' to the [mpg] section of ~/.tovid/tovid.ini to avoid"
             yecho "being asked this question in the future)"
             read input
             echo
@@ -1230,6 +1225,11 @@
     LENGTH=$V_DURATION
     MPEG_OVERHEAD=$(bc_math "$FIT_SIZE / 100")
     AUD_VID_SIZE=$(bc_math "$FIT_SIZE - $MPEG_OVERHEAD")
+    # When the audio is already compliant and the bitrate is known we
+    # can calculate a more accurate size.
+    if $AUDIO_OK && test "$ID_AUDIO_BITRATE" != "0"; then
+        AUD_BITRATE=$(echo "scale = 0; $ID_AUDIO_BITRATE / 1000" | bc)
+    fi
     AUDIO_SIZE=$(bc_math "$AUD_BITRATE * $LENGTH / (8 *1024)")
     VIDEO_SIZE=$(bc_math "$AUD_VID_SIZE - $AUDIO_SIZE")
     VID_BITRATE=$(bc_math "$VIDEO_SIZE*8*1024 / $LENGTH")
@@ -1849,12 +1849,26 @@
     [[ $TARGET = "DVD-VCD" ]] && FF_ADD_ARGS="$FF_ADD_ARGS -g 12" # experiment FIXME
 
     # Padding, for any letterboxing to be done
-    FF_VPAD=""
-    FF_HPAD=""
-    FF_VPIX=$(expr \( $TGT_HEIGHT \- $INNER_HEIGHT \) \/ 2)
-    FF_HPIX=$(expr \( $TGT_WIDTH \- $INNER_WIDTH \) \/ 2)
-    test "$FF_VPIX" -ne 0 && FF_VPAD="-padtop $FF_VPIX -padbottom $FF_VPIX"
-    test "$FF_HPIX" -ne 0 && FF_HPAD="-padleft $FF_HPIX -padright $FF_HPIX"
+    FF_PAD=''
+    FF_VPIX=0
+    FF_HPIX=0
+    FF_VPIX=$(( (TGT_HEIGHT - INNER_HEIGHT) / 2 ))
+    FF_HPIX=$(( (TGT_WIDTH - INNER_WIDTH) / 2 ))
+    PAD=0
+    (( FF_VPIX )) || (( FF_HPIX )) && PAD=1
+    # changed options: -pad{side} to -vfilters pad= , to -vf pad=. Check this.
+    ff_opts=$(ffmpeg --help 2>&1)
+    if grep -q -w -- -vf <<< "$ff_opts" && ((PAD)); then
+        FF_PAD="-vf pad=${TGT_WIDTH}:${TGT_HEIGHT}:${FF_HPIX}:${FF_VPIX}"
+    elif grep -q -w -- -vfilters <<< "$ff_opts" && ((PAD)); then
+        FF_PAD="-vfilters pad=${TGT_WIDTH}:${TGT_HEIGHT}:${FF_HPIX}:${FF_VPIX}"
+    else
+        FF_HPAD=''
+        FF_VPAD=''
+        ((FF_HPIX)) && FF_HPAD="-padleft $FF_HPIX -padright $FF_HPIX"
+        ((FF_VPIX)) && FF_VPAD="-padtop $FF_VPIX -padbottom $FF_VPIX"
+        ((PAD)) && FF_PAD="$FF_HPAD $FF_VPAD"
+    fi 
 
     # Target TV system
     test "$TVSYS" = "PAL" && FF_TARGET="-target pal"
@@ -1882,13 +1896,12 @@
     FF_BITRATE="-b ${VID_BITRATE}k -ab ${AUD_BITRATE}k ${AUDIO_CHAN[chan1-1]} "
     FF_ENC_CMD="$PRIORITY ffmpeg -i \"$IN_FILE\" $FF_THREAD $CLIP_SEEK $FF_LENGTH $ASYNC $ASYNC1 \
         $FF_TARGET $FF_QUANT $FF_BITRATE $FF_ADD_ARGS $FF_FPS $FF_ILACE \
-        $FF_SIZE $FF_VPAD $FF_HPAD $FF_ASPECT $FF_CHANNEL_MAP"
+        $FF_SIZE $FF_PAD $FF_ASPECT $FF_CHANNEL_MAP"
     $OVERWRITE && FF_ENC_CMD="$FF_ENC_CMD -y "
     FF_ENC_CMD="$FF_ENC_CMD \"$OUT_FILENAME\" ${NEW_AUDIO[@]}"
     yecho "Encoding video and audio with the following command:"
     yecho "$FF_ENC_CMD"
 
-    LOG_FILTER="$CRLF"
     cmd_exec "$FF_ENC_CMD"
 
     if $FAKE; then
@@ -1930,7 +1943,6 @@
     #AUDIO_CMD="$PRIORITY mplayer $MPLAYER_OPTS \"$IN_FILE\" -dumpaudio -dumpfile \"$AUDIO_STREAM\""
     run_audio_cmd()
     {
-        LOG_FILTER="$CRLF"
         "${AUDIO_CMD[@]}" >> "$LOG_FILE" 2>&1 &
         #$PRIORITY ffmpeg $CLIP_SEEK $FF_LENGTH -i "$IN_FILE" -vn -acodec copy \
         #$AUDIO_MAP "${AUDIO_STREAM[@]}" >> "$LOG_FILE" 2>&1
@@ -2043,7 +2055,6 @@
 
 
     # Copy the video stream
-    LOG_FILTER="$CRLF"
     cmd_exec "$VID_COPY_CMD"
 
 
@@ -2060,7 +2071,7 @@
     fi
     VID_PLAY_CMD="$PRIORITY $MPLAYER $NOCONSOLE_CONTROLS -benchmark -nosound -noframedrop $SUBTITLES -vo yuv4mpeg:file=\"$YUV_STREAM\"${YUV4MPEG_ILACE} $VID_FILTER $MPLAYER_OPTS \"$IN_FILE\" $CLIP_SEEK $MP_FRAMES"
     if $USE_FFMPEG ; then
-        VID_ENC_CMD="ffmpeg -i \"$IN_FILE\" $FF_THREAD $CLIP_SEEK $FF_LENGTH -an $FF_TARGET $FF_CODEC $FF_QUANT $FF_BITRATE $FF_ADD_ARGS $FF_ILACE $FF_SIZE $FF_VPAD $FF_HPAD $FF_ASPECT -y \"$VIDEO_STREAM\""
+        VID_ENC_CMD="ffmpeg -i \"$IN_FILE\" $FF_THREAD $CLIP_SEEK $FF_LENGTH -an $FF_TARGET $FF_CODEC $FF_QUANT $FF_BITRATE $FF_ADD_ARGS $FF_ILACE $FF_SIZE $FF_PAD $FF_ASPECT -y \"$VIDEO_STREAM\""
     else
         VID_ENC_CMD="cat \"$YUV_STREAM\" | $YUVDENOISE $ADJUST_FPS $PRIORITY mpeg2enc --sequence-length $DISC_SIZE --nonvideo-bitrate $NONVIDEO_BITRATE $MTHREAD $ASPECT_FMT $MPEG2_FMT $VID_FPS $VERBOSE $VID_NORM $MPEG2_QUALITY -o \"$VIDEO_STREAM\""
     fi
@@ -2078,7 +2089,6 @@
         file_output_progress "$YUV_STREAM" "Ripping raw uncompressed video stream"
     fi
 
-    LOG_FILTER="$CRLF"
     cmd_exec "$VID_ENC_CMD"
 
     # For parallel encoding, nothing further yet
