Example #1
0
def GetDownScaledMD5File(clip, dnw, dnh, path, algo):
    contentBaseName = GetShortContentName(clip.file_name, False)
    actual_algo = 'None' if clip.width == dnw and clip.height == dnh else algo
    filename = contentBaseName + ('_Scaled_%s_%dx%d.md5' %
                                  (actual_algo, dnw, dnh))
    dnscaledmd5 = os.path.join(path, filename)
    return dnscaledmd5
Example #2
0
def GetBitstreamFile(method, codec, preset, yuvfile, qp, outpath):
    bs_suffix = SUFFIX[codec]
    Prefix_EncodeCfg = '_%s_%s_Preset_%s' % (method, codec, preset)
    filename = GetShortContentName(yuvfile, False) + Prefix_EncodeCfg + "_QP_"\
               + str(qp) + bs_suffix
    filename = os.path.join(outpath, filename)
    return filename
Example #3
0
def GetDownScaledOutFile(input, inw, inh, dnw, dnh, path, algo):
    contentBaseName = GetShortContentName(input)
    actual_algo = 'None' if inw == dnw and inh == dnh else algo
    filename = contentBaseName + ('_DnScaled_%s_%dx%d.yuv' % (actual_algo, dnw,
                                                              dnh))
    dnscaledout = os.path.join(path, filename)
    return dnscaledout
Example #4
0
def GetBsReconFileName(encmethod, codecname, test_cfg, preset, clip, dw, dh,
                       dnScAlgo, upScAlgo, qp, path_bs):
    dsyuv_name = GetDownScaledOutFile(clip, dw, dh, path_bs, dnScAlgo)
    # return bitstream file with absolute path
    bs = GetBitstreamFile(encmethod, codecname, test_cfg, preset, dsyuv_name,
                          qp, path_bs)
    decode_to_yuv = (clip.width != dw or clip.height != dh)
    decoded = GetDecodedFile(bs, path_bs, decode_to_yuv)
    suffix = ".yuv" if decode_to_yuv else ".y4m"
    ds_clip = Clip(GetShortContentName(decoded, False) + suffix,
                   decoded, clip.file_class, dw, dh, clip.fmt, clip.fps_num,
                   clip.fps_denom, clip.bit_depth)
    reconfilename = GetUpScaledOutFile(ds_clip, clip.width, clip.height,
                                       upScAlgo, path_bs)
    # return only Recon yuv file name w/o path
    reconfilename = GetShortContentName(reconfilename, False) + suffix
    return bs, reconfilename
Example #5
0
def GenerateCfgFile(clip, outw, outh, algo, outfile, num, configpath):
    contentBaseName = GetShortContentName(clip.file_name, False)
    cfg_filename = contentBaseName + ('_Scaled_%s_%dx%d.cfg' %
                                      (algo, outw, outh))
    fmt = 1
    if (clip.fmt == '400'):
        fmt = 0
    elif (clip.fmt == '420'):
        fmt = 1
    elif (clip.fmt == '422'):
        fmt = 2
    elif (clip.fmt == '444'):
        fmt = 3

    cfgfile = os.path.join(configpath, cfg_filename)
    copyfile(HDRToolsConfigFileTemplate, cfgfile)
    fp = fileinput.input(cfgfile, inplace=1)
    for line in fp:
        if 'SourceFile=' in line:
            line = 'SourceFile="%s"\n' % clip.file_path
        if 'OutputFile=' in line:
            line = 'OutputFile="%s"\n' % outfile
        if 'SourceWidth=' in line:
            line = 'SourceWidth=%d\n' % clip.width
        if 'SourceHeight=' in line:
            line = 'SourceHeight=%d\n' % clip.height
        if 'OutputWidth=' in line:
            line = 'OutputWidth=%d\n' % outw
        if 'OutputHeight=' in line:
            line = 'OutputHeight=%d\n' % outh
        if 'SourceRate=' in line:
            line = 'SourceRate=%4.3f\n' % (float)(
                clip.fps_num / clip.fps_denom)
        if 'SourceChromaFormat=' in line:
            line = 'SourceChromaFormat=%d\n' % fmt
        if 'SourceBitDepthCmp0=' in line:
            line = 'SourceBitDepthCmp0=%d\n' % clip.bit_depth
        if 'SourceBitDepthCmp1=' in line:
            line = 'SourceBitDepthCmp1=%d\n' % clip.bit_depth
        if 'SourceBitDepthCmp2=' in line:
            line = 'SourceBitDepthCmp2=%d\n' % clip.bit_depth
        if 'OutputRate=' in line:
            line = 'OutputRate=%4.3f\n' % (float)(
                clip.fps_num / clip.fps_denom)
        if 'OutputChromaFormat=' in line:
            line = 'OutputChromaFormat=%d\n' % fmt
        if 'OutputBitDepthCmp0=' in line:
            line = 'OutputBitDepthCmp0=%d\n' % clip.bit_depth
        if 'OutputBitDepthCmp1=' in line:
            line = 'OutputBitDepthCmp1=%d\n' % clip.bit_depth
        if 'OutputBitDepthCmp2=' in line:
            line = 'OutputBitDepthCmp2=%d\n' % clip.bit_depth
        if 'NumberOfFrames=' in line:
            line = 'NumberOfFrames=%d\n' % num
        print(line, end='')
    fp.close()
    return cfgfile
