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