编解码器一致性验证和性能测试自动化脚本

  1. 1、自动化测试脚本说明
  2. 2、自动化测试脚本实现
  3. 3、关于该脚本中的diffyuv
    1. 3.1 方法一
    2. 3.2 方法二
  4. THE END!

1、自动化测试脚本说明

说明:编解码器在开发过程中,通常需要和标准或参考编解码进行对比以验证编解码一致性,以及测试测试编解码的性能。该脚本可用于在Linux平台、arm平台上对编解码器单独编解码或者用于一致性验证和性能测试。

2、自动化测试脚本实现

#! /bin/sh
#Functionality: codecs coherence test and performance test
#Filename:  auto_codec_arm_test.sh
#Creator:     SoaringLee
#Modify: 1、支持待验证可执行文件单独解码码流;
#         2、支持测试性能时,解码不写yuv,默认是解码写yuv的;
#         3、增加在脚本执行中断后从制定序号位置处继续执行的功能;
##===================main========================
##定义全局变量
MaxChar=100
AnchorNdec=0
Refdec=0

Refdemo="0"
YUVflag="1" #默认写yuv
YUVCompare="./diffyuv" ##YUV比较可执行文件
CoreNum="" ##指定当前可执行文件运行的CPU核心

##输入参数个数检查
if [ $# -lt 3 ];then
    echo "Usage: $0 <AnchorDemo StreamDir outFileDir> [YUVflag RefDemo start_idx CodeNum]"
    echo "Notice: This shell script need at lease 3 parameters,<xxx> is necessary, [xxx] is optinal"
    exit 1

##读取命令行参数,增加可读性
AnchorDemo="$1"
StreamsDir="$2"
outFileDir="$3"

##判断输出目录是否存在
if [ -d ${outFileDir} ];then
    echo "${outFileDir} doesn't exist, Now create it!"
    mkdir "${outFileDir}"
else
    echo "${outFileDir} already exist!"
fi

if [ $# -ge 4 ];then
    YUVflag="$4"
fi
if [ $# -ge 5 ];then
    RefDemo="$5"
fi

if [ $# -ge 6 ];then
    StartIdx="$6"
fi
if [ $# -ge 7 ];then
    CoreNum="$7"

##统计输出txt
pMatchtxt=${outFileDir}/"__pMatch.txt"       #一致性对比的一致输出txt
pNotMatchtxt=${outFileDir}/"__pNotMatch.txt" #一致性对比的不一致输出txt
pPerformancetxt=${outFileDir}/"__pCollect.txt"#性能对比输出txt
pAnchor_Ndectxt=${outFileDir}/"__Anchor_notdecstream.txt"#待验证可执行文件不能解码的码流
pRef_Ndectxt=${outFileDir}/"__Ref_notdecstream.txt"#参考可执行文件不能解码的码流
##title
title="filename"
spacenum_title=$((${MaxChar}-${#title}))
spacezero=$(seq -s '-' ${spacenum_title} | sed 's/[0-9]//g')
totaltitle="filename ${spacezero}    total frames  | fps"
echo $totaltitle > $pPerformancetxt

processIdx=-1
##[1]. Recursively get svac stream files
allfile=$(find  ${StreamDir} -name "*.svac")
for file in `ls ${allfiles}`
do
    ## 去除含有QP和ai的码流
    result=`echo $file | grep -e "QP" -e "ai"`
    if  [ -n "${result}" ]; then
        continue
    fi
    processIdx=$((${processIdx}+1))
    if [ $# -ge 6 ]; then
      if [ ${processIdx}  -le  ${StartIdx} ]; then
        continue
      fi
    fi
    echo "******processIdx*******:" ${processIdx}
    echo "******Current test*******:" $file
    ##提取出文件名
    filename=${file##*/} #从字符首部开始,删除最长匹配*/的子串
    filename=${filename%.*} 从字符串尾部开始,删除最短匹配.*的子串
##格式控制
spacenum=$((${MaxChar}-${#filename}))
spaceone=$(seq -s '-' ${spacenum} | sed 's/[0-9]//g')
spacetwo=$(seq -s '-' ${spacenum} | sed 's/[0-9]//g')
spacethr=$(seq -s '-' ${#filename} | sed 's/[0-9]//g')

##解码yuv和解码输出txt
outyuvAnchor=${outFileDir}/${filename}"_Anchor.yuv"
outyuvRef=${outFileDir}/${filename}"_Ref.yuv"
outtxtAnchor=${outFileDir}/${filename}"_Anchor.txt"
outtxtRef=${outFileDir}/${filename}"_Ref.yuv"

RawCmd=${AnchorDemo}" -i "${file}
RefCmd=${RawDemo}" -i "${file}

##[2].Decoding svac streams using anchor and red decoder
if [ "${YUVflag}"=="1" ];then
    RefCmd=${RefCmd}" -o "${outyuvRef}
    RawCmd=${RawCmd}" -o "${outyuvAnchor}
fi
if [ -n "${CoreNum}" ]; then
    RefCmd=${RefCmd}" -c ${CoreNum}"
    RawCmd=${RawCmd}" -c ${CoreNum}"
fi

RefCmd=${RefCmd}" > "${outtxtRef}
RawCmd=${RawCmd}" > "${outtxtAnchor}

##原始可执行文件解码
echo ${RawCmd}
eval ${RawCmd}
if [ #? -ne 0 ];then
    echo "========Anchor Dec Failure!========="
    echo "${AnchorDemo} cannot dec: $file, ret:$?" >> ${pAnchor_Ndectxt}
    AnchorNdec=1
else
    echo "********Anchor Dec Success!*********"
fi

## 参考可执行文件解码
if [ x"RefDemo" != x"0" ];then
    echo ${RefCmd}
    eval ${RefCmd}
    if [ #? -ne 0 ];then
        echo "========Ref Dec Failure!========="
        echo "${RefDemo} cannot dec: $file, ret:$?" >> ${pRef_Ndectxt}
        RefNdec=1
    else
        echo "********Ref Dec Success!*********"
    fi
else
    RefNdec=1
fi

##[3]. ref and anchor filecmp for coherence test
if [[ ${AnchorNdec} -ne 1 && ${RefNdec} -ne 1 && ${YUVflag} -eq 1]];then ##两者都解码成功才进行yuv比较
    cmpCmd=${YUVCompare}" "${outyuvAnchor}" "${outyuvRef}
    eval ${cmpCmd}
    if [ $? -eq 0 ];then
        echo "**********YUV MATCH!***********"
        echo "[$filename]${spacesone}MATCH!" >>${pMatchtxt}
        rm -f ${outyuvAnchor}
        rm -f ${outyuvRef}
    else
        echo "=========YUV DISMATCH!========="
        echo "[$filename]${spacesone}DISMATCH!>>${pNotMatchtxt}"
    fi
fi
##[4]. Performance collect
if [ ${AnchorNdec} -ne 1 ];then
    result=`cat $outtxtAnchor | grep -e loop` #查找文件中含有loop字符串的行
    framenum=${result%%frames*} ##delete right side
    framenum=${framenum##*,} ##delete left side
    fps=${result%%fps*}
    fps=${fps##*,}
    echo "$filename(Anchor) ${spacestwo} $framenum  $fps" >> ${pPerformancetxt}
    rm -f ${outtxtAnchor}
fi
if [ ${RefNdec} -ne 1 ];then
    result=`cat $outtxtRef | grep -e loop` #查找文件中含有loop字符串的行
    framenum=${result%%frames*} ##delete right side
    framenum=${framenum##*,} ##delete left side
    fps=${result%%fps*}
    fps=${fps##*,}
    echo "${spacesthr}   (Ref) ${spacestwo} $framenum  $fps" >> ${pPerformancetxt}
    rm -f ${outtxtRef}
fi
AnchorNdec=0  ##恢复原始不解码标记
RefNdec=0  ##恢复参考不解码标记
done

echo "This shell script run successfully!"
exit 0

3、关于该脚本中的diffyuv

3.1 方法一

https://blog.csdn.net/SoaringLee_fighting/article/details/80867857

3.2 方法二

YUV比较的C实现可以参考:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compareFile(FILE* file_compared, FILE* file_checked);

int main(int argc, char **argv)
{
    int ret;
    FILE *file1=fopen(argv[1],"rb");
    FILE *file2=fopen(argv[2],"rb");
    if(NULL==file1 || NULL==file2)
        printf("file1 or file2 open error!\n");
    ret = compareFile(file1,file2);
    if(ret)
        printf("Different!\n");
    else
        printf("Same!\n");
    return ret;
}

int compareFile(FILE* file_compared, FILE* file_checked)
{
    int diff=0;
    int N=30;
    char* b1 = (char*) calloc(1,N+1);
    char* b2 = (char*) calloc(1,N+1);
    size_t s1,s2;
    do{
        s1 = fread(b1,1,N,file_compared);
        s2 = fread(b2,1,N,file_checked);
        if(s1 != s2 || memcmp(b1,b2,s1))
        {
            diff = 1;
            break;
        }
    }while(!feof(file_compared)||!feof(file_checked));
    free(b1);
    free(b2);
    if(diff)   return 1;
    else       return 0;
}

THE END!


本博文只能阅读,谢绝转载,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 2963033731@qq.com

文章标题:编解码器一致性验证和性能测试自动化脚本

字数:1.4k

本文作者:Soaring Lee

发布时间:2018-09-07, 15:13:47

最后更新:2021-06-14, 12:13:44

原始链接:https://soaringleefighting.github.io/2018/09/07/【Codecs系列】编解码器性能测试自动化脚本/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

×

喜欢就点赞,疼爱就打赏

相册