]> git.sesse.net Git - ffmpeg/blob - tests/fate-run.sh
fate: Reduce the number of frames used to test video filters
[ffmpeg] / tests / fate-run.sh
1 #! /bin/sh
2
3 export LC_ALL=C
4
5 base=$(dirname $0)
6 . "${base}/md5.sh"
7
8 base64=tests/base64
9
10 test="${1#fate-}"
11 samples=$2
12 target_exec=$3
13 target_path=$4
14 command=$5
15 cmp=${6:-diff}
16 ref=${7:-"${base}/ref/fate/${test}"}
17 fuzz=${8:-1}
18 threads=${9:-1}
19 thread_type=${10:-frame+slice}
20 cpuflags=${11:-all}
21 cmp_shift=${12:-0}
22 cmp_target=${13:-0}
23 size_tolerance=${14:-0}
24 cmp_unit=${15:-2}
25 gen=${16:-no}
26 hwaccel=${17:-none}
27
28 outdir="tests/data/fate"
29 outfile="${outdir}/${test}"
30 errfile="${outdir}/${test}.err"
31 cmpfile="${outdir}/${test}.diff"
32 repfile="${outdir}/${test}.rep"
33
34 target_path(){
35     test ${1} = ${1#/} && p=${target_path}/
36     echo ${p}${1}
37 }
38
39 # $1=value1, $2=value2, $3=threshold
40 # prints 0 if absolute difference between value1 and value2 is <= threshold
41 compare(){
42     awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
43 }
44
45 do_tiny_psnr(){
46     psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
47     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
48     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
49     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
50     val_cmp=$(compare $val $cmp_target $fuzz)
51     size_cmp=$(compare $size1 $size2 $size_tolerance)
52     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
53         echo "$psnr"
54         return 1
55     fi
56 }
57
58 oneoff(){
59     do_tiny_psnr "$1" "$2" MAXDIFF
60 }
61
62 stddev(){
63     do_tiny_psnr "$1" "$2" stddev
64 }
65
66 oneline(){
67     printf '%s\n' "$1" | diff -u -b - "$2"
68 }
69
70 run(){
71     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
72     $target_exec $target_path/"$@"
73 }
74
75 probefmt(){
76     run avprobe -show_format_entry format_name -v 0 "$@"
77 }
78
79 avconv(){
80     dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
81     avconv_args="-nostats -cpuflags $cpuflags"
82     for arg in $@; do
83         [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
84         avconv_args="${avconv_args} ${arg}"
85     done
86     run avconv ${avconv_args}
87 }
88
89 framecrc(){
90     avconv "$@" -f framecrc -
91 }
92
93 framemd5(){
94     avconv "$@" -f framemd5 -
95 }
96
97 crc(){
98     avconv "$@" -f crc -
99 }
100
101 md5(){
102     avconv "$@" md5:
103 }
104
105 pcm(){
106     avconv "$@" -vn -f s16le -
107 }
108
109 enc_dec_pcm(){
110     out_fmt=$1
111     dec_fmt=$2
112     pcm_fmt=$3
113     src_file=$(target_path $4)
114     shift 4
115     encfile="${outdir}/${test}.${out_fmt}"
116     cleanfiles=$encfile
117     encfile=$(target_path ${encfile})
118     avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
119     avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
120 }
121
122 FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
123 DEC_OPTS="-threads $threads -idct simple $FLAGS"
124 ENC_OPTS="-threads 1        -idct simple -dct fastint"
125
126 enc_dec(){
127     src_fmt=$1
128     srcfile=$2
129     enc_fmt=$3
130     enc_opt=$4
131     dec_fmt=$5
132     dec_opt=$6
133     encfile="${outdir}/${test}.${enc_fmt}"
134     decfile="${outdir}/${test}.out.${dec_fmt}"
135     cleanfiles="$cleanfiles $decfile"
136     test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
137     tsrcfile=$(target_path $srcfile)
138     tencfile=$(target_path $encfile)
139     tdecfile=$(target_path $decfile)
140     avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
141         -f $enc_fmt -y $tencfile || return
142     do_md5sum $encfile
143     echo $(wc -c $encfile)
144     avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
145         -f $dec_fmt -y $tdecfile || return
146     do_md5sum $decfile
147     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
148 }
149
150 lavftest(){
151     t="${test#lavf-}"
152     ref=${base}/ref/lavf/$t
153     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
154 }
155
156 video_filter(){
157     filters=$1
158     shift
159     label=${test#filter-}
160     raw_src="${target_path}/tests/vsynth1/%02d.pgm"
161     printf '%-20s' $label
162     avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
163         $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
164 }
165
166 pixfmts(){
167     filter=${test#filter-pixfmts-}
168     filter_args=$1
169
170     showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
171     exclude_fmts=${outfile}${filter}_exclude_fmts
172     out_fmts=${outfile}${filter}_out_fmts
173
174     # exclude pixel formats which are not supported as input
175     avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
176     $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
177
178     pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
179
180     outertest=$test
181     for pix_fmt in $pix_fmts; do
182         test=$pix_fmt
183         video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v 1
184     done
185
186     rm $exclude_fmts $out_fmts
187     test=$outertest
188 }
189
190 mkdir -p "$outdir"
191
192 exec 3>&2
193 eval $command >"$outfile" 2>$errfile
194 err=$?
195
196 if [ $err -gt 128 ]; then
197     sig=$(kill -l $err 2>/dev/null)
198     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
199 fi
200
201 if test -e "$ref" || test $cmp = "oneline" ; then
202     case $cmp in
203         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
204         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
205         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
206         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
207         null)   cat               "$outfile"            >$cmpfile ;;
208     esac
209     cmperr=$?
210     test $err = 0 && err=$cmperr
211     test $err = 0 || cat $cmpfile
212 else
213     echo "reference file '$ref' not found"
214     err=1
215 fi
216
217 if [ $err -eq 0 ]; then
218     unset cmpo erro
219 else
220     cmpo="$($base64 <$cmpfile)"
221     erro="$($base64 <$errfile)"
222 fi
223 echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
224
225 if test $err != 0 && test $gen != "no" ; then
226     echo "GEN     $ref"
227     cp -f "$outfile" "$ref"
228     err=$?
229 fi
230
231 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
232 exit $err