fate-run.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. #! /bin/sh
  2. export LC_ALL=C
  3. base=$(dirname $0)
  4. . "${base}/md5.sh"
  5. base64=tests/base64${HOSTEXECSUF}
  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. keep=${19:-0}
  25. outdir="tests/data/fate"
  26. outfile="${outdir}/${test}"
  27. errfile="${outdir}/${test}.err"
  28. cmpfile="${outdir}/${test}.diff"
  29. repfile="${outdir}/${test}.rep"
  30. case $threads in
  31. random*)
  32. threads_max=${threads#random}
  33. [ -z "$threads_max" ] && threads_max=16
  34. threads=$(awk "BEGIN { srand(); print 1+int(rand() * $threads_max) }" < /dev/null)
  35. ;;
  36. esac
  37. target_path(){
  38. test ${1} = ${1#/} && p=${target_path}/
  39. echo ${p}${1}
  40. }
  41. # $1=value1, $2=value2, $3=threshold
  42. # prints 0 if absolute difference between value1 and value2 is <= threshold
  43. compare(){
  44. awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
  45. }
  46. do_tiny_psnr(){
  47. psnr=$(tests/tiny_psnr${HOSTEXECSUF} "$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. oneoff(){
  65. do_tiny_psnr "$1" "$2" MAXDIFF
  66. }
  67. stddev(){
  68. do_tiny_psnr "$1" "$2" stddev
  69. }
  70. oneline(){
  71. printf '%s\n' "$1" | diff -u -b - "$2"
  72. }
  73. run(){
  74. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  75. $target_exec $target_path/"$@"
  76. }
  77. runecho(){
  78. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  79. $target_exec $target_path/"$@" >&3
  80. }
  81. probefmt(){
  82. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_entries format=format_name -print_format default=nw=1:nk=1 "$@"
  83. }
  84. probeaudiostream(){
  85. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_entries stream=codec_name,codec_time_base,sample_fmt,channels,channel_layout:side_data "$@"
  86. }
  87. probetags(){
  88. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_entries format_tags "$@"
  89. }
  90. runlocal(){
  91. test "${V:-0}" -gt 0 && echo ${base}/"$@" ${base} >&3
  92. ${base}/"$@" ${base}
  93. }
  94. probeframes(){
  95. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_frames "$@"
  96. }
  97. probechapters(){
  98. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_chapters "$@"
  99. }
  100. probegaplessinfo(){
  101. filename="$1"
  102. shift
  103. run ffprobe${PROGSUF}${EXECSUF} -bitexact -select_streams a -show_entries format=start_time,duration:stream=index,start_pts,duration_ts "$filename" "$@"
  104. pktfile1="${outdir}/${test}.pkts"
  105. framefile1="${outdir}/${test}.frames"
  106. cleanfiles="$cleanfiles $pktfile1 $framefile1"
  107. run ffprobe${PROGSUF}${EXECSUF} -bitexact -select_streams a -of compact -count_packets -show_entries packet=pts,dts,duration,flags:stream=nb_read_packets "$filename" "$@" > "$pktfile1"
  108. head -n 8 "$pktfile1"
  109. tail -n 9 "$pktfile1"
  110. run ffprobe${PROGSUF}${EXECSUF} -bitexact -select_streams a -of compact -count_frames -show_entries frame=pts,pkt_dts,best_effort_timestamp,pkt_duration,nb_samples:stream=nb_read_frames "$filename" "$@" > "$framefile1"
  111. head -n 8 "$framefile1"
  112. tail -n 9 "$framefile1"
  113. }
  114. ffmpeg(){
  115. dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
  116. ffmpeg_args="-nostdin -nostats -noauto_conversion_filters -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}${EXECSUF} ${ffmpeg_args}
  122. }
  123. ffprobe_demux(){
  124. filename=$1
  125. shift
  126. print_filename=$(basename "$filename")
  127. run ffprobe${PROGSUF}${EXECSUF} -print_filename "${print_filename}" \
  128. -of compact -bitexact -show_format -show_streams -show_packets \
  129. -show_data_hash CRC32 "$filename" "$@"
  130. }
  131. framecrc(){
  132. ffmpeg "$@" -bitexact -f framecrc -
  133. }
  134. ffmetadata(){
  135. ffmpeg "$@" -bitexact -f ffmetadata -
  136. }
  137. framemd5(){
  138. ffmpeg "$@" -bitexact -f framemd5 -
  139. }
  140. crc(){
  141. ffmpeg "$@" -f crc -
  142. }
  143. md5pipe(){
  144. ffmpeg "$@" md5:
  145. }
  146. md5(){
  147. encfile="${outdir}/${test}.out"
  148. cleanfiles="$cleanfiles $encfile"
  149. ffmpeg -y "$@" $(target_path $encfile) || return
  150. do_md5sum $encfile | awk '{print $1}'
  151. }
  152. pcm(){
  153. ffmpeg -auto_conversion_filters "$@" -vn -f s16le -
  154. }
  155. fmtstdout(){
  156. fmt=$1
  157. shift 1
  158. ffmpeg -bitexact "$@" -bitexact -f $fmt -
  159. }
  160. enc_dec_pcm(){
  161. out_fmt=$1
  162. dec_fmt=$2
  163. pcm_fmt=$3
  164. src_file=$(target_path $4)
  165. shift 4
  166. encfile="${outdir}/${test}.${out_fmt}"
  167. cleanfiles=$encfile
  168. encfile=$(target_path ${encfile})
  169. ffmpeg -auto_conversion_filters -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  170. ffmpeg -auto_conversion_filters -bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -fflags +bitexact -f ${dec_fmt} -
  171. }
  172. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  173. DEC_OPTS="-threads $threads -thread_type $thread_type -idct simple $FLAGS"
  174. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  175. enc_dec(){
  176. enc_fmt_in=$1
  177. srcfile=$2
  178. enc_fmt_out=$3
  179. enc_opt_out=$4
  180. dec_fmt_out=$5
  181. dec_opt_out=$6
  182. dec_opt_in=$7
  183. ffprobe_opts=$8
  184. twopass=$9
  185. encfile="${outdir}/${test}.${enc_fmt_out}"
  186. decfile="${outdir}/${test}.out.${dec_fmt_out}"
  187. cleanfiles="$cleanfiles $decfile"
  188. test "$keep" -ge 1 || cleanfiles="$cleanfiles $encfile"
  189. tsrcfile=$(target_path $srcfile)
  190. tencfile=$(target_path $encfile)
  191. tdecfile=$(target_path $decfile)
  192. if [ -n "$twopass" ]; then
  193. logfile_prefix="${outdir}/${test}.pass1"
  194. cleanfiles="$cleanfiles ${logfile_prefix}-0.log"
  195. tlogfile_prefix=$(target_path $logfile_prefix)
  196. ffmpeg -auto_conversion_filters -f $enc_fmt_in $DEC_OPTS -i $tsrcfile \
  197. $ENC_OPTS $enc_opt_out $FLAGS -pass 1 -passlogfile $tlogfile_prefix \
  198. -f $enc_fmt_out -y $tencfile || return
  199. enc_opt_out="$enc_opt_out -pass 2 -passlogfile $tlogfile_prefix"
  200. fi
  201. ffmpeg -auto_conversion_filters -f $enc_fmt_in $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt_out $FLAGS \
  202. -f $enc_fmt_out -y $tencfile || return
  203. do_md5sum $encfile
  204. echo $(wc -c $encfile)
  205. ffmpeg -auto_conversion_filters $dec_opt_in $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt_out $FLAGS \
  206. -f $dec_fmt_out -y $tdecfile || return
  207. do_md5sum $decfile
  208. tests/tiny_psnr${HOSTEXECSUF} $srcfile $decfile $cmp_unit $cmp_shift
  209. test -z $ffprobe_opts || \
  210. run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || return
  211. }
  212. transcode(){
  213. src_fmt=$1
  214. srcfile=$2
  215. enc_fmt=$3
  216. enc_opt=$4
  217. final_encode=$5
  218. ffprobe_opts=$6
  219. additional_input=$7
  220. final_decode=$8
  221. enc_opt_in=$9
  222. test -z "$additional_input" || additional_input="$DEC_OPTS $additional_input"
  223. encfile="${outdir}/${test}.${enc_fmt}"
  224. test $keep -ge 1 || cleanfiles="$cleanfiles $encfile"
  225. tsrcfile=$(target_path $srcfile)
  226. tencfile=$(target_path $encfile)
  227. ffmpeg -f $src_fmt $DEC_OPTS $enc_opt_in -i $tsrcfile $additional_input \
  228. $ENC_OPTS $enc_opt $FLAGS -f $enc_fmt -y $tencfile || return
  229. do_md5sum $encfile
  230. echo $(wc -c $encfile)
  231. ffmpeg $DEC_OPTS $final_decode -i $tencfile $ENC_OPTS $FLAGS $final_encode \
  232. -f framecrc - || return
  233. test -z $ffprobe_opts || \
  234. run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || return
  235. }
  236. stream_remux(){
  237. src_fmt=$1
  238. srcfile=$2
  239. src_opts=$3
  240. enc_fmt=$4
  241. stream_maps=$5
  242. final_decode=$6
  243. ffprobe_opts=$7
  244. encfile="${outdir}/${test}.${enc_fmt}"
  245. test $keep -ge 1 || cleanfiles="$cleanfiles $encfile"
  246. tsrcfile=$(target_path $srcfile)
  247. tencfile=$(target_path $encfile)
  248. ffmpeg -f $src_fmt $src_opts -i $tsrcfile $stream_maps -codec copy $FLAGS \
  249. -f $enc_fmt -y $tencfile || return
  250. ffmpeg $DEC_OPTS -i $tencfile $ENC_OPTS $FLAGS $final_decode \
  251. -f framecrc - || return
  252. test -z $ffprobe_opts || \
  253. run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || return
  254. }
  255. # this function is for testing external encoders,
  256. # where the precise output is not controlled by us
  257. # we can still test e.g. that the output can be decoded correctly
  258. enc_external(){
  259. srcfile=$1
  260. enc_fmt=$2
  261. enc_opt=$3
  262. probe_opt=$4
  263. srcfile=$(target_path $srcfile)
  264. encfile=$(target_path "${outdir}/${test}.${enc_fmt}")
  265. ffmpeg -i $srcfile $enc_opt -f $enc_fmt -y $encfile || return
  266. run ffprobe${PROGSUF}${EXECSUF} -bitexact $probe_opt $encfile || return
  267. }
  268. # FIXME: There is a certain duplication between the avconv-related helper
  269. # functions above and below that should be refactored.
  270. ffmpeg2="$target_exec ${target_path}/ffmpeg${PROGSUF}${EXECSUF}"
  271. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  272. pcm_src="${target_path}/tests/data/asynth1.sw"
  273. [ "${V-0}" -gt 0 ] && echov=echov || echov=:
  274. echov(){
  275. echo "$@" >&3
  276. }
  277. AVCONV_OPTS="-nostdin -nostats -noauto_conversion_filters -y -cpuflags $cpuflags -filter_threads $threads"
  278. COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  279. DEC_OPTS="$COMMON_OPTS -threads $threads"
  280. ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint"
  281. run_avconv(){
  282. $echov $ffmpeg2 $AVCONV_OPTS $*
  283. $ffmpeg2 $AVCONV_OPTS $*
  284. }
  285. do_avconv(){
  286. f="$1"
  287. shift
  288. set -- $* ${target_path}/$f
  289. run_avconv $*
  290. do_md5sum $f
  291. echo $(wc -c $f)
  292. }
  293. do_avconv_crc(){
  294. f="$1"
  295. shift
  296. printf "%s " "$f"
  297. run_avconv $* -f crc -
  298. }
  299. lavf_audio(){
  300. t="${test#lavf-}"
  301. outdir="tests/data/lavf"
  302. file=${outdir}/lavf.$t
  303. test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
  304. do_avconv $file -auto_conversion_filters $DEC_OPTS $1 -ar 44100 -f s16le -i $pcm_src "$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 $2
  305. test "$4" = "disable_crc" ||
  306. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS $3 -i $target_path/$file
  307. }
  308. lavf_container(){
  309. t="${test#lavf-}"
  310. outdir="tests/data/lavf"
  311. file=${outdir}/lavf.$t
  312. test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
  313. do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le $1 -i $pcm_src "$ENC_OPTS -metadata title=lavftest" -b:a 64k -t 1 -qscale:v 10 $2
  314. test "$3" = "disable_crc" ||
  315. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $3
  316. }
  317. lavf_container_attach() { lavf_container "" "$1 -attach ${raw_src%/*}/00.pgm -metadata:s:t mimetype=image/x-portable-greymap"; }
  318. lavf_container_timecode_nodrop() { lavf_container "" "$1 -timecode 02:56:14:13"; }
  319. lavf_container_timecode_drop() { lavf_container "" "$1 -timecode 02:56:14.13 -r 30000/1001"; }
  320. lavf_container_timecode()
  321. {
  322. lavf_container_timecode_nodrop "$@"
  323. lavf_container_timecode_drop "$@"
  324. lavf_container "" "$1"
  325. }
  326. lavf_container_fate()
  327. {
  328. t="${test#lavf-fate-}"
  329. outdir="tests/data/lavf-fate"
  330. file=${outdir}/lavf.$t
  331. cleanfiles="$cleanfiles $file"
  332. input="${target_samples}/$1"
  333. do_avconv $file -auto_conversion_filters $DEC_OPTS $2 -i "$input" "$ENC_OPTS -metadata title=lavftest" -vcodec copy -acodec copy
  334. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $3
  335. }
  336. lavf_image(){
  337. no_file_checksums="$3"
  338. nb_frames=13
  339. t="${test#lavf-}"
  340. outdir="tests/data/images/$t"
  341. mkdir -p "$outdir"
  342. file=${outdir}/%02d.$t
  343. if [ "$keep" -lt 1 ]; then
  344. for i in `seq $nb_frames`; do
  345. filename=`printf "$file" $i`
  346. cleanfiles="$cleanfiles $filename"
  347. done
  348. fi
  349. run_avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $1 "$ENC_OPTS -metadata title=lavftest" -vf scale -frames $nb_frames -y -qscale 10 $target_path/$file
  350. if [ -z "$no_file_checksums" ]; then
  351. do_md5sum ${outdir}/02.$t
  352. echo $(wc -c ${outdir}/02.$t)
  353. fi
  354. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS $2 -i $target_path/$file $2
  355. }
  356. lavf_image2pipe(){
  357. t="${test#lavf-}"
  358. t="${t%pipe}"
  359. outdir="tests/data/lavf"
  360. file=${outdir}/${t}pipe.$t
  361. do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src -f image2pipe "$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10
  362. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -f image2pipe -i $target_path/$file
  363. }
  364. lavf_video(){
  365. t="${test#lavf-}"
  366. outdir="tests/data/lavf"
  367. file=${outdir}/lavf.$t
  368. test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
  369. do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src "$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 $1 $2
  370. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $1
  371. }
  372. refcmp_metadata(){
  373. refcmp=$1
  374. pixfmt=$2
  375. fuzz=${3:-0.001}
  376. ffmpeg -auto_conversion_filters $FLAGS $ENC_OPTS \
  377. -lavfi "testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},split[ref][tmp];[tmp]avgblur=4[enc];[enc][ref]${refcmp},metadata=print:file=-" \
  378. -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
  379. }
  380. cmp_metadata(){
  381. refcmp=$1
  382. pixfmt=$2
  383. fuzz=${3:-0.001}
  384. ffmpeg $FLAGS $ENC_OPTS \
  385. -lavfi "testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},${refcmp},metadata=print:file=-" \
  386. -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
  387. }
  388. refcmp_metadata_files(){
  389. file1=$1
  390. file2=$2
  391. refcmp=$3
  392. pixfmt=$4
  393. fuzz=${5:-0.001}
  394. ffmpeg -auto_conversion_filters $FLAGS -i $file1 $FLAGS -i $file2 $ENC_OPTS \
  395. -lavfi "[0:v]format=${pixfmt}[v0];[1:v]format=${pixfmt}[v1];[v0][v1]${refcmp},metadata=print:file=-" \
  396. -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
  397. }
  398. refcmp_metadata_transcode(){
  399. srcfile=$1
  400. enc_opt=$2
  401. enc_fmt=$3
  402. enc_ext=$4
  403. shift 4
  404. encfile="${outdir}/${test}.${enc_ext}"
  405. cleanfiles="$cleanfiles $encfile"
  406. tsrcfile=$(target_path $srcfile)
  407. tencfile=$(target_path $encfile)
  408. ffmpeg $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS -y -f $enc_fmt $tencfile || return
  409. refcmp_metadata_files $tencfile $tsrcfile "$@"
  410. }
  411. pixfmt_conversion(){
  412. conversion="${test#pixfmt-}"
  413. outdir="tests/data/pixfmt"
  414. raw_dst="$outdir/$conversion.out.yuv"
  415. file=${outdir}/${conversion}.yuv
  416. cleanfiles="$cleanfiles $raw_dst $file"
  417. run_avconv $DEC_OPTS -r 1 -f image2 -c:v pgmyuv -i $raw_src \
  418. $ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $conversion $target_path/$raw_dst
  419. do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $conversion -i $target_path/$raw_dst \
  420. $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p
  421. }
  422. video_filter(){
  423. filters=$1
  424. shift
  425. label=${test#filter-}
  426. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  427. printf '%-20s' $label
  428. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  429. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
  430. }
  431. pixfmts(){
  432. filter=${test#filter-pixfmts-}
  433. filter=${filter%_*}
  434. filter_args=$1
  435. prefilter_chain=$2
  436. nframes=${3:-1}
  437. showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts${EXECSUF}"
  438. scale_exclude_fmts=${outfile}_scale_exclude_fmts
  439. scale_in_fmts=${outfile}_scale_in_fmts
  440. scale_out_fmts=${outfile}_scale_out_fmts
  441. in_fmts=${outfile}_in_fmts
  442. # exclude pixel formats which are not supported as input
  443. $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  444. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  445. comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  446. $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  447. pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  448. outertest=$test
  449. for pix_fmt in $pix_fmts; do
  450. test=$pix_fmt
  451. video_filter "${prefilter_chain}scale,format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes
  452. done
  453. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  454. test=$outertest
  455. }
  456. gapless(){
  457. sample=$(target_path $1)
  458. extra_args=$2
  459. decfile1="${outdir}/${test}.out-1"
  460. decfile2="${outdir}/${test}.out-2"
  461. decfile3="${outdir}/${test}.out-3"
  462. cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
  463. # test packet data
  464. ffmpeg -auto_conversion_filters $extra_args -i "$sample" -bitexact -c:a copy -f framecrc -y $(target_path $decfile1)
  465. do_md5sum $decfile1
  466. # test decoded (and cut) data
  467. ffmpeg -auto_conversion_filters $extra_args -i "$sample" -bitexact -f wav md5:
  468. # the same as above again, with seeking to the start
  469. ffmpeg -auto_conversion_filters $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -bitexact -c:a copy -f framecrc -y $(target_path $decfile2)
  470. do_md5sum $decfile2
  471. ffmpeg -auto_conversion_filters $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -bitexact -f wav md5:
  472. # test packet data, with seeking to a specific position
  473. ffmpeg -auto_conversion_filters $extra_args -ss 5 -seek_timestamp 1 -i "$sample" -bitexact -c:a copy -f framecrc -y $(target_path $decfile3)
  474. do_md5sum $decfile3
  475. }
  476. gaplessenc(){
  477. sample=$(target_path $1)
  478. format=$2
  479. codec=$3
  480. file1="${outdir}/${test}.out-1"
  481. cleanfiles="$cleanfiles $file1"
  482. # test data after reencoding
  483. ffmpeg -i "$sample" -bitexact -map 0:a -c:a $codec -af aresample -f $format -y "$(target_path "$file1")"
  484. probegaplessinfo "$(target_path "$file1")"
  485. }
  486. audio_match(){
  487. sample=$(target_path $1)
  488. trefile=$2
  489. extra_args=$3
  490. decfile="${outdir}/${test}.wav"
  491. cleanfiles="$cleanfiles $decfile"
  492. ffmpeg -auto_conversion_filters -i "$sample" -bitexact $extra_args -y $(target_path $decfile)
  493. tests/audiomatch${HOSTEXECSUF} $decfile $trefile
  494. }
  495. concat(){
  496. template=$1
  497. sample=$2
  498. mode=$3
  499. extra_args=$4
  500. concatfile="${outdir}/${test}.ffconcat"
  501. packetfile="${outdir}/${test}.ffprobe"
  502. cleanfiles="$concatfile $packetfile"
  503. awk "{gsub(/%SRCFILE%/, \"$sample\"); print}" $template > $concatfile
  504. if [ "$mode" = "md5" ]; then
  505. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_streams -show_packets -safe 0 $extra_args $(target_path $concatfile) | tr -d '\r' > $packetfile
  506. do_md5sum $packetfile
  507. else
  508. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_streams -show_packets -of compact=p=0:nk=1 -safe 0 $extra_args $(target_path $concatfile)
  509. fi
  510. }
  511. venc_data(){
  512. file=$1
  513. stream=$2
  514. frames=$3
  515. run tools/venc_data_dump${EXECSUF} ${file} ${stream} ${frames} ${threads} ${thread_type}
  516. }
  517. null(){
  518. :
  519. }
  520. # Disable globbing: command arguments may contain globbing characters and
  521. # must be kept verbatim
  522. set -f
  523. exec 3>&2
  524. eval $command >"$outfile" 2>$errfile
  525. err=$?
  526. if [ $err -gt 128 ]; then
  527. sig=$(kill -l $err 2>/dev/null)
  528. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  529. fi
  530. if test -e "$ref" || test $cmp = "oneline" || test $cmp = "null" || test $cmp = "grep" ; then
  531. case $cmp in
  532. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  533. rawdiff)diff -u "$ref" "$outfile" >$cmpfile ;;
  534. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  535. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  536. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  537. grep) grep "$ref" "$errfile" >$cmpfile ;;
  538. null) cat "$outfile" >$cmpfile ;;
  539. esac
  540. cmperr=$?
  541. test $err = 0 && err=$cmperr
  542. if [ "$report_type" = "ignore" ]; then
  543. test $err = 0 || echo "IGNORE\t${test}" && err=0 && unset sig
  544. else
  545. test $err = 0 || cat $cmpfile
  546. fi
  547. else
  548. echo "reference file '$ref' not found"
  549. err=1
  550. fi
  551. if [ $err -eq 0 ] && test $report_type = "standard" ; then
  552. unset cmpo erro
  553. else
  554. echo "threads=$threads" >> "$errfile"
  555. cmpo="$($base64 <$cmpfile)"
  556. erro="$($base64 <$errfile)"
  557. fi
  558. echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
  559. if test $err != 0 && test $gen != "no" ; then
  560. echo "GEN $ref"
  561. cp -f "$outfile" "$ref"
  562. err=$?
  563. fi
  564. if test $err = 0; then
  565. if test $keep -lt 2; then
  566. rm -f $outfile $errfile $cmpfile $cleanfiles
  567. fi
  568. elif test $gen = "no"; then
  569. echo "Test $test failed. Look at $errfile for details."
  570. test "${V:-0}" -gt 0 && cat $errfile
  571. else
  572. echo "Updating reference failed, possibly no output file was generated."
  573. fi
  574. exit $err