regression-funcs.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. #
  3. # common regression functions for ffmpeg
  4. #
  5. #
  6. test="${1#regtest-}"
  7. test_ref=$2
  8. raw_src_dir=$3
  9. target_exec=$4
  10. target_path=$5
  11. threads=${6:-1}
  12. datadir="./tests/data"
  13. target_datadir="${target_path}/${datadir}"
  14. this="$test.$test_ref"
  15. logdir="$datadir/regression/$test_ref"
  16. logfile="$logdir/$test"
  17. outfile="$datadir/$test_ref/"
  18. errfile="$datadir/$this.err"
  19. # various files
  20. ffmpeg="$target_exec ${target_path}/ffmpeg"
  21. tiny_psnr="tests/tiny_psnr"
  22. raw_src="${target_path}/$raw_src_dir/%02d.pgm"
  23. raw_dst="$datadir/$this.out.yuv"
  24. raw_ref="$datadir/$test_ref.ref.yuv"
  25. pcm_src="$target_datadir/asynth1.sw"
  26. pcm_dst="$datadir/$this.out.wav"
  27. pcm_ref="$datadir/$test_ref.ref.wav"
  28. crcfile="$datadir/$this.crc"
  29. target_crcfile="$target_datadir/$this.crc"
  30. cleanfiles="$raw_dst $pcm_dst $crcfile"
  31. trap 'rm -f -- $cleanfiles' EXIT
  32. mkdir -p "$datadir"
  33. mkdir -p "$outfile"
  34. mkdir -p "$logdir"
  35. (exec >&3) 2>/dev/null || exec 3>&2
  36. [ "${V-0}" -gt 0 ] && echov=echov || echov=:
  37. [ "${V-0}" -gt 1 ] || exec 2>$errfile
  38. echov(){
  39. echo "$@" >&3
  40. }
  41. . $(dirname $0)/md5.sh
  42. FFMPEG_OPTS="-v 0 -y"
  43. COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact"
  44. DEC_OPTS="$COMMON_OPTS -threads $threads"
  45. ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint"
  46. run_ffmpeg()
  47. {
  48. $echov $ffmpeg $FFMPEG_OPTS $*
  49. $ffmpeg $FFMPEG_OPTS $*
  50. }
  51. do_ffmpeg()
  52. {
  53. f="$1"
  54. shift
  55. set -- $* ${target_path}/$f
  56. run_ffmpeg $*
  57. do_md5sum $f >> $logfile
  58. if [ $f = $raw_dst ] ; then
  59. $tiny_psnr $f $raw_ref >> $logfile
  60. elif [ $f = $pcm_dst ] ; then
  61. $tiny_psnr $f $pcm_ref 2 >> $logfile
  62. else
  63. wc -c $f >> $logfile
  64. fi
  65. }
  66. do_ffmpeg_nomd5()
  67. {
  68. f="$1"
  69. shift
  70. set -- $* ${target_path}/$f
  71. run_ffmpeg $*
  72. if [ $f = $raw_dst ] ; then
  73. $tiny_psnr $f $raw_ref >> $logfile
  74. elif [ $f = $pcm_dst ] ; then
  75. $tiny_psnr $f $pcm_ref 2 >> $logfile
  76. else
  77. wc -c $f >> $logfile
  78. fi
  79. }
  80. do_ffmpeg_crc()
  81. {
  82. f="$1"
  83. shift
  84. run_ffmpeg $* -f crc "$target_crcfile"
  85. echo "$f $(cat $crcfile)" >> $logfile
  86. }
  87. do_video_decoding()
  88. {
  89. do_ffmpeg $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2
  90. }
  91. do_video_encoding()
  92. {
  93. file=${outfile}$1
  94. do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS $2
  95. }
  96. do_audio_encoding()
  97. {
  98. file=${outfile}$1
  99. do_ffmpeg $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2
  100. }
  101. do_audio_decoding()
  102. {
  103. do_ffmpeg $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav
  104. }