#!/bin/bash # Set default options to be overriden by command line arguments. w=400 h=325 rate=50 TEMPDIR= unset remove_tempdir interlaced= aspect_ratio= bitrate= while getopts ":w:h:t:r:ia:b:" opt; do case $opt in w) w=$OPTARG ;; h) h=$OPTARG ;; t) TEMPDIR=$OPTARG ;; r) rate=$OPTARG ;; i) interlaced=TRUE ;; a) aspect_ratio=$OPTARG ;; b) bitrate=$OPTARG ;; \?) echo -n "\ Error: Invalid option -$OPTARG Usage: test_pattern.bash [options] -w width The width in pixels. -h height The height in pixels. -t tempdir Temporary directory for intermediate files. If no directory is specified, one is created and deleted at the end of processing. -r fieldrate -i Generate an interlaced test pattern -a n:m Aspect ratio of generated video. -b bitrate Bitrate used for encoding. Example: test_pattern.bash -w 1440 -h 1080 -t temp -r 50 -i -a 16:9 -b 12000k " exit 1 esac done if [ -z "$aspect_ratio" ] ; then aspect_ratio="${w}:${h}" fi aspectx=$(echo $aspect_ratio | cut -d: -f1) aspecty=$(echo $aspect_ratio | cut -d: -f2) # Calculate some dimensions based on the requested size. barw=$((w/32)) barstep=$((w/90)) barstart=$((-barw/barstep-1)) frames=$((w/2)) unity=$((h*2/27)) unitx=$((unity*aspecty*w/(aspectx*h))) gridlw=$((unity*3/43)) echo unity=$unity echo unitx=$unitx nvgrid=$(((h-gridlw)/unity)) nhgrid=$(((((w-gridlw)/unitx)-1)/2*2+1)) gridstartx=$((w/2-(nhgrid*unitx+gridlw)/2-1)) gridstarty=$((h/2-(nvgrid*unity+gridlw)/2-1)) echo nvgrid=$nvgrid echo nhgrid=$nhgrid echo gridstartx=$gridstartx echo gridstarty=$gridstarty echo parsed tempdir $TEMPDIR if [ -z "$TEMPDIR" ] ; then TEMPDIR=$(mktemp -d --tmpdir=/tmp) remove_tempdir=1 else if [ ! -d "$TEMPDIR" ] ; then mkdir $TEMPDIR fi fi echo parsed tempdir $TEMPDIR $remove_tempdir unset checker checker=( -fill "rgb(192,192,192)" ) for ((g=-9;g<=7;g=g+2)) ; do checker=( "${checker[@]}" -draw "rectangle $((w/2+g*unitx*7/10)),$((gridstarty+unity*3+gridlw)) $((w/2+(g+1)*unitx*7/10)),$((gridstarty+unity*4+gridlw))" ) done checker=( "${checker[@]}" -fill black ) for ((g=-8;g<=8;g=g+2)) ; do checker=( "${checker[@]}" -draw "rectangle $((w/2+g*unitx*7/10)),$((gridstarty+unity*3+gridlw)) $((w/2+(g+1)*unitx*7/10)),$((gridstarty+unity*4+gridlw))" ) done unset stripe stripe=( -fill white ) for ((g=0;g<5;g++)) ; do startx=$((w/2+(3-g*2)*unitx)) endx=$((startx+2*unitx)) for ((x=startx;x