fate-run.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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_demux(){
  237. src_fmt=$1
  238. srcfile=$2
  239. src_opts=$3
  240. enc_opts=$4
  241. ffprobe_opts=$5
  242. tsrcfile=$(target_path $srcfile)
  243. ffmpeg $DEC_OPTS -f $src_fmt $src_opts -i $tsrcfile $ENC_OPTS $FLAGS $enc_opts \
  244. -f framecrc - || return
  245. test -z "$ffprobe_opts" || \
  246. run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tsrcfile || return
  247. }
  248. stream_remux(){
  249. src_fmt=$1
  250. srcfile=$2
  251. src_opts=$3
  252. enc_fmt=$4
  253. stream_maps=$5
  254. final_decode=$6
  255. final_encode=$7
  256. ffprobe_opts=$8
  257. encfile="${outdir}/${test}.${enc_fmt}"
  258. test $keep -ge 1 || cleanfiles="$cleanfiles $encfile"
  259. tsrcfile=$(target_path $srcfile)
  260. tencfile=$(target_path $encfile)
  261. ffmpeg -f $src_fmt $src_opts -i $tsrcfile $stream_maps -codec copy $FLAGS \
  262. -f $enc_fmt -y $tencfile || return
  263. ffmpeg $DEC_OPTS $final_decode -i $tencfile $ENC_OPTS $FLAGS $final_encode \
  264. -f framecrc - || return
  265. test -z "$ffprobe_opts" || \
  266. run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || return
  267. }
  268. # this function is for testing external encoders,
  269. # where the precise output is not controlled by us
  270. # we can still test e.g. that the output can be decoded correctly
  271. enc_external(){
  272. srcfile=$1
  273. enc_fmt=$2
  274. enc_opt=$3
  275. probe_opt=$4
  276. srcfile=$(target_path $srcfile)
  277. encfile=$(target_path "${outdir}/${test}.${enc_fmt}")
  278. ffmpeg -i $srcfile $enc_opt -f $enc_fmt -y $encfile || return
  279. run ffprobe${PROGSUF}${EXECSUF} -bitexact $probe_opt $encfile || return
  280. }
  281. # FIXME: There is a certain duplication between the avconv-related helper
  282. # functions above and below that should be refactored.
  283. ffmpeg2="$target_exec ${target_path}/ffmpeg${PROGSUF}${EXECSUF}"
  284. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  285. pcm_src="${target_path}/tests/data/asynth1.sw"
  286. [ "${V-0}" -gt 0 ] && echov=echov || echov=:
  287. echov(){
  288. echo "$@" >&3
  289. }
  290. AVCONV_OPTS="-nostdin -nostats -noauto_conversion_filters -y -cpuflags $cpuflags -filter_threads $threads"
  291. COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  292. DEC_OPTS="$COMMON_OPTS -threads $threads"
  293. ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint"
  294. run_avconv(){
  295. $echov $ffmpeg2 $AVCONV_OPTS $*
  296. $ffmpeg2 $AVCONV_OPTS $*
  297. }
  298. do_avconv(){
  299. f="$1"
  300. shift
  301. set -- $* ${target_path}/$f
  302. run_avconv $* || return
  303. do_md5sum $f
  304. echo $(wc -c $f)
  305. }
  306. do_avconv_crc(){
  307. f="$1"
  308. shift
  309. printf "%s " "$f"
  310. run_avconv $* -f crc -
  311. }
  312. lavf_audio(){
  313. t="${test#lavf-}"
  314. outdir="tests/data/lavf"
  315. file=${outdir}/lavf.$t
  316. test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
  317. do_avconv $file -auto_conversion_filters $DEC_OPTS $1 -ar 44100 -f s16le -i $pcm_src \
  318. "$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 $2 || return
  319. test "$4" = "disable_crc" ||
  320. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS $3 -i $target_path/$file
  321. }
  322. lavf_container(){
  323. t="${test#lavf-}"
  324. outdir="tests/data/lavf"
  325. file=${outdir}/lavf.$t
  326. test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
  327. do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $DEC_OPTS \
  328. -ar 44100 -f s16le $1 -i $pcm_src "$ENC_OPTS -metadata title=lavftest" -b:a 64k -t 1 -qscale:v 10 $2 || return
  329. test "$3" = "disable_crc" ||
  330. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $3
  331. }
  332. lavf_container_attach() { lavf_container "" "$1 -attach ${raw_src%/*}/00.pgm -metadata:s:t mimetype=image/x-portable-greymap"; }
  333. lavf_container_timecode_nodrop() { lavf_container "" "$1 -timecode 02:56:14:13"; }
  334. lavf_container_timecode_drop() { lavf_container "" "$1 -timecode 02:56:14.13 -r 30000/1001"; }
  335. lavf_container_timecode()
  336. {
  337. lavf_container_timecode_nodrop "$@"
  338. lavf_container_timecode_drop "$@"
  339. lavf_container "" "$1"
  340. }
  341. lavf_container_fate()
  342. {
  343. t="${test#lavf-fate-}"
  344. outdir="tests/data/lavf-fate"
  345. file=${outdir}/lavf.$t
  346. cleanfiles="$cleanfiles $file"
  347. input="${target_samples}/$1"
  348. do_avconv $file -auto_conversion_filters $DEC_OPTS $2 -i "$input" \
  349. "$ENC_OPTS -metadata title=lavftest" -vcodec copy -acodec copy || return
  350. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $3
  351. }
  352. lavf_image(){
  353. no_file_checksums="$3"
  354. nb_frames=13
  355. t="${test#lavf-}"
  356. outdir="tests/data/images/$t"
  357. mkdir -p "$outdir"
  358. file=${outdir}/%02d.$t
  359. if [ "$keep" -lt 1 ]; then
  360. for i in `seq $nb_frames`; do
  361. filename=`printf "$file" $i`
  362. cleanfiles="$cleanfiles $filename"
  363. done
  364. fi
  365. run_avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $1 \
  366. "$ENC_OPTS -metadata title=lavftest" -vf scale -frames $nb_frames \
  367. -y -qscale 10 $target_path/$file || return
  368. if [ -z "$no_file_checksums" ]; then
  369. do_md5sum ${outdir}/02.$t
  370. echo $(wc -c ${outdir}/02.$t)
  371. fi
  372. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS $2 -i $target_path/$file $2
  373. }
  374. lavf_image2pipe(){
  375. t="${test#lavf-}"
  376. t="${t%pipe}"
  377. outdir="tests/data/lavf"
  378. file=${outdir}/${t}pipe.$t
  379. do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src \
  380. -f image2pipe "$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 || return
  381. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -f image2pipe -i $target_path/$file
  382. }
  383. lavf_video(){
  384. t="${test#lavf-}"
  385. outdir="tests/data/lavf"
  386. file=${outdir}/lavf.$t
  387. test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
  388. do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src \
  389. "$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 $1 $2 || return
  390. do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $1
  391. }
  392. refcmp_metadata(){
  393. refcmp=$1
  394. pixfmt=$2
  395. fuzz=${3:-0.001}
  396. ffmpeg -auto_conversion_filters $FLAGS $ENC_OPTS \
  397. -lavfi "testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},split[ref][tmp];[tmp]avgblur=4[enc];[enc][ref]${refcmp},metadata=print:file=-" \
  398. -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
  399. }
  400. cmp_metadata(){
  401. refcmp=$1
  402. pixfmt=$2
  403. fuzz=${3:-0.001}
  404. ffmpeg $FLAGS $ENC_OPTS \
  405. -lavfi "testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},${refcmp},metadata=print:file=-" \
  406. -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
  407. }
  408. refcmp_metadata_files(){
  409. file1=$1
  410. file2=$2
  411. refcmp=$3
  412. pixfmt=$4
  413. fuzz=${5:-0.001}
  414. ffmpeg -auto_conversion_filters $FLAGS -i $file1 $FLAGS -i $file2 $ENC_OPTS \
  415. -lavfi "[0:v]format=${pixfmt}[v0];[1:v]format=${pixfmt}[v1];[v0][v1]${refcmp},metadata=print:file=-" \
  416. -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
  417. }
  418. refcmp_metadata_transcode(){
  419. srcfile=$1
  420. enc_opt=$2
  421. enc_fmt=$3
  422. enc_ext=$4
  423. shift 4
  424. encfile="${outdir}/${test}.${enc_ext}"
  425. cleanfiles="$cleanfiles $encfile"
  426. tsrcfile=$(target_path $srcfile)
  427. tencfile=$(target_path $encfile)
  428. ffmpeg $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS -y -f $enc_fmt $tencfile || return
  429. refcmp_metadata_files $tencfile $tsrcfile "$@"
  430. }
  431. pixfmt_conversion(){
  432. conversion="${test#pixfmt-}"
  433. outdir="tests/data/pixfmt"
  434. raw_dst="$outdir/$conversion.out.yuv"
  435. file=${outdir}/${conversion}.yuv
  436. cleanfiles="$cleanfiles $raw_dst $file"
  437. run_avconv $DEC_OPTS -r 1 -f image2 -c:v pgmyuv -i $raw_src \
  438. $ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $conversion $target_path/$raw_dst || return
  439. do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $conversion -i $target_path/$raw_dst \
  440. $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p
  441. }
  442. video_filter(){
  443. filters=$1
  444. shift
  445. label=${test#filter-}
  446. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  447. printf '%-20s' $label
  448. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  449. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
  450. }
  451. pixfmts(){
  452. filter=${test#filter-pixfmts-}
  453. filter=${filter%_*}
  454. filter_args=$1
  455. prefilter_chain=$2
  456. nframes=${3:-1}
  457. showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts${EXECSUF}"
  458. scale_exclude_fmts=${outfile}_scale_exclude_fmts
  459. scale_in_fmts=${outfile}_scale_in_fmts
  460. scale_out_fmts=${outfile}_scale_out_fmts
  461. in_fmts=${outfile}_in_fmts
  462. # exclude pixel formats which are not supported as input
  463. $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  464. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  465. comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  466. $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  467. pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  468. outertest=$test
  469. for pix_fmt in $pix_fmts; do
  470. test=$pix_fmt
  471. video_filter "${prefilter_chain}scale,format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes || return
  472. done
  473. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  474. test=$outertest
  475. }
  476. gapless(){
  477. sample=$(target_path $1)
  478. extra_args=$2
  479. decfile1="${outdir}/${test}.out-1"
  480. decfile2="${outdir}/${test}.out-2"
  481. decfile3="${outdir}/${test}.out-3"
  482. cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
  483. # test packet data
  484. ffmpeg -auto_conversion_filters $extra_args -i "$sample" \
  485. -bitexact -c:a copy -f framecrc -y $(target_path $decfile1) || return
  486. do_md5sum $decfile1
  487. # test decoded (and cut) data
  488. ffmpeg -auto_conversion_filters $extra_args -i "$sample" -bitexact -f wav md5: || return
  489. # the same as above again, with seeking to the start
  490. ffmpeg -auto_conversion_filters $extra_args -ss 0 -seek_timestamp 1 -i "$sample" \
  491. -bitexact -c:a copy -f framecrc -y $(target_path $decfile2) || return
  492. do_md5sum $decfile2
  493. ffmpeg -auto_conversion_filters $extra_args -ss 0 -seek_timestamp 1 -i "$sample" \
  494. -bitexact -f wav md5: || return
  495. # test packet data, with seeking to a specific position
  496. ffmpeg -auto_conversion_filters $extra_args -ss 5 -seek_timestamp 1 -i "$sample" \
  497. -bitexact -c:a copy -f framecrc -y $(target_path $decfile3) || return
  498. do_md5sum $decfile3
  499. }
  500. gaplessenc(){
  501. sample=$(target_path $1)
  502. format=$2
  503. codec=$3
  504. file1="${outdir}/${test}.out-1"
  505. cleanfiles="$cleanfiles $file1"
  506. # test data after reencoding
  507. ffmpeg -i "$sample" -bitexact -map 0:a -c:a $codec -af aresample \
  508. -f $format -y "$(target_path "$file1")" || return
  509. probegaplessinfo "$(target_path "$file1")"
  510. }
  511. audio_match(){
  512. sample=$(target_path $1)
  513. trefile=$2
  514. extra_args=$3
  515. decfile="${outdir}/${test}.wav"
  516. cleanfiles="$cleanfiles $decfile"
  517. ffmpeg -auto_conversion_filters -i "$sample" -bitexact $extra_args -y $(target_path $decfile) || return
  518. tests/audiomatch${HOSTEXECSUF} $decfile $trefile
  519. }
  520. concat(){
  521. template=$1
  522. sample=$2
  523. mode=$3
  524. extra_args=$4
  525. concatfile="${outdir}/${test}.ffconcat"
  526. packetfile="${outdir}/${test}.ffprobe"
  527. cleanfiles="$concatfile $packetfile"
  528. awk "{gsub(/%SRCFILE%/, \"$sample\"); print}" $template > $concatfile
  529. if [ "$mode" = "md5" ]; then
  530. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_streams -show_packets -safe 0 $extra_args $(target_path $concatfile) | tr -d '\r' > $packetfile
  531. do_md5sum $packetfile
  532. else
  533. run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_streams -show_packets -of compact=p=0:nk=1 -safe 0 $extra_args $(target_path $concatfile)
  534. fi
  535. }
  536. venc_data(){
  537. file=$1
  538. stream=$2
  539. frames=$3
  540. run tools/venc_data_dump${EXECSUF} ${file} ${stream} ${frames} ${threads} ${thread_type}
  541. }
  542. null(){
  543. :
  544. }
  545. # Disable globbing: command arguments may contain globbing characters and
  546. # must be kept verbatim
  547. set -f
  548. exec 3>&2
  549. eval $command >"$outfile" 2>$errfile
  550. err=$?
  551. if [ $err -gt 128 ]; then
  552. sig=$(kill -l $err 2>/dev/null)
  553. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  554. fi
  555. if test -e "$ref" || test $cmp = "oneline" || test $cmp = "null" || test $cmp = "grep" ; then
  556. case $cmp in
  557. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  558. rawdiff)diff -u "$ref" "$outfile" >$cmpfile ;;
  559. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  560. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  561. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  562. grep) grep "$ref" "$errfile" >$cmpfile ;;
  563. null) cat "$outfile" >$cmpfile ;;
  564. esac
  565. cmperr=$?
  566. test $err = 0 && err=$cmperr
  567. if [ "$report_type" = "ignore" ]; then
  568. test $err = 0 || echo "IGNORE\t${test}" && err=0 && unset sig
  569. else
  570. test $err = 0 || cat $cmpfile
  571. fi
  572. else
  573. echo "reference file '$ref' not found"
  574. err=1
  575. fi
  576. if [ $err -eq 0 ] && test $report_type = "standard" ; then
  577. unset cmpo erro
  578. else
  579. echo "threads=$threads" >> "$errfile"
  580. cmpo="$($base64 <$cmpfile)"
  581. erro="$($base64 <$errfile)"
  582. fi
  583. echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
  584. if test $err != 0 && test $gen != "no" && test "${ref#tests/data/}" = "$ref" ; then
  585. echo "GEN $ref"
  586. cp -f "$outfile" "$ref"
  587. err=$?
  588. fi
  589. if test $err = 0; then
  590. if test $keep -lt 2; then
  591. rm -f $outfile $errfile $cmpfile $cleanfiles
  592. fi
  593. elif test $gen = "no"; then
  594. echo "Test $test failed. Look at $errfile for details."
  595. test "${V:-0}" -gt 0 && cat $errfile
  596. else
  597. echo "Updating reference failed, possibly no output file was generated."
  598. fi
  599. exit $err