Example #6
0
def GetBsReconFileName(encmethod, codecname, preset, content, width, height,
                       dnwidth, dnheight, dnScAlgo,
                       upScAlgo, qp, path_bs):
    dsyuv_name = GetDownScaledOutFile(content, width, height, dnwidth, dnheight,
                                      path_bs, dnScAlgo)
    # return bitstream file with absolute path
    bs = GetBitstreamFile(encmethod, codecname, preset, dsyuv_name, qp, path_bs)
    decoded = GetDecodedFile(bs, path_bs)
    reconfilename = GetUpScaledOutFile(decoded, dnwidth, dnheight, width, height,
                                       path_bs, upScAlgo)
    # return only Recon yuv file name w/o path
    reconfilename = GetShortContentName(reconfilename, False)
    return bs, reconfilename
Example #7
0
def CalBDRateWithPython_OneSheet(sht, cols_bdmtrs, resultfiles, cellformat):
    row_refst = 0
    bdstep = len(QPs['AS']) - 1
    assert row_refst + bdstep < len(CvxH_WtRows)

    shtname = sht.get_name()
    rdrows = CvxH_WtRows
    rdcols = CvxH_WtCols
    for cols_bd, residx in zip(cols_bdmtrs, range(1, len(DnScaleRatio))):
        sht.write(
            0, cols_bd,
            'BD-Rate %.2f vs. %.2f' % (DnScaleRatio[residx], DnScaleRatio[0]))
        sht.write_row(1, cols_bd, QualityList)
        for (cls, clip_list), row_class in zip(ClipDict.items(), Rows_Class):
            rows_content = [i * len(QPs['AS']) for i in range(len(clip_list))]
            for row_cont, clip in zip(rows_content, clip_list):
                key = GetShortContentName(clip.file_name)
                for resfile in resultfiles:
                    if key in resfile:
                        rdwb = xlrd.open_workbook(resfile)
                        rdsht = rdwb.sheet_by_name(shtname)
                        break
                for y in range(len(QualityList)):
                    refbrs = rdsht.col_values(rdcols[0], rdrows[row_refst],
                                              rdrows[row_refst + bdstep] + 1)
                    refqtys = rdsht.col_values(rdcols[0] + 1 + y,
                                               rdrows[row_refst],
                                               rdrows[row_refst + bdstep] + 1)
                    testbrs = rdsht.col_values(rdcols[residx],
                                               rdrows[row_refst],
                                               rdrows[row_refst + bdstep] + 1)
                    testqtys = rdsht.col_values(rdcols[residx] + 1 + y,
                                                rdrows[row_refst],
                                                rdrows[row_refst + bdstep] + 1)
                    bdrate = BD_RATE(refbrs, refqtys, testbrs, testqtys)
                    if (bdrate != 'Error'):
                        bdrate /= 100.0
                        sht.write(row_class + row_cont, cols_bd + y, bdrate,
                                  cellformat)
                    else:
                        sht.write(row_class + row_cont, cols_bd + y, bdrate)
Example #8
0
def Run_EncDec_Upscale(method, codec, preset, clip, test_cfg, QP, num, outw,
                       outh, path_bs, path_decoded, path_upscaled, path_cfg,
                       path_perf, path_enc_log, upscale_algo, LogCmdOnly = False):
    logger.info("%s %s start encode file %s with QP = %d" %
                (method, codec, clip.file_name, QP))
    bsFile = Encode(method, codec, preset, clip, test_cfg, QP, num, path_bs,
                    path_perf, path_enc_log, LogCmdOnly)
    logger.info("start decode file %s" % os.path.basename(bsFile))
    decode_to_yuv = (clip.width != outw or clip.height != outh)
    decodedYUV = Decode(test_cfg, codec, bsFile, path_decoded, path_perf, decode_to_yuv,
                        LogCmdOnly)
    suffix = ".yuv" if decode_to_yuv else ".y4m"
    logger.info("start upscale file %s" % os.path.basename(decodedYUV))
    #hard code frame rate to 30fps to match with decoder output for now.
    #TODO: change to real frame rate after decoder fix the issue
    dec_clip = Clip(GetShortContentName(decodedYUV, False) + suffix,
                    decodedYUV, clip.file_class, clip.width, clip.height,
                    clip.fmt, clip.fps_num, clip.fps_denom, clip.bit_depth)
    upscaledYUV = UpScaling(dec_clip, num, outw, outh, path_upscaled, path_cfg,
                            upscale_algo, LogCmdOnly)
    logger.info("finish Run Encode, Decode and Upscale")
    return upscaledYUV
