[125] | 1 | #! /bin/sh |
---|
| 2 | |
---|
| 3 | # The copyright in this software is being made available under the BSD |
---|
| 4 | # License, included below. This software may be subject to other third party |
---|
| 5 | # and contributor rights, including patent rights, and no such rights are |
---|
| 6 | # granted under this license. |
---|
| 7 | # |
---|
[595] | 8 | # Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[125] | 9 | # All rights reserved. |
---|
| 10 | # |
---|
| 11 | # Redistribution and use in source and binary forms, with or without |
---|
| 12 | # modification, are permitted provided that the following conditions are met: |
---|
| 13 | # |
---|
| 14 | # * Redistributions of source code must retain the above copyright notice, |
---|
| 15 | # this list of conditions and the following disclaimer. |
---|
| 16 | # * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 17 | # this list of conditions and the following disclaimer in the documentation |
---|
| 18 | # and/or other materials provided with the distribution. |
---|
| 19 | # * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 20 | # be used to endorse or promote products derived from this software without |
---|
| 21 | # specific prior written permission. |
---|
| 22 | # |
---|
| 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 24 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 25 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 26 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 27 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 28 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 29 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 30 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 31 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 32 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 33 | # THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 34 | |
---|
| 35 | # Outputs a command to run the encoder for a given set of arguments. The encoder typically requires a lot of arguments to run, so this script can be more convenient than running the encoder direcly because it automatically generates many of the arguments. |
---|
| 36 | |
---|
| 37 | # "Include" encode.shl which contains common shell script code related to encoding |
---|
| 38 | SUB_TOOLS_DIRECTORY=$(echo "$0" | sed -e 's/[^\/]*$//') |
---|
| 39 | . ${SUB_TOOLS_DIRECTORY}encode.shl |
---|
| 40 | |
---|
| 41 | USE_LOG_FILE_OPTION="-l" |
---|
| 42 | INPUT_DIRECTORY_OPTION="-id" |
---|
| 43 | NUM_FRAMES_OPTION="-f" |
---|
| 44 | |
---|
| 45 | function outputUsageAndExit { |
---|
| 46 | local EXECUTABLE_USAGE_STRING=executable |
---|
| 47 | local INPUT_DIRECTORY_USAGE_STRING=inputDirectory |
---|
| 48 | local CONFIGURATION_PATH_USAGE_STRING=configurationPath |
---|
| 49 | local CONFIGURATION_DIRECTORY_USAGE_STRING=configurationDirectory |
---|
| 50 | local NUM_FRAMES_USAGE_STRING=numFrames |
---|
| 51 | |
---|
| 52 | echo "Usage: $0 $CONFIGURATION_IDENTIFIER_OPTION $CONFIGURATION_IDENTIFIER_USAGE_STRING ($CONFIGURATION_PATH_OPTION $CONFIGURATION_PATH_USAGE_STRING -or- $CONFIGURATION_DIRECTORY_OPTION $CONFIGURATION_DIRECTORY_USAGE_STRING) $Q_OPTION $Q_USAGE_STRING $EXECUTABLE_OPTION $EXECUTABLE_USAGE_STRING [$NUM_FRAMES_OPTION $NUM_FRAMES_USAGE_STRING] [$EXTRA_ARGUMENTS_OPTION $EXTRA_ARGUMENTS_USAGE_STRING] $OUTPUT_DIRECTORY_OPTION $OUTPUT_DIRECTORY_USAGE_STRING [$USE_LOG_FILE_OPTION] [$INPUT_DIRECTORY_OPTION $INPUT_DIRECTORY_USAGE_STRING] $INPUT_NAME_USAGE_STRING" >&2 |
---|
| 53 | outputConfigurationIdentifierUsage |
---|
| 54 | echo "${USAGE_INDENT}$CONFIGURATION_PATH_USAGE_STRING is the path of the configuration file to use. Either this or $CONFIGURATION_DIRECTORY_USAGE_STRING must be specified (but not both)." >&2 |
---|
| 55 | echo "${USAGE_INDENT}$CONFIGURATION_DIRECTORY_USAGE_STRING is the path of the directory that contains the configuration files. The particular file will be chosen based on $CONFIGURATION_IDENTIFIER_USAGE_STRING. Either this or $CONFIGURATION_PATH_USAGE_STRING must be specified (but not both)." >&2 |
---|
| 56 | outputQUsage |
---|
| 57 | echo "${USAGE_INDENT}$EXECUTABLE_USAGE_STRING is the path of the encoder executable." >&2 |
---|
| 58 | echo "${USAGE_INDENT}$NUM_FRAMES_USAGE_STRING is the number of frames to encode. If omitted, the entire sequence will be encoded." >&2 |
---|
| 59 | echo "${USAGE_INDENT}$EXTRA_ARGUMENTS_USAGE_STRING is any extra arguments that should be passed on to the encoder." >&2 |
---|
| 60 | outputOutputDirectoryUsage |
---|
| 61 | echo "${USAGE_INDENT}If $USE_LOG_FILE_OPTION is specified, the encoder will output to a log file. Otherwise it will output to the standard output." >&2 |
---|
| 62 | echo "${USAGE_INDENT}$INPUT_DIRECTORY_USAGE_STRING is the directory that contains the sequences. The default value is the SEQUENCE_DIR environment variable." >&2 |
---|
| 63 | outputInputNameUsage |
---|
| 64 | |
---|
| 65 | exit 1 |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | # Used to lookup the width, height, number of frames, and frame rate for a given sequence |
---|
| 69 | table=`printf "${table}\nNebutaFestival_2560x1600_60_10bit_crop 2560 1600 300 60"` |
---|
| 70 | table=`printf "${table}\nSteamLocomotiveTrain_2560x1600_60_10bit_crop 2560 1600 300 60"` |
---|
| 71 | table=`printf "${table}\nTraffic_2560x1600_30_crop 2560 1600 150 30"` |
---|
| 72 | table=`printf "${table}\nPeopleOnStreet_2560x1600_30_crop 2560 1600 150 30"` |
---|
| 73 | table=`printf "${table}\nBQTerrace_1920x1080_60 1920 1080 600 60"` |
---|
| 74 | table=`printf "${table}\nBasketballDrive_1920x1080_50 1920 1080 500 50"` |
---|
| 75 | table=`printf "${table}\nCactus_1920x1080_50 1920 1080 500 50"` |
---|
| 76 | table=`printf "${table}\nKimono1_1920x1080_24 1920 1080 240 24"` |
---|
| 77 | table=`printf "${table}\nParkScene_1920x1080_24 1920 1080 240 24"` |
---|
| 78 | table=`printf "${table}\nvidyo1_720p_60 1280 720 600 60"` |
---|
| 79 | table=`printf "${table}\nvidyo3_720p_60 1280 720 600 60"` |
---|
| 80 | table=`printf "${table}\nvidyo4_720p_60 1280 720 600 60"` |
---|
| 81 | table=`printf "${table}\nRaceHorses_832x480_30 832 480 300 30"` |
---|
| 82 | table=`printf "${table}\nBQMall_832x480_60 832 480 600 60"` |
---|
| 83 | table=`printf "${table}\nPartyScene_832x480_50 832 480 500 50"` |
---|
| 84 | table=`printf "${table}\nBasketballDrill_832x480_50 832 480 500 50"` |
---|
| 85 | table=`printf "${table}\nRaceHorses_416x240_30 416 240 300 30"` |
---|
| 86 | table=`printf "${table}\nBQSquare_416x240_60 416 240 600 60"` |
---|
| 87 | table=`printf "${table}\nBlowingBubbles_416x240_50 416 240 500 50"` |
---|
| 88 | table=`printf "${table}\nBasketballPass_416x240_50 416 240 500 50"` |
---|
| 89 | table=`printf "${table}\nBasketballDrillText_832x480_50 832 480 500 50"` |
---|
| 90 | table=`printf "${table}\nChinaspeed_1024x768_30 1024 768 500 30"` |
---|
| 91 | table=`printf "${table}\nSlideEditing_1280x720_30 1280 720 300 30"` |
---|
| 92 | table=`printf "${table}\nSlideShow_1280x720_20 1280 720 500 20"` |
---|
| 93 | |
---|
| 94 | EXECUTABLE_STRING="executable ($EXECUTABLE_OPTION)" |
---|
| 95 | INPUT_DIRECTORY_STRING="input directory ($INPUT_DIRECTORY_OPTION)" |
---|
| 96 | CONFIGURATION_PATH_STRING="configuration path ($CONFIGURATION_PATH_OPTION)" |
---|
| 97 | CONFIGURATION_DIRECTORY_STRING="configuration directory ($CONFIGURATION_DIRECTORY_OPTION)" |
---|
| 98 | |
---|
| 99 | inputDirectory="$SEQUENCE_DIR" # The default input directory is taken from this environment variable |
---|
| 100 | |
---|
| 101 | # For every argument $1 |
---|
| 102 | while [ "" != "$*" ] ; do |
---|
| 103 | case $1 in |
---|
| 104 | $USE_LOG_FILE_OPTION) |
---|
| 105 | useLogFile=$1 |
---|
| 106 | ;; |
---|
| 107 | -*) |
---|
| 108 | checkDollarTwo "$1" "$2" |
---|
| 109 | case $1 in |
---|
| 110 | $EXECUTABLE_OPTION) executable=$2 ;; |
---|
| 111 | $INPUT_DIRECTORY_OPTION) inputDirectory=$2 ;; |
---|
| 112 | $EXTRA_ARGUMENTS_OPTION) extraArguments=$2 ;; |
---|
| 113 | $Q_OPTION) q=$2 ;; |
---|
| 114 | $OUTPUT_DIRECTORY_OPTION) outputDirectory=$2 ;; |
---|
| 115 | $CONFIGURATION_IDENTIFIER_OPTION) configurationIdentifier=$2 ;; |
---|
| 116 | $CONFIGURATION_PATH_OPTION) configurationPath=$2 ;; |
---|
| 117 | $CONFIGURATION_DIRECTORY_OPTION) configurationDirectory=$2 ;; |
---|
| 118 | $NUM_FRAMES_OPTION) numFrames=$2 ;; |
---|
| 119 | *) |
---|
| 120 | printf "You entered an invalid option: \"$1\".\n" >&2 |
---|
| 121 | outputUsageAndExit |
---|
| 122 | ;; |
---|
| 123 | esac |
---|
| 124 | shift |
---|
| 125 | ;; |
---|
| 126 | *) |
---|
| 127 | if [[ "" == $inputName ]] ; then |
---|
| 128 | inputName=$1 |
---|
| 129 | else |
---|
| 130 | printf "You entered too many arguments.\n" >&2 |
---|
| 131 | outputUsageAndExit |
---|
| 132 | fi |
---|
| 133 | ;; |
---|
| 134 | esac |
---|
| 135 | |
---|
| 136 | shift |
---|
| 137 | done |
---|
| 138 | |
---|
| 139 | verifyProvided "$EXECUTABLE_STRING" "$executable" |
---|
| 140 | verifyNotDirectory "$EXECUTABLE_STRING" "$executable" |
---|
| 141 | |
---|
| 142 | verifyDirectory "$INPUT_DIRECTORY_STRING" "$inputDirectory" |
---|
| 143 | |
---|
| 144 | verifyProvided "$Q_STRING" "$q" |
---|
| 145 | verifyQ $q |
---|
| 146 | |
---|
| 147 | verifyProvided "$OUTPUT_DIRECTORY_STRING" "$outputDirectory" |
---|
| 148 | verifyDirectory "$OUTPUT_DIRECTORY_STRING" "$outputDirectory" |
---|
| 149 | |
---|
| 150 | verifyProvided "$CONFIGURATION_IDENTIFIER_STRING" "$configurationIdentifier" |
---|
| 151 | verifyConfigurationIdentifier "$configurationIdentifier" |
---|
| 152 | |
---|
| 153 | # Validate $configurationPath or $configurationDirectory |
---|
| 154 | if [[ $configurationPath != "" ]] ; then |
---|
| 155 | verifyNotDirectory "$CONFIGURATION_PATH_STRING" "$configurationPath" |
---|
| 156 | else |
---|
| 157 | if [[ "" == $configurationDirectory ]] ; then |
---|
| 158 | printf "You must enter a $CONFIGURATION_PATH_STRING or $CONFIGURATION_DIRECTORY_STRING.\n" >&2 |
---|
| 159 | outputUsageAndExit |
---|
| 160 | else |
---|
| 161 | verifyDirectory "$CONFIGURATION_DIRECTORY_STRING" "$configurationDirectory" |
---|
| 162 | fi |
---|
| 163 | fi |
---|
| 164 | |
---|
| 165 | verifyProvided "$INPUT_NAME_STRING" "$inputName" |
---|
| 166 | verifyNotDirectory "$INPUT_NAME_STRING" "$inputName" |
---|
| 167 | |
---|
| 168 | # If configurationPath is not already populated, populate it based on the configuration directory and the configuration identifier |
---|
| 169 | if [[ "" == $configurationPath ]] ; then |
---|
| 170 | configurationPath="${configurationDirectory}encoder_" |
---|
| 171 | case $configurationIdentifier in |
---|
| 172 | ldLC) configurationPath="${configurationPath}lowdelay_loco" ;; |
---|
| 173 | raLC) configurationPath="${configurationPath}randomaccess_loco" ;; |
---|
| 174 | inLC) configurationPath="${configurationPath}intra_loco" ;; |
---|
| 175 | ldHE) configurationPath="${configurationPath}lowdelay" ;; |
---|
| 176 | raHE) configurationPath="${configurationPath}randomaccess" ;; |
---|
| 177 | *) configurationPath="${configurationPath}intra" ;; # inHE |
---|
| 178 | esac |
---|
| 179 | configurationPath="${configurationPath}.cfg" |
---|
| 180 | fi |
---|
| 181 | |
---|
| 182 | # Validate the input name and populate masterLine which contains the line from the table for the given sequence |
---|
| 183 | masterLine=`printf "$table" | grep -i "^$inputName "` |
---|
| 184 | if [[ "" == $masterLine ]] ; then |
---|
| 185 | printf "Invalid input name.\n" >&2 |
---|
| 186 | outputUsageAndExit |
---|
| 187 | fi |
---|
| 188 | |
---|
| 189 | # If numFrames is not yet initialized, initialize it by looking up the values in the table |
---|
| 190 | if [[ "" == $numFrames ]] ; then |
---|
| 191 | numFrames=`printf -- "$masterLine" | awk '{ print $4 }'` |
---|
| 192 | fi |
---|
| 193 | |
---|
| 194 | # Initialize these variables by looking up the values in the table |
---|
| 195 | frameRate=`printf -- "$masterLine" | awk '{ print $5 }'` |
---|
| 196 | width=`printf -- "$masterLine" | awk '{ print $2 }'` |
---|
| 197 | height=`printf -- "$masterLine" | awk '{ print $3 }'` |
---|
| 198 | |
---|
| 199 | # Initialize intraPeriod |
---|
| 200 | case $configurationIdentifier in |
---|
| 201 | ld*) |
---|
| 202 | intraPeriod="-1" |
---|
| 203 | ;; |
---|
| 204 | ra*) |
---|
| 205 | if [[ 20 == "$frameRate" ]] ; then |
---|
| 206 | intraPeriod="16" |
---|
| 207 | else |
---|
| 208 | intraPeriod=$(expr "$frameRate" + 4) |
---|
| 209 | intraPeriod=$(expr "$intraPeriod" / 8) |
---|
| 210 | intraPeriod=$(expr "$intraPeriod" \* 8) |
---|
| 211 | fi |
---|
| 212 | ;; |
---|
| 213 | in*) |
---|
| 214 | intraPeriod="1" |
---|
| 215 | ;; |
---|
| 216 | *) |
---|
| 217 | outputConfigurationIdentifierErrorAndExit |
---|
| 218 | ;; |
---|
| 219 | esac |
---|
| 220 | |
---|
| 221 | # Initialize tenBit if the given sequence is 10-bit |
---|
| 222 | printf -- "$inputName" | grep -i '10bit' > /dev/null |
---|
| 223 | case $? in |
---|
| 224 | 0) tenBit="--InputBitDepth=10 " |
---|
| 225 | ;; |
---|
| 226 | 1) ;; |
---|
| 227 | *) exit $? |
---|
| 228 | ;; |
---|
| 229 | esac |
---|
| 230 | |
---|
| 231 | outputPathBegin="${outputDirectory}${inputName}_${configurationIdentifier}_q${q}" |
---|
| 232 | |
---|
| 233 | # Output the command |
---|
| 234 | printf -- "$executable " |
---|
| 235 | printf -- "-c $configurationPath " |
---|
| 236 | printf -- "-i $inputDirectory$inputName.yuv " |
---|
| 237 | printf -- "-f $numFrames " |
---|
| 238 | printf -- "-fr $frameRate " |
---|
| 239 | printf -- "-wdt $width " |
---|
| 240 | printf -- "-hgt $height " |
---|
| 241 | printf -- "-ip $intraPeriod " |
---|
| 242 | printf -- "$tenBit" |
---|
| 243 | if [[ $tenBit != "" ]] ; then |
---|
| 244 | printf " " |
---|
| 245 | fi |
---|
| 246 | printf -- "$extraArguments" |
---|
| 247 | if [[ $extraArguments != "" ]] ; then |
---|
| 248 | printf -- " " |
---|
| 249 | fi |
---|
| 250 | printf -- "-q $q " |
---|
| 251 | printf -- "-b $outputPathBegin.bin " |
---|
| 252 | printf -- "-o $outputPathBegin.yuv " |
---|
| 253 | if [[ "" != $useLogFile ]] ; then |
---|
| 254 | printf -- "&> $outputPathBegin.log" |
---|
| 255 | fi |
---|
| 256 | printf "\n" |
---|
| 257 | |
---|
| 258 | exit 0 |
---|