-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.sh
145 lines (121 loc) · 3.06 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#Program:
#
#History
#2016/4/29 Ken first release
INFILE=${1}
###confirm the file exist or not
echo "file name is $INFILE"
if [ -f $FILENAME ];then
echo "file exist"
else
echo "file isn't exist"
exit 0
fi
###Get the resolution from argument
echo "argument number $#"
echo $@
numARG=$#
#i=1
i=2
#set -- $@
#echo ${!i}
#while [ $i -le $(($#-2)) ]
while [ $i -le $# ]
do
#temp=$i
echo "arg $i is ${!i}"
IMG_RESOLUTION[$(($i-1))]=${!i}
#echo "i is $i"
i=$(($i+1))
done
##Reduce Frame argument
RF_FILE=reduceFrame.y4m
START=00:00:03
FRAMES=128
##Down Sampling argument
DS_FILE=downSampling.y4m
##Encode HEVC argument
#QP is 0~51
read -p "please input the step size of QP" step
j=0
k=1
while [ $j -le 51 ]
do
QP[$k]=$j
echo "new QP $j class"
k=$(($k+1))
j=$(($j+$step))
done
##Decode HEVC argument
DC_FILE=decode.y4m
##Up Sampling argument
US_FILE=upSampling.y4m
##Calculate PSNR argument
PSNR_LOG=PSNR.log
###Reduce Frame
START=00:00:03
ffmpeg -i $INFILE -ss $START -vframes $FRAMES -strict -1 $RF_FILE
read -p "pause" Pause
l=1
#TODO:BUG for loop condition
while [ $l -lt $(($i-1)) ]
do
TEMPDS=${IMG_RESOLUTION[$l]}_$DS_FILE
###Down Sampling
ffmpeg -i $RF_FILE -vf scale=${IMG_RESOLUTION[$l]} -strict -1 $TEMPDS
###Encode HEVC
S=1
while [ $S -lt $k ]
do
TEMPQPBIN=${IMG_RESOLUTION[$l]}_${QP[$S]}.bin
TEMPCSV=${IMG_RESOLUTION[$l]}_${QP[$S]}.csv
x265 $TEMPDS $TEMPQPBIN -p slower -q ${QP[$S]} --csv-log-level 2 --csv $TEMPCSV --tune psnr
###Decode HEVC
TEMPDC=${IMG_RESOLUTION[$l]}_${QP[$S]}_$DC_FILE
ffmpeg -i $TEMPQPBIN -vsync 0 -strict -1 $TEMPDC
###Up Sampling
TEMPUS=${IMG_RESOLUTION[$l]}_${QP[$S]}_$US_FILE
ffmpeg -i $TEMPDC -vf scale=4096x2160 -strict -1 $TEMPUS
###Calulate PSNR
TEMPLOG=${IMG_RESOLUTION[$l]}_${QP[$S]}_$PSNR_LOG
ffmpeg -i $RF_FILE -i $TEMPUS -filter_complex "psnr" -f null nul > $TEMPLOG 2>&1
###TODO:get PSNR and Bitrate
echo "CSV $TEMPCSV LOG $TEMPLOG"
echo "grep -A1 "'$TEMPCSV'" $TEMPCSV | awk -F', ' '{print $5}'"
Bitrate=$(grep -A1 $TEMPCSV $TEMPCSV | awk -F', ' '{print $5}')
echo "Bit $Bitrate"
PSNR=$(grep -oP 'PSNR y:\K\d+.\d+' $TEMPLOG)
echo "PSNR $PSNR"
echo "Bitrate $Bitrate PSNR $PSNR"
echo "$Bitrate $PSNR" >> ${IMG_RESOLUTION[$l]}_Bitrate_PSNR.log
S=$(($S+1))
done
FILEINGP[$l]=${IMG_RESOLUTION[$l]}_Bitrate_PSNR.log
echo "GILEINGP[$l] ${FILEINGP[$l]}"
l=$(($l+1))
done
GPCONFIG=gpconfig.gp
GPPLOT="plot [0:30000][20:55] "
p=1
echo "***** l = $l*****"
while [ $p -lt $l ]
do
GPPLOT="$GPPLOT ""'${FILEINGP[$p]}'"" title ""'${IMG_RESOLUTION[$p]}'"","
echo "p = $p ,l = $l"
p=$(($p+1))
done
echo "GPPLOT $GPPLOT"
echo $GPPLOT
TEMPGP=tempgp.gp
cp gpconfig.gp $TEMPGP
echo $GPPLOT >> $TEMPGP
gnuplot $TEMPGP
rm -f $TEMPGP
#ffmpeg -i $INFILE -vf scale=$IMG_RESOLUTION[] -strict -1
###get PSNR
#grep -oP 'PSNR y:\K\d+.\d+' psnr.log
###get Bitrate
#grep -A1 '1024x540_0.csv' 1024x540_0.csv | awk -F', ' '{print $5}'
#echo $TESTGP | gnuplot ###work!!!
#multiple execution will cause csv file to append , so the grep will get multiple result Fxxk