Example #9
0
def Run_ConvexHull_Test(clip, dnScalAlgo, upScalAlgo, LogCmdOnly=False):
    Utils.Logger.info("start encode %s" % clip.file_name)
    DnScaledRes = [(int(clip.width / ratio), int(clip.height / ratio))
                   for ratio in DnScaleRatio]
    for i in range(len(DnScaledRes)):
        if SaveMemory:
            CleanIntermediateFiles()
        DnScaledW = DnScaledRes[i][0]
        DnScaledH = DnScaledRes[i][1]
        # downscaling if the downscaled file does not exist
        dnscalyuv = GetDownScaledOutFile(clip, DnScaledW, DnScaledH,
                                         Path_DnScaleYuv, dnScalAlgo)
        if not os.path.isfile(dnscalyuv):
            dnscalyuv = DownScaling(clip, FrameNum['AS'], DnScaledW, DnScaledH,
                                    Path_DnScaleYuv, Path_CfgFiles, dnScalAlgo,
                                    LogCmdOnly)
        ds_clip = Clip(
            GetShortContentName(dnscalyuv, False) + '.y4m', dnscalyuv, "",
            DnScaledW, DnScaledH, clip.fmt, clip.fps_num, clip.fps_denom,
            clip.bit_depth)
        for QP in QPs['AS']:
            Utils.Logger.info("start encode and upscale for QP %d" % QP)
            #encode and upscaling
            reconyuv = Run_EncDec_Upscale(
                EncodeMethod, CodecName, EncodePreset, ds_clip, 'AS', QP,
                FrameNum['AS'], clip.width, clip.height, Path_Bitstreams,
                Path_DecodedYuv, Path_DecUpScaleYuv, Path_CfgFiles,
                Path_PerfLog, Path_EncLog, upScalAlgo, LogCmdOnly)
            #calcualte quality distortion
            Utils.Logger.info("start quality metric calculation")
            CalculateQualityMetric(clip.file_path, FrameNum['AS'], reconyuv,
                                   clip.fmt, clip.width, clip.height,
                                   clip.bit_depth, Path_QualityLog, LogCmdOnly)
        if SaveMemory:
            Cleanfolder(Path_DnScaleYuv)
        Utils.Logger.info("finish running encode test.")
    Utils.Logger.info("finish running encode test.")
Example #10
0
def CopyResultDataToSummaryFile_Onesheet(sht, wt_cols, resultfiles):
    rdrows = CvxH_WtRows
    rd_endcol = CvxH_WtLastCol

    shtname = sht.get_name()
    sht.write(1, 0, 'Content Class')
    sht.write(1, 1, 'Content Name')
    sht.write(1, 2, 'QP')
    for residx, col in zip(range(len(DnScaleRatio)), wt_cols):
        sht.write(0, col, 'Scaling Ratio = %.2f' % (DnScaleRatio[residx]))
        sht.write(1, col, 'Bitrate(kbps)')
        qtynames = ['%s' % qty for qty in QualityList]
        sht.write_row(1, col + 1, qtynames)

    # copy the results data from each content's result file to corresponding
    # location in summary excel file
    for (cls, contents), row_class in zip(ContentsDict.items(), Rows_Class):
        sht.write(row_class, 0, cls)
        rows_content = [i * len(QPs) for i in range(len(contents))]
        for content, row_cont in zip(contents, rows_content):
            key = GetShortContentName(content)
            sht.write(row_class + row_cont, 1, key)
            rdwb = None
            for resfile in resultfiles:
                if key in resfile:
                    rdwb = xlrd.open_workbook(resfile)
                    rdsht = rdwb.sheet_by_name(shtname)
                    for i, rdrow in zip(range(len(QPs)), rdrows):
                        data = rdsht.row_values(rdrow, 0, rd_endcol + 1)
                        sht.write_row(row_class + row_cont + i, 2, data)
                    break
            assert rdwb is not None
            if rdwb is None:
                logger.warning(
                    "not find convex hull result file for content:%s" %
                    content)
