#!/bin/bash # # A script to correct the resolution of an AVI file and # make a DVD without any stretching or squashing # # NTSC values dvd_width=720 dvd_height=480 # Precision of computations BC_SCALE=10 print_usage() { echo "Usage: ${PROG_NAME} [OPTION]... WIDTHxHEIGHT" echo echo "Outputs ffmpeg options to correctly convert an AVI file," echo "of width WIDTH and height HEIGHT, for creating a" echo "video DVD." echo echo "Options:" echo " -h display this help and exit" echo " -w output in widescreen format (preferred)" echo " -v verbose output" echo echo "When encoding to a 16:9 aspect MPEG (*see note below*)" echo " Source NTSC/PAL NTSC/PAL NTSC/PAL Aspect CVD SVCD DVD 4:3 Not Applicable: See above table for 1.33 resolutions 16:9 *352x480 / *352x576 *480x480 / *480x576 352x480 / 352x576 704x480 / 704x576 720x480 / 720x576 1.85 *352x460 / *352x552 *480x460 / *480x552 352x460 / 352x552 704x460 / 704x552 720x460 / 720x552 2.20 *352x388 / *352x432 *480x388 / *480x464 352x388 / 352x464 704x388 / 704x464 720x388 / 720x464 2.35 *352x360 / *352x432 *480x360 / *480x432 352x360 / 352x432 704x360 / 704x432 720x360 / 720x432" } #dvd_dar this is either 16:9 or 4:3 the Display Aspect Ratio dvd_dar=`echo "scale=${BC_SCALE}; 4/3" | bc` DISPLAY_DAR="4:3" while getopts "hwv" flag ;do case ${flag} in h) print_usage exit 0 ;; w) # Widescreen, 16:9 dvd_dar=`echo "scale=${BC_SCALE}; 16/9" | bc` DISPLAY_DAR="16:9" widescreen=yes ;; v) VERBOSE=yes ;; ?) echo "${PROG_NAME}: Invalid option: ${OPTARG}." echo "Try \`${PROG_NAME} --help' for more information." exit 1 ;; esac done shift `expr "${OPTIND}" - 1` # `$#' now represents the number of arguments after the options. # `$1' is the first argument, etc. if [ $# -ne 1 ]; then print_usage exit 1 fi calc_par() { width=$1 height=$2 dar=$3 echo "scale=${BC_SCALE}; ($height*$dar)/$width" | bc } src_width=$(echo $1 | sed "s!\([0-9]*\)x[0-9]*!\1!") src_height=$(echo $1 | sed "s![0-9]*x\([0-9]*\)!\1!") src_dar=`echo "scale=${BC_SCALE}; $src_width/$src_height" | bc` src_par=$(calc_par $src_width $src_height $src_dar) dvd_par=$(calc_par $dvd_width $dvd_height $dvd_dar) # when width of DVD is going to be 720, height will be: out_height=`echo "scale=0; ($dvd_par*$dvd_width)/$src_dar" | bc` # Temporaire: if [ ${out_height} -gt 480 -a ${out_height} -lt 485 ]; then out_height=${dvd_height} fi h22=`echo "scale=0; ($out_height/2)*2" | bc` # ...and working out height is even, if not add 1 to make it even if [ $out_height != $h22 ]; then out_height=`expr $out_height + 1` fi #Padding needed #And test if even pixels p=`echo "scale=0; ($dvd_height-$out_height)/2" | bc` p22=`echo "scale=0; ($p/2)*2" | bc` # Padding values must be even. if [ $p != $p22 ]; then p_top=`expr $p - 1` p_bot=`expr $p + 1` else p_bot=$p p_top=$p fi if [ "x${VERBOSE}" = "xyes" ]; then out_par=$(calc_par $dvd_width $out_height $dvd_dar) echo "Source:" echo " Size................: ${src_width}x${src_height}" echo " Display Aspect Ratio: ${src_dar}" echo " Pixel Aspect Ratio..: ${src_par}" echo echo "DVD:" echo " Size................: ${dvd_width}x${dvd_height}" echo " Display Aspect Ratio: ${dvd_dar}" echo " Pixel Aspect Ratio..: ${dvd_par}" echo echo "Output:" echo " Size................: ${dvd_width}x${out_height}" echo " Display Aspect Ratio: ${dvd_dar}" echo " Pixel Aspect Ratio..: ${out_par}" echo " Padding Top.........: ${p_top}" echo " Padding Bottom......: ${p_bot}" echo echo "ffmpeg options:" fi echo " -s ${dvd_width}x${out_height} -padtop ${p_top} -padbottom ${p_bot} -aspect ${DISPLAY_DAR}" exit $?