You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

439 lines
12KB

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