Example #11
0
def GeneratePerContentExcelFile(dnScalAlgos, upScalAlgos, content, scaleRatios,
                                path_log):
    contshortname = GetShortContentName(content)
    logger.info("start generate excel file for content :%s" % contshortname)
    excFile = GetScalingResultExcelFile_PerContent(content)
    wb = xlsxwriter.Workbook(excFile)
    shtname = contshortname
    sht = wb.add_worksheet(shtname)

    sht.write(1, 0, 'Content Name')
    sht.write(2, 0, contshortname)
    sht.write(1, 1, 'Scaling Ratio')
    sht.write_column(2, 1, scaleRatios)
    pre_title = ['Width', 'Height', 'DnScaledWidth', 'DnScaledHeight']
    sht.write_row(1, 2, pre_title)
    for dn_algo, up_algo, col in zip(dnScalAlgos, upScalAlgos, ScalQty_WtCols):
        algos = dn_algo + '--' + up_algo
        sht.write(0, col, algos)
        sht.write_row(1, col, QualityList)

    cls, w, h, fr, bitdepth, fmt, totalnum = GetVideoInfo(content, Clips)
    rows = [ScalQty_startRow + i for i in range(len(scaleRatios))]
    continfos = []
    for ratio, row in zip(scaleRatios, rows):
        dw = int(w / ratio)
        dh = int(h / ratio)
        info = [w, h, dw, dh]
        sht.write_row(row, 2, info)
        continfos.append(info)

    charts = []; y_mins = {}; y_maxs = {}
    for qty, x in zip(QualityList, range(len(QualityList))):
        chart_title = 'Scaling Quality - %s' % qty
        xaxis_name = 'scaling ratio'
        chart = CreateChart_Scatter(wb, chart_title, xaxis_name, qty)
        charts.append(chart)
        y_mins[x] = []; y_maxs[x] = []

    for dn_algo, up_algo, col, i in zip(dnScalAlgos, upScalAlgos, ScalQty_WtCols,
                                        range(len(dnScalAlgos))):
        qualities = []
        seriname = dn_algo + '--' + up_algo
        for ratio, row, idx in zip(scaleRatios, rows, range(len(scaleRatios))):
            w = continfos[idx][0]
            h = continfos[idx][1]
            dw = continfos[idx][2]
            dh = continfos[idx][3]
            dnScalOut = GetDownScaledOutFile(content, w, h, dw, dh,
                                             path_log, dn_algo)
            upScalOut = GetUpScaledOutFile(dnScalOut, dw, dh, w, h,
                                           path_log, up_algo)
            qtys = GatherQualityMetrics(upScalOut, path_log)
            sht.write_row(row, col, qtys)
            qualities.append(qtys)
        for x in range(len(QualityList)):
            AddSeriesToChart_Scatter(shtname, rows, col + x, 1, charts[x],
                                     seriname, LineColors[i])

        # get min and max of y-axis for a certain dn up scaling algo
        for qty, x in zip(QualityList, range(len(QualityList))):
            qs = [row[x] for row in qualities]
            y_mins[x].append(min(qs))
            y_maxs[x].append(max(qs))

    for qty, x in zip(QualityList, range(len(QualityList))):
        ymin = min(y_mins[x])
        ymax = max(y_maxs[x])
        margin = 0.1  # add 10% on min and max value for y_axis range
        num_precsn = 5 if 'MS-SSIM' in qty else 3
        UpdateChart(charts[x], ymin, ymax, margin, qty, num_precsn)

    startrow = rows[-1] + 2; startcol = 1
    InsertChartsToSheet(sht, startrow, startcol, charts)

    wb.close()
    logger.info("finish export scaling quality results to excel file.")
Example #12
0
def GetScalingResultExcelFile_PerContent(content):
    filename = GetShortContentName(content)
    filename = "ScalingResults_%s.xlsx" % filename
    file = os.path.join(Path_ScalingResults, filename)
    return file
