]> git.sesse.net Git - ffmpeg/blob - tests/fate-run.sh
avformat/rtpdec_jpeg: fix low contrast image on low quality setting
[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 target_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) || return 1
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         if [ "$val_cmp" != 0 ]; then
55             echo "$3: |$val - $cmp_target| >= $fuzz"
56         fi
57         if [ "$size_cmp" != 0 ]; then
58             echo "size: |$size1 - $size2| >= $size_tolerance"
59         fi
60         return 1
61     fi
62 }
63
64 oneoff(){
65     do_tiny_psnr "$1" "$2" MAXDIFF
66 }
67
68 stddev(){
69     do_tiny_psnr "$1" "$2" stddev
70 }
71
72 oneline(){
73     printf '%s\n' "$1" | diff -u -b - "$2"
74 }
75
76 run(){
77     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
78     $target_exec $target_path/"$@"
79 }
80
81 runecho(){
82     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
83     $target_exec $target_path/"$@" >&3
84 }
85
86 probefmt(){
87     run ffprobe${PROGSUF} -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
88 }
89
90 runlocal(){
91     test "${V:-0}" -gt 0 && echo ${base}/"$@" ${base} >&3
92     ${base}/"$@" ${base}
93 }
94
95 probeframes(){
96     run ffprobe${PROGSUF} -show_frames -v 0 "$@"
97 }
98
99 probegaplessinfo(){
100     filename="$1"
101     shift
102     run ffprobe${PROGSUF} -bitexact -select_streams a -show_entries format=start_time,duration:stream=index,start_pts,duration_ts -v 0 "$filename" "$@"
103     pktfile1="${outdir}/${test}.pkts"
104     framefile1="${outdir}/${test}.frames"
105     cleanfiles="$cleanfiles $pktfile1 $framefile1"
106     run ffprobe${PROGSUF} -bitexact -select_streams a -of compact -count_packets -show_entries packet=pts,dts,duration:stream=nb_read_packets -v 0 "$filename" "$@" > "$pktfile1"
107     head -n 8 "$pktfile1"
108     tail -n 9 "$pktfile1"
109     run ffprobe${PROGSUF} -bitexact -select_streams a -of compact -count_frames -show_entries frame=pkt_pts,pkt_dts,best_effort_timestamp,pkt_duration,nb_samples:stream=nb_read_frames -v 0 "$filename" "$@" > "$framefile1"
110     head -n 8 "$framefile1"
111     tail -n 9 "$framefile1"
112 }
113
114 ffmpeg(){
115     dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
116     ffmpeg_args="-nostdin -nostats -cpuflags $cpuflags"
117     for arg in $@; do
118         [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
119         ffmpeg_args="${ffmpeg_args} ${arg}"
120     done
121     run ffmpeg${PROGSUF} ${ffmpeg_args}
122 }
123
124 framecrc(){
125     ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framecrc -
126 }
127
128 framemd5(){
129     ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framemd5 -
130 }
131
132 crc(){
133     ffmpeg "$@" -f crc -
134 }
135
136 md5(){
137     ffmpeg "$@" md5:
138 }
139
140 pcm(){
141     ffmpeg "$@" -vn -f s16le -
142 }
143
144 fmtstdout(){
145     fmt=$1
146     shift 1
147     ffmpeg -flags +bitexact -fflags +bitexact "$@" -f $fmt -
148 }
149
150 enc_dec_pcm(){
151     out_fmt=$1
152     dec_fmt=$2
153     pcm_fmt=$3
154     src_file=$(target_path $4)
155     shift 4
156     encfile="${outdir}/${test}.${out_fmt}"
157     cleanfiles=$encfile
158     encfile=$(target_path ${encfile})
159     ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
160     ffmpeg -flags +bitexact -fflags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -fflags +bitexact -f ${dec_fmt} -
161 }
162
163 FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
164 DEC_OPTS="-threads $threads -idct simple $FLAGS"
165 ENC_OPTS="-threads 1        -idct simple -dct fastint"
166
167 enc_dec(){
168     src_fmt=$1
169     srcfile=$2
170     enc_fmt=$3
171     enc_opt=$4
172     dec_fmt=$5
173     dec_opt=$6
174     encfile="${outdir}/${test}.${enc_fmt}"
175     decfile="${outdir}/${test}.out.${dec_fmt}"
176     cleanfiles="$cleanfiles $decfile"
177     test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
178     tsrcfile=$(target_path $srcfile)
179     tencfile=$(target_path $encfile)
180     tdecfile=$(target_path $decfile)
181     ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
182         -f $enc_fmt -y $tencfile || return
183     do_md5sum $encfile
184     echo $(wc -c $encfile)
185     ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
186         -f $dec_fmt -y $tdecfile || return
187     do_md5sum $decfile
188     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
189 }
190
191 lavffatetest(){
192     t="${test#lavf-fate-}"
193     ref=${base}/ref/lavf-fate/$t
194     ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
195 }
196
197 lavftest(){
198     t="${test#lavf-}"
199     ref=${base}/ref/lavf/$t
200     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
201 }
202
203 video_filter(){
204     filters=$1
205     shift
206     label=${test#filter-}
207     raw_src="${target_path}/tests/vsynth1/%02d.pgm"
208     printf '%-20s' $label
209     ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
210         $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
211 }
212
213 pixfmts(){
214     filter=${test#filter-pixfmts-}
215     filter=${filter%_*}
216     filter_args=$1
217     prefilter_chain=$2
218     nframes=${3:-1}
219
220     showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
221     scale_exclude_fmts=${outfile}_scale_exclude_fmts
222     scale_in_fmts=${outfile}_scale_in_fmts
223     scale_out_fmts=${outfile}_scale_out_fmts
224     in_fmts=${outfile}_in_fmts
225
226     # exclude pixel formats which are not supported as input
227     $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
228     $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
229     comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
230
231     $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
232     pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
233
234     outertest=$test
235     for pix_fmt in $pix_fmts; do
236         test=$pix_fmt
237         video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes
238     done
239
240     rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
241     test=$outertest
242 }
243
244 gapless(){
245     sample=$(target_path $1)
246     extra_args=$2
247
248     decfile1="${outdir}/${test}.out-1"
249     decfile2="${outdir}/${test}.out-2"
250     decfile3="${outdir}/${test}.out-3"
251     cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
252
253     # test packet data
254     ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile1
255     do_md5sum $decfile1
256     # test decoded (and cut) data
257     ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
258     # the same as above again, with seeking to the start
259     ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile2
260     do_md5sum $decfile2
261     ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
262     # test packet data, with seeking to a specific position
263     ffmpeg $extra_args -ss 5 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile3
264     do_md5sum $decfile3
265 }
266
267 gaplessenc(){
268     sample=$(target_path $1)
269     format=$2
270     codec=$3
271
272     file1="${outdir}/${test}.out-1"
273     cleanfiles="$cleanfiles $file1"
274
275     # test data after reencoding
276     ffmpeg -i "$sample" -flags +bitexact -fflags +bitexact -map 0:a -c:a $codec -f $format -y "$file1"
277     probegaplessinfo "$file1"
278 }
279
280 audio_match(){
281     sample=$(target_path $1)
282     trefile=$(target_path $2)
283     extra_args=$3
284
285     decfile="${outdir}/${test}.wav"
286     cleanfiles="$cleanfiles $decfile"
287
288     ffmpeg -i "$sample" -flags +bitexact -fflags +bitexact $extra_args -y $decfile
289     tests/audiomatch $decfile $trefile
290 }
291
292 concat(){
293     template=$1
294     sample=$2
295     mode=$3
296     extra_args=$4
297
298     concatfile="${outdir}/${test}.ffconcat"
299     packetfile="${outdir}/${test}.ffprobe"
300     cleanfiles="$concatfile $packetfile"
301
302     awk "{gsub(/%SRCFILE%/, \"$sample\"); print}" $template > $concatfile
303
304     if [ "$mode" = "md5" ]; then
305         run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -fflags keepside -safe 0 $extra_args $concatfile | tr -d '\r' > $packetfile
306         do_md5sum $packetfile
307     else
308         run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -of compact=p=0:nk=1 -fflags keepside -safe 0 $extra_args $concatfile
309     fi
310 }
311
312 mkdir -p "$outdir"
313
314 # Disable globbing: command arguments may contain globbing characters and
315 # must be kept verbatim
316 set -f
317
318 exec 3>&2
319 eval $command >"$outfile" 2>$errfile
320 err=$?
321
322 if [ $err -gt 128 ]; then
323     sig=$(kill -l $err 2>/dev/null)
324     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
325 fi
326
327 if test -e "$ref" || test $cmp = "oneline" ; then
328     case $cmp in
329         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
330         rawdiff)diff -u    "$ref" "$outfile"            >$cmpfile ;;
331         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
332         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
333         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
334         null)   cat               "$outfile"            >$cmpfile ;;
335     esac
336     cmperr=$?
337     test $err = 0 && err=$cmperr
338     test $err = 0 || cat $cmpfile
339 else
340     echo "reference file '$ref' not found"
341     err=1
342 fi
343
344 if [ $err -eq 0 ]; then
345     unset cmpo erro
346 else
347     cmpo="$($base64 <$cmpfile)"
348     erro="$($base64 <$errfile)"
349 fi
350 echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
351
352 if test $err != 0 && test $gen != "no" ; then
353     echo "GEN     $ref"
354     cp -f "$outfile" "$ref"
355     err=$?
356 fi
357
358 if test $err = 0; then
359     rm -f $outfile $errfile $cmpfile $cleanfiles
360 elif test $gen = "no"; then
361     echo "Test $test failed. Look at $errfile for details."
362     test "${V:-0}" -gt 0 && cat $errfile
363 else
364     echo "Updating reference failed, possibly no output file was generated."
365 fi
366 exit $err