fate-run.sh 11 KB

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