Example #13
0
def GenerateSummarySheet(wb, dnScalAlgos, upScalAlgos, ratio, path_log):
    logger.info("start generate summary sheet for ratio %2.2f" % ratio)

    shts = []
    shtname = "Ratio=%1.2f" % ratio
    sht = wb.add_worksheet(shtname)
    shts.append(sht)
    sht.write(1, 0, 'Content Class')
    sht.write(1, 1, 'Content NO.')
    sht.write(1, 2, 'Content Name')
    pre_title = ['Width', 'Height', 'DnScaledWidth', 'DnScaledHeight']
    sht.write_row(1, 3, pre_title)

    for dn_algo, up_algo, col in zip(dnScalAlgos, upScalAlgos, ScalSumQty_WtCols):
        algos = dn_algo + '--' + up_algo
        sht.write(0, col, algos)
        sht.write_row(1, col, QualityList)

    content_infos = {}; totalnum_contents = 0
    for (clss, contents), row_clss in zip(ContentsDict.items(), Rows_Class):
        sht.write(row_clss, 0, clss)
        totalnum_contents = totalnum_contents + len(contents)
        for content, row_cont in zip(contents, range(len(contents))):
            cl, w, h, fr, bitdepth, fmt, totalnum = GetVideoInfo(content, Clips)
            dw = int(w / ratio)
            dh = int(h / ratio)
            shortcntname = GetShortContentName(content)
            sht.write(row_clss + row_cont, 2, shortcntname)
            infos = [w, h, dw, dh]
            sht.write_row(row_clss + row_cont, 3, infos)
            content_infos[shortcntname] = infos

    charts = []; y_mins = {}; y_maxs = {}
    for qty, x in zip(QualityList, range(len(QualityList))):
        chart_title = '%s of %s' % (qty, shtname)
        chart = CreateChart_Scatter(wb, chart_title, 'Contents', qty)
        charts.append(chart)
        y_mins[x] = []; y_maxs[x] = []

    rows_all = [ScalQty_startRow + i for i in range(totalnum_contents)]
    sht.write_column(ScalQty_startRow, 1, range(totalnum_contents))
    for dn_algo, up_algo, col, i in zip(dnScalAlgos, upScalAlgos,
                                        ScalSumQty_WtCols,
                                        range(len(dnScalAlgos))):
        qualities = []
        seriname = dn_algo + '--' + up_algo
        for (clss, contents), row_clss in zip(ContentsDict.items(), Rows_Class):
            for content, row_cont in zip(contents, range(len(contents))):
                key = GetShortContentName(content)
                w = content_infos[key][0]
                h = content_infos[key][1]
                dw = content_infos[key][2]
                dh = content_infos[key][3]
                dnScalOut = GetDownScaledOutFile(content, w, h, dw, dh,
                                                 path_log, dn_algo)
                upScalOut = GetUpScaledOutFile(dnScalOut, dw, dh, w, h,
                                               path_log, up_algo)
                qtys = GatherQualityMetrics(upScalOut, path_log)
                sht.write_row(row_clss + row_cont, col, qtys)
                qualities.append(qtys)

        for x in range(len(QualityList)):
            AddSeriesToChart_Scatter(shtname, rows_all, col + x, 1, charts[x],
                                     seriname, LineColors[i])

        # get min and max of y-axis for a certain dn up scaling algo
        for qty, x in zip(QualityList, range(len(QualityList))):
            qs = [row[x] for row in qualities]
            y_mins[x].append(min(qs))
            y_maxs[x].append(max(qs))

    for qty, x in zip(QualityList, range(len(QualityList))):
        ymin = min(y_mins[x])
        ymax = max(y_maxs[x])
        margin = 0.1  # add 10% on min and max value for y_axis range
        num_precsn = 5 if 'MS-SSIM' in qty else 3
        UpdateChart(charts[x], ymin, ymax, margin, qty, num_precsn)

    startrow = rows_all[-1] + 2; startcol = 1
    InsertChartsToSheet(sht, startrow, startcol, charts)
    logger.info("finish average sheet for ratio:%2.2f." % ratio)

    return sht
Example #14
0
def GetRDResultExcelFile(clip):
    contentBaseName = GetShortContentName(clip.file_name, False)
    filename = "RDResults_%s_%s_%s_%s.xlsx" % (contentBaseName, EncodeMethod,
                                               CodecName, EncodePreset)
    file = os.path.join(Path_RDResults, filename)
    return file
