regression-funcs.sh 2.2 KB

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