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