Example #15
0
def SaveConvexHullResultsToExcel(clip,
                                 dnScAlgos,
                                 upScAlgos,
                                 csv,
                                 perframe_csv,
                                 EnablePreInterpolation=False):
    Utils.Logger.info("start saving RD results to excel file.......")
    if not os.path.exists(Path_RDResults):
        os.makedirs(Path_RDResults)
    excFile = GetRDResultExcelFile(clip)
    wb = xlsxwriter.Workbook(excFile)
    shts = []
    for i in range(len(dnScAlgos)):
        shtname = dnScAlgos[i] + '--' + upScAlgos[i]
        shts.append(wb.add_worksheet(shtname))

    DnScaledRes = [(int(clip.width / ratio), int(clip.height / ratio))
                   for ratio in DnScaleRatio]
    contentname = GetShortContentName(clip.file_name)
    for sht, indx in zip(shts, list(range(len(dnScAlgos)))):
        # write QP
        sht.write(1, 0, "QP")
        sht.write_column(CvxH_WtRows[0], 0, QPs['AS'])
        shtname = sht.get_name()

        charts = []
        y_mins = {}
        y_maxs = {}
        RDPoints = {}
        Int_RDPoints = {}
        for qty, x in zip(QualityList, range(len(QualityList))):
            chart_title = 'RD Curves - %s with %s' % (contentname, shtname)
            xaxis_name = 'Bitrate - Kbps'
            chart = CreateChart_Scatter(wb, chart_title, xaxis_name, qty)
            charts.append(chart)
            y_mins[x] = []
            y_maxs[x] = []
            RDPoints[x] = []
            Int_RDPoints[x] = []

        # write RD data
        for col, i in zip(CvxH_WtCols, range(len(DnScaledRes))):
            DnScaledW = DnScaledRes[i][0]
            DnScaledH = DnScaledRes[i][1]
            sht.write(0, col, "resolution=%dx%d" % (DnScaledW, DnScaledH))
            sht.write(1, col, "Bitrate(kbps)")
            sht.write_row(1, col + 1, QualityList)

            bitratesKbps = []
            qualities = []
            for qp in QPs['AS']:
                bs, reconyuv = GetBsReconFileName(EncodeMethod, CodecName,
                                                  'AS', EncodePreset, clip,
                                                  DnScaledW, DnScaledH,
                                                  dnScAlgos[indx],
                                                  upScAlgos[indx], qp,
                                                  Path_Bitstreams)
                file_name_dnscaled_res = re.sub(
                    r'(3840x2160)',
                    str(DnScaledW) + 'x' + str(DnScaledH), clip.file_name)
                reconyuv = os.path.join(file_name_dnscaled_res + '-' + str(qp))

                out_file = open(
                    os.path.join(Path_Bitstreams,
                                 file_name_dnscaled_res + '-daala.out'), 'r')
                out_data = []
                for line in out_file.readlines():
                    out_data = line.split(' ')
                    if (int(out_data[0]) == qp):
                        break
                size_in_bytes = int(out_data[2])
                bitrate = (size_in_bytes * 8 *
                           (clip.fps_num / clip.fps_denom) /
                           FrameNum['AS']) / 1000.0
                bitratesKbps.append(bitrate)
                quality, perframe_vmaf_log = GatherQualityMetrics(
                    reconyuv, Path_QualityLog)
                qualities.append(quality)

                #"TestCfg,EncodeMethod,CodecName,EncodePreset,Class,Res,Name,FPS,Bit Depth,QP,Bitrate(kbps)")
                csv.write(
                    "%s,%s,%s,%s,%s,%s,%s,%.4f,%d,%d,%.4f" %
                    ("AS", EncodeMethod, CodecName, EncodePreset,
                     clip.file_class, str(DnScaledW) + "x" + str(DnScaledH),
                     contentname, clip.fps, clip.bit_depth, qp, bitrate))
                for qty in quality:
                    csv.write(",%.4f" % qty)
                enc_time, dec_time = float(out_data[14]), float(out_data[16])
                enc_hour = (enc_time / 3600.0)
                csv.write(",%.2f,%.2f,%.2f,\n" %
                          (enc_time, dec_time, enc_hour))
            sht.write_column(CvxH_WtRows[0], col, bitratesKbps)
            for qs, row in zip(qualities, CvxH_WtRows):
                sht.write_row(row, col + 1, qs)

            seriname = "resolution %dx%d" % (DnScaledW, DnScaledH)
            for x in range(len(QualityList)):
                # add RD curves of current resolution to each quality chart
                AddSeriesToChart_Scatter(shtname, CvxH_WtRows, col + 1 + x,
                                         col, charts[x], seriname,
                                         LineColors[i])
                # get min and max of y-axis
                qs = [row[x] for row in qualities]
                y_mins[x].append(min(qs))
                y_maxs[x].append(max(qs))
                # get RD points - (bitrate, quality) for each quality metrics
                rdpnts = [(brt, qty) for brt, qty in zip(bitratesKbps, qs)]
                RDPoints[x] = RDPoints[x] + rdpnts
                if EnablePreInterpolation:
                    int_rdpnts = Interpolate(rdpnts)
                    Int_RDPoints[x] = Int_RDPoints[x] + int_rdpnts

        # add convexhull curve to charts
        endrow = AddConvexHullCurveToCharts(sht, charts, RDPoints, DnScaledRes,
                                            TargetQtyMetrics,
                                            EnablePreInterpolation,
                                            Int_RDPoints)

        #update RD chart with approprate y axis range
        for qty, x in zip(QualityList, range(len(QualityList))):
            ymin = min(y_mins[x])
            ymax = max(y_maxs[x])
            margin = 0.1  # add 10% on min and max value for y_axis range
            num_precsn = 5 if 'MS-SSIM' in qty else 3
            UpdateChart(charts[x], ymin, ymax, margin, qty, num_precsn)

        startrow = endrow + 2
        startcol = 1
        InsertChartsToSheet(sht, startrow, startcol, charts)

    wb.close()
    Utils.Logger.info("finish export convex hull results to excel file.")
