fate-run.sh 23 KB

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