• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#*******************************************************************
3# brief: multi-encoders comparision for openh264
4#        (one given sequence only)
5#        comparision almong encoders in \$TestEncoderList
6#
7#        more detail, please refer to runUsage() and runBrief()
8#
9# date: 2015-12-16
10#*******************************************************************
11
12runUsage()
13{
14    echo -e "\033[32m ********************************************************************* \033[0m"
15    echo " Usage: "
16    echo "      --$0 \$TestPicW \$TestPicH \$TestEncoderList"
17    echo ""
18    echo "      --example:"
19    echo "        $0 1280 720 h264enc_master h264enc_target1 h264enc_target2 "
20    echo ""
21    echo " Pre-test:"
22    echo "      --1) copy welsenc.cfg from ./openh264/testbin/ to current dir"
23    echo "      --2) set test YUV path in welsenc.cfg "
24    echo "      --3) copy layer0.cfg from ./openh264/testbin/layer2.cfg to current dir"
25    echo "      --4) copy layer1.cfg from ./openh264/testbin/layer2.cfg to current dir"
26    echo "      --5) copy layer2.cfg from ./openh264/testbin/layer2.cfg to current dir"
27    echo "      --6) copy layer3.cfg from ./openh264/testbin/layer2.cfg to current dir"
28    echo "           layer0.cfg~layer3.cfg are used for multi-layers test cases"
29    echo ""
30    echo "      --7) generate at least one encoder, "
31    echo "           eg. h264enc_master----master branch as benchmark codec"
32    echo "               h264enc_target----your branch CodecChanged as target codec"
33    echo ""
34    echo "      --8) copy all tests codec to folder ./Encoder"
35    echo "      --9) run below command line:"
36    echo "           $0 \$TestPicW \$TestPicH \$TestEncoderList"
37    echo ""
38    echo " Post-test:"
39    echo "      --1) temp cases log will be output in ./Trace-AllTestData"
40    echo "      --2) all comparision data parsed from log files will be output to "
41    echo "           related .csv file under ./Trace-AllTestData "
42    echo ""
43    echo " example:"
44    echo "     --comparison almong h264enc_master h264enc_target1 h264enc_target2"
45    echo "       for Zhuling_1280x720.yuv"
46    echo ""
47    echo "     --run command as below:"
48    echo "       $0 1280 720 h264enc_master h264enc_target1 h264enc_target2 "
49    echo ""
50    echo "     --get final result files(.csv) under ./Trace-AllTestData"
51    echo ""
52    echo -e "\033[32m ********************************************************************* \033[0m"
53}
54
55runBrief()
56{
57    echo -e "\033[32m ********************************************************************* \033[0m"
58    echo " brief:"
59    echo ""
60    echo " encoder veision comparision "
61    echo "       --comparision almong encoders in \$TestEncoderList"
62    echo "       --please generate at least one encoder and copy to folder ./Encoder"
63    echo "       --script will run all test cases for each test encoder"
64    echo "         and generate related trace log files for each encoder"
65    echo "       --script will parse and extact data based on keyword from trace log file"
66    echo "         and output to related .csv files for all encoder"
67    echo "       --the test outout file will be put under ./Trace-AllTestData"
68    echo ""
69    echo " test cases:"
70    echo "       --add more cases in function runGlobleInit()"
71    echo "       --add new argument with for loop  like rc. etc in function "
72    echo "         runAllEncodeCasesAndGenerateLog()"
73    echo ""
74    echo " new data:"
75    echo "      --currently only memory usage, you can add new data for your comparision"
76    echo "      --need to add related data parse in function runParseTraceLog()"
77    echo ""
78    echo -e "\033[32m ********************************************************************* \033[0m"
79}
80
81runPrompt()
82{
83    echo -e "\033[32m ********************************************************************* \033[0m"
84    echo ""
85    echo "             ------Test completed!--------"
86    echo ""
87    echo -e "\033[32m ********************************************************************* \033[0m"
88    echo " "
89    echo "   --Total ${iTotalCaseNum} cases run for encoders: ${aEncoderList[@]}"
90    echo ""
91    echo "   --Statistic files for comparision are list as below:"
92    echo "     ${MemoryUsageStatic}"
93    echo ""
94    echo "   --trace log files can be found under:"
95    echo "     ${LogDir}"
96    echo ""
97    echo -e "\033[32m ********************************************************************* \033[0m"
98}
99
100runGlobleInit()
101{
102    CurrenDir=`pwd`
103    LogDir="${CurrenDir}/Trace-AllTestData"
104    EncoderDir="${CurrenDir}/Encoder"
105
106    if [ ! -d ${LogDir} ]
107    then
108        mkdir ${LogDir}
109    fi
110
111
112    LogFile="Log_EncTraceInfo.log"
113    MemoryUsageStatic="${LogDir}/MemoryUsage.csv"
114    TempEncoderList=""
115    for((i=0; i<${#aEncoderList[@]}; i++))
116    do
117        if [ -z "${TempEncoderList}" ]
118        then
119            TempEncoderList="${aEncoderList[$i]},"
120        else
121            TempEncoderList="${TempEncoderList} ${aEncoderList[$i]},"
122        fi
123    done
124
125    let "iTotalCaseNum=0"
126    let "MemoryUsage = 0"
127    echo "LogDir is ${LogDir}"
128    echo "MemoryUsageStatic file is ${MemoryUsageStatic}"
129    echo "SpatialLayerNum, ThreadNum, SliceMode, SliceNum, SlicMbNum, ${TempEncoderList}" >${MemoryUsageStatic}
130
131    echo "LogDir is ${LogDir}"
132    echo "MemoryUsageStatic file is ${MemoryUsageStatic}"
133
134
135    let "iTraceLevel=4"
136    let "iFrameToBeEncoded = 32"
137    let "iMaxNalSize=0"
138    #you can add more test case like rc, gop size, et.
139    #and add "for loop" in function runAllEncodeCasesAndGenerateLog()
140    aSpatialLayerNum=(1 2 3 4 )
141    aThreadIdc=(1 4)
142    aSliceMode=(0 1 2 3)
143    aSliceNum=(0 8 16 32)
144    aSliceMbNum=(0 960)
145
146    Encoder=""
147    sEncoderCommand=""
148}
149
150runCheck()
151{
152    if [ ! -d ${EncoderDir} ]
153    then
154        echo "encoder folder does not exist, please following below command to copy encoder to test folder--./Encoder"
155        echo "   mkdir Encoder"
156        echo "   cp \${AllVersionEncoders}  ./Encoder "
157        exit 1
158    fi
159
160    let "bEncoderFlag = 0"
161    echo "aEncoderList is ${aEncoderList[@]} "
162    for file in ${aEncoderList[@]}
163    do
164        if [ -x ${EncoderDir}/${file} ]
165        then
166            let "bEncoderFlag = 1"
167        fi
168    done
169
170    if [ ${bEncoderFlag} -eq 0 ]
171    then
172        echo "no encoder under test folder, please following below command to copy encoder to test folder--./Encoder"
173        echo "   cp \${AllVersionEncoders}  ./Encoder "
174        echo "   chmod u+x ./Encoder/* "
175        exit 1
176    fi
177}
178
179
180runGenerateSpatialLayerResolution()
181{
182    SpatialLayerNum=$1
183    if [ -z "${SpatialLayerNum}" ]
184    then
185        let "SpatialLayerNum =1"
186    fi
187
188    let "PicW_L0= PicW / 8"
189    let "PicW_L1= PicW / 4"
190    let "PicW_L2= PicW / 2"
191    let "PicW_L3= PicW"
192
193    let "PicH_L0= PicH / 8"
194    let "PicH_L1= PicH / 4"
195    let "PicH_L2= PicH / 2"
196    let "PicH_L3= PicH"
197
198    if [ ${SpatialLayerNum} -eq 1 ]
199    then
200        aPicW=( ${PicW_L3} 0 0 0 )
201        aPicH=( ${PicH_L3} 0 0 0 )
202
203    elif [ ${SpatialLayerNum} -eq 2 ]
204    then
205        aPicW=( ${PicW_L2} ${PicW_L3} 0 0 )
206        aPicH=( ${PicH_L2} ${PicH_L3} 0 0 )
207
208    elif [ ${SpatialLayerNum} -eq 3 ]
209    then
210        aPicW=( ${PicW_L1} ${PicW_L2} ${PicW_L3} 0 )
211        aPicH=( ${PicH_L1} ${PicH_L2} ${PicH_L3} 0 )
212
213    elif [ ${SpatialLayerNum} -eq 4 ]
214    then
215        aPicW=( ${PicW_L0} ${PicW_L1} ${PicW_L2} ${PicW_L3} )
216        aPicH=( ${PicH_L0} ${PicH_L1} ${PicH_L2} ${PicH_L3} )
217    fi
218
219    echo "*************************************************************************"
220    echo "  ${SpatialLayerNum} layers spactial resolution for ${PicW}x${PicH} are:"
221    echo ""
222    echo "  aPicW is ${aPicW[@]}"
223    echo "  aPicH is ${aPicH[@]}"
224    echo "*************************************************************************"
225
226}
227
228#parse data from encoder trace log
229#you can add more key word to extract data from log file
230runParseTraceLog()
231{
232    TempLogFile=$1
233    let "MemoryUsage = 0"
234
235    echo "*****************************************"
236    echo "parsing trace log file"
237    echo "log file name is ${TempLogFile}"
238    echo "*****************************************"
239
240    if [ ! -e ${TempLogFile} ]
241    then
242        echo "LogFile ${TempLogFile} does not exist, please double check!"
243        return 1
244    fi
245
246    MemUsageInLog=""
247    while read line
248    do
249        if [[ "${line}" =~ "overall memory usage" ]]
250        then
251            #[OpenH264] this = 0x0x7fa4d2c04c30, Info:WelsInitEncoderExt() exit, overall memory usage: 40907254 bytes
252            MemUsageInLog=(`echo $line | awk 'BEGIN {FS="usage:"} {print $2}' `)
253        fi
254
255        # you can add more key word to extract data from log file
256        # e.g.: bit rate, fps, encoder time, psnr etc.
257        # add script block like:
258        # ****************************************************
259        #   if [[ "${line}" =~ "KeyWordYouWantToSearch" ]]
260        #   then
261        #       $line in log file which contain data you want
262        #       DataYouWant=(`echo $line | awk 'BEGIN {FS="keywordYourSearch"} {print $2}' `)
263        #   fi
264        # ****************************************************
265
266    done < ${TempLogFile}
267
268    let "MemoryUsage = ${MemUsageInLog}"
269    echo "MemoryUsage is ${MemoryUsage}"
270}
271
272runEncodeOneCase()
273{
274    #encoding process
275    echo "------------------------------------------------------"
276    echo "${Encoder} welsenc.cfg ${sEncoderCommand}" >${LogFile}
277    ${Encoder} welsenc.cfg ${sEncoderCommand}      2>>${LogFile}
278    ${Encoder} welsenc.cfg ${sEncoderCommand}       >>${LogFile}
279    echo "------------------------------------------------------"
280}
281
282runAllEncodeCasesAndGenerateLog()
283{
284
285    echo "aSpatialLayerNum is ${aSpatialLayerNum[@]}"
286    echo "aThreadIdc       is ${aThreadIdc[@]}"
287    echo "aSliceMode       is ${aSliceMode[@]}"
288    echo "aSliceNum        is ${aSliceNum[@]}"
289    echo "aSliceMbNum      is ${aSliceMbNum[@]}"
290
291    sEncoderCommand1="-lconfig 0 layer0.cfg -lconfig 1 layer1.cfg -lconfig 2 layer2.cfg  -lconfig 3 layer3.cfg"
292    TempMemoryUsage=""
293    OtherDataYouWant=""
294    TempTestCase=""
295    let "CaseNum=1"
296    for iSLayerNum in ${aSpatialLayerNum[@]}
297    do
298        for iThreadNum in ${aThreadIdc[@]}
299        do
300            for iSliceMode in ${aSliceMode[@]}
301            do
302                for iSliceNum in ${aSliceNum[@]}
303                do
304                    #raster slice mb mode, slice-mb-num =0, switch to row-mb-mode
305                    if [ ${iSliceMode} -eq 2 ]
306                    then
307                        aSliceMbNum=(0 960)
308                    else
309                        aSliceMbNum=(960)
310                    fi
311
312                    for iSlicMbNum in ${aSliceMbNum[@]}
313                    do
314                        TempMemoryUsage=""
315                        #for cases output to statistic file
316                        TempTestCase="${iSLayerNum}, ${iThreadNum}, ${iSliceMode}, ${iSliceNum}, ${iSlicMbNum}"
317
318                        for eEncoder in ${aEncoderList[@]}
319                        do
320                            Encoder=${EncoderDir}/${eEncoder}
321                            if [ -x ${Encoder} ]
322                            then
323
324                                if [ ${iSliceMode} -eq 3 ]
325                                then
326                                    iMaxNalSize=1000
327                                else
328                                    iMaxNalSize=0
329                                fi
330
331                                runGenerateSpatialLayerResolution ${iSLayerNum}
332
333                                sEncoderCommand2="-slcmd 0 ${iSliceMode} -slcmd 1 ${iSliceMode} -slcmd 2 ${iSliceMode} -slcmd 3 ${iSliceMode}"
334                                sEncoderCommand3="-slcnum 0 ${iSliceNum} -slcnum 1  ${iSliceNum} -slcnum 2 ${iSliceNum} -slcnum 3 ${iSliceNum}"
335                                sEncoderCommand4="-slcmbnum 0 ${iSlicMbNum} -slcmbnum 1 ${iSlicMbNum} -slcmbnum 2 ${iSlicMbNum} -slcmbnum 3 ${iSlicMbNum} "
336
337                                sEncoderCommand5="-trace ${iTraceLevel} -numl  ${iSLayerNum}  -thread  ${iThreadNum} -nalsize  ${iMaxNalSize}"
338
339                                sEncoderCommand6="-dw 0 ${aPicW[0]} -dw 1 ${aPicW[1]}  -dw 2 ${aPicW[2]} -dw 3 ${aPicW[3]}"
340                                sEncoderCommand7="-dh 0 ${aPicH[0]} -dh 1 ${aPicH[1]}  -dh 2 ${aPicH[2]} -dh 3 ${aPicH[3]}"
341
342                                sEncoderCommand="-frms ${iFrameToBeEncoded} ${sEncoderCommand1} ${sEncoderCommand2} ${sEncoderCommand3} ${sEncoderCommand4} ${sEncoderCommand5} ${sEncoderCommand6} ${sEncoderCommand7}"
343
344                                LogFile="${LogDir}/${CaseNum}_LogInfo_iSLNum_${iSLayerNum}_ThrNum_${iThreadNum}_SlcM_${iSliceMode}_SlcN_${iSliceNum}_${eEncoder}.log"
345
346                                echo "Encode command is: "
347                                echo "${Encoder} welsenc.cfg  ${sEncoderCommand}"
348                                echo ""
349                                echo "log file is ${LogFile}"
350
351                                #encode one case
352                                runEncodeOneCase
353
354                                #parse trace log
355                                runParseTraceLog ${LogFile}
356
357                                #data extracted from log
358                                #you can add new data here like rc, fps , etc.
359                                echo "memory usage is ${MemoryUsage}"
360                                if [ -z ${TempMemoryUsage} ]
361                                then
362                                    TempMemoryUsage="${MemoryUsage},"
363                                else
364                                    TempMemoryUsage="${TempMemoryUsage} ${MemoryUsage},"
365                                fi
366                                echo "TempMemoryUsage is ${TempMemoryUsage}"
367                            fi
368                        done
369
370                        #output memory usage for all encoders
371                        echo "${TempTestCase}, ${TempMemoryUsage}, ${OtherDataYouWant}" >>${MemoryUsageStatic}
372                        let " CaseNum ++"
373                        let "iTotalCaseNum ++"
374
375                    done
376
377                done
378
379            done
380
381        done
382
383    done
384
385}
386
387
388runMain()
389{
390    runGlobleInit
391    runCheck
392    runAllEncodeCasesAndGenerateLog
393    runPrompt
394}
395
396#*************************************************************
397if [ $# -lt 3 ]
398then
399    runUsage
400    runBrief
401    exit 1
402fi
403
404declare -a aEncoderList
405declare -a aParamList
406
407aParamList=( $@ )
408ParamNum=$#
409
410PicW=${aParamList[0]}
411PicH=${aParamList[1]}
412
413for((i=2;i<$#;i++))
414do
415    echo "encoder is  ${aParamList[$i]}"
416    aEncoderList="${aEncoderList} ${aParamList[$i]}"
417done
418aEncoderList=(${aEncoderList})
419
420
421echo -e "\033[32m ********************************* \033[0m"
422echo ""
423echo "   --num parameters is ${ParamNum} "
424echo "   --input parameters are:"
425echo "     $0 $@"
426echo ""
427echo -e "\033[32m ********************************* \033[0m"
428
429runMain
430#*************************************************************
431
432