Example #16
0
def GetFfmpegLogFile(recfile, path):
    filename = GetShortContentName(recfile, False) + '_psnr.log'
    file = os.path.join(path, filename)
    return file
Example #17
0
def GetDecodedFile(bsfile, outpath):
    filename = GetShortContentName(bsfile, False) + '_Decoded.yuv'
    decodedfile = os.path.join(outpath, filename)
    return decodedfile
Example #18
0
def GenerateSummaryConvexHullExcelFile(encMethod, codecName, preset,
                                       summary_outpath, resultfiles):
    if not os.path.exists(summary_outpath):
        os.makedirs(summary_outpath)
    smfile = GetConvexHullDataSummaryFileName(encMethod, codecName, preset,
                                              summary_outpath)
    wb = xlsxwriter.Workbook(smfile)

    # shts is for all scaling algorithms' convex hull test results
    shts = []
    cols = [3 + i * 4 for i in range(len(QualityList))]
    for dnsc, upsc in zip(dnScalAlgos, upScalAlgos):
        shtname = dnsc + '--' + upsc
        sht = wb.add_worksheet(shtname)
        shts.append(sht)
        # write headers
        sht.write(0, 0, 'Content Class')
        sht.write(0, 1, 'Content Name')
        sht.write(0, 2, 'Num RD Points')

        for qty, col in zip(QualityList, cols):
            sht.write(0, col, 'Resolution')
            sht.write(0, col + 1, 'QP')
            sht.write(0, col + 2, 'Bitrate(kbps)')
            sht.write(0, col + 3, qty)

        # copy convexhull data from each content's result file to corresponding
        # location in summary excel file
        row = 1
        rdcolstart = CvxHDataStartCol + 1
        for (cls, contents) in ContentsDict.items():
            sht.write(row, 0, cls)
            for content in contents:
                key = GetShortContentName(content)
                sht.write(row, 1, key)
                for resfile in resultfiles:
                    if key in resfile:
                        rdwb = xlrd.open_workbook(resfile)
                        rdsht = rdwb.sheet_by_name(shtname)
                        maxNumQty = 0
                        for rdrow, col in zip(CvxHDataRows, cols):
                            qtys = []
                            brs = []
                            qps = []
                            ress = []
                            numQty = 0
                            for qty in rdsht.row_values(rdrow)[rdcolstart:]:
                                if qty == '':
                                    break
                                else:
                                    qtys.append(qty)
                                    numQty = numQty + 1
                            maxNumQty = max(maxNumQty, numQty)

                            for br in rdsht.row_values(rdrow + 1)[rdcolstart:]:
                                if br == '':
                                    break
                                else:
                                    brs.append(br)
                            for qp in rdsht.row_values(rdrow + 2)[rdcolstart:]:
                                if qp == '':
                                    break
                                else:
                                    qps.append(qp)
                            for res in rdsht.row_values(rdrow +
                                                        3)[rdcolstart:]:
                                if res == '':
                                    break
                                else:
                                    ress.append(res)

                            sht.write_column(row, col, ress)
                            sht.write_column(row, col + 1, qps)
                            sht.write_column(row, col + 2, brs)
                            sht.write_column(row, col + 3, qtys)

                        sht.write(row, 2, maxNumQty)
                        row = row + maxNumQty
                        break

    wb.close()
    return smfile
Example #19
0
def GetVMAFLogFile(recfile, path):
    filename = GetShortContentName(recfile, False) + '_vmaf.log'
    file = os.path.join(path, filename)
    return file
Example #20
0
def GetDecodedFile(bsfile, outpath, decode_to_yuv):
    suffix = ".yuv" if decode_to_yuv else ".y4m"
    filename = GetShortContentName(bsfile, False) + '_Decoded' + suffix
    decodedfile = os.path.join(outpath, filename)
    return decodedfile
Example #21
0
def GetUpScaledOutFile(clip, outw, outh, algo, path):
    actual_algo = 'None' if clip.width == outw and clip.height == outh else algo
    filename = GetShortContentName(clip.file_name, False) + \
               ('_Scaled_%s_%dx%d.y4m' % (actual_algo, outw, outh))
    upscaledout = os.path.join(path, filename)
    return upscaledout
