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