Example #22
0
def SaveConvexHullResultsToExcel(content, dnScAlgos, upScAlgos):
    Utils.Logger.info("start saving RD results to excel file.......")
    if not os.path.exists(Path_RDResults):
        os.makedirs(Path_RDResults)
    excFile = GetRDResultExcelFile(content)
    wb = xlsxwriter.Workbook(excFile)
    shts = []
    for i in range(len(dnScAlgos)):
        shtname = dnScAlgos[i] + '--' + upScAlgos[i]
        shts.append(wb.add_worksheet(shtname))

    cls, width, height, fr, bitdepth, fmt, totalnum = GetVideoInfo(content, Clips)
    DnScaledRes = [(int(width / ratio), int(height / ratio)) for ratio in DnScaleRatio]
    contentname = GetShortContentName(content)
    for sht, indx in zip(shts, list(range(len(dnScAlgos)))):
        # write QP
        sht.write(1, 0, "QP")
        sht.write_column(CvxH_WtRows[0], 0, QPs)
        shtname = sht.get_name()

        charts = [];  y_mins = {}; y_maxs = {}; RDPoints = {}
        for qty, x in zip(QualityList, range(len(QualityList))):
            chart_title = 'RD Curves - %s with %s' % (contentname, shtname)
            xaxis_name = 'Bitrate - Kbps'
            chart = CreateChart_Scatter(wb, chart_title, xaxis_name, qty)
            charts.append(chart)
            y_mins[x] = []; y_maxs[x] = []; RDPoints[x] = []

        # write RD data
        for col, i in zip(CvxH_WtCols, range(len(DnScaledRes))):
            DnScaledW = DnScaledRes[i][0]
            DnScaledH = DnScaledRes[i][1]
            sht.write(0, col, "resolution=%dx%d" % (DnScaledW, DnScaledH))
            sht.write(1, col, "Bitrate(kbps)")
            sht.write_row(1, col + 1, QualityList)

            bitratesKbps = []; qualities = []
            for qp in QPs:
                bs, reconyuv = GetBsReconFileName(EncodeMethod, CodecName,
                                                  EncodePreset, content, width,
                                                  height, DnScaledW, DnScaledH,
                                                  dnScAlgos[indx], upScAlgos[indx],
                                                  qp, Path_Bitstreams)
                bitrate = (os.path.getsize(bs) * 8 * fr / FrameNum) / 1000.0
                bitratesKbps.append(bitrate)
                quality = GatherQualityMetrics(reconyuv, Path_QualityLog)
                qualities.append(quality)

            sht.write_column(CvxH_WtRows[0], col, bitratesKbps)
            for qs, row in zip(qualities, CvxH_WtRows):
                sht.write_row(row, col + 1, qs)

            seriname = "resolution %dx%d" % (DnScaledW, DnScaledH)
            for x in range(len(QualityList)):
                # add RD curves of current resolution to each quality chart
                AddSeriesToChart_Scatter(shtname, CvxH_WtRows, col + 1 + x, col,
                                         charts[x], seriname, LineColors[i])
                # get min and max of y-axis
                qs = [row[x] for row in qualities]
                y_mins[x].append(min(qs))
                y_maxs[x].append(max(qs))
                # get RD points - (bitrate, quality) for each quality metrics
                rdpnts = [(brt, qty) for brt, qty in zip(bitratesKbps, qs)]
                RDPoints[x] = RDPoints[x] + rdpnts

        # add convexhull curve to charts
        endrow = AddConvexHullCurveToCharts(sht, charts, RDPoints, DnScaledRes,
                                            TargetQtyMetrics)

        #update RD chart with approprate y axis range
        for qty, x in zip(QualityList, range(len(QualityList))):
            ymin = min(y_mins[x])
            ymax = max(y_maxs[x])
            margin = 0.1  # add 10% on min and max value for y_axis range
            num_precsn = 5 if 'MS-SSIM' in qty else 3
            UpdateChart(charts[x], ymin, ymax, margin, qty, num_precsn)

        startrow = endrow + 2; startcol = 1
        InsertChartsToSheet(sht, startrow, startcol, charts)

    wb.close()
    Utils.Logger.info("finish export convex hull results to excel file.")
Example #23
0
def GetUpScaledOutFile(infile, inw, inh, outw, outh, path, algo):
    actual_algo = 'None' if inw == outw and inh == outh else algo
    filename = GetShortContentName(infile, False) + ('_UpScaled_%s_%dx%d.yuv'
                                                     % (actual_algo, outw, outh))
    upscaledout = os.path.join(path, filename)
    return upscaledout