Пример #1
0
def process_downsampler_compare(yuv_list, downscale):
    out_path = __init__.OUT_DATA_PATH

    f1 = open(out_path + os.sep + "psnrCompare1" + "_%d" % downscale + ".csv", "w")
    f2 = open(out_path + os.sep + "psnrCompare2" + "_%d" % downscale + ".csv", "w")
    f3 = open(out_path + os.sep + "psnrCompare3" + "_%d" % downscale + ".csv", "w")
    f1.write("filename,psnr_y,psnr_u,psnr_v,psnr2, ssim\n")
    f2.write("filename,psnr_y,psnr_u,psnr_v,psnr2, ssim\n")
    f3.write("filename,psnr_y,psnr_u,psnr_v,psnr2, ssim\n")

    for one_yuv in yuv_list:
        width, height, framerate = __init__.get_resolution_from_name(one_yuv)
        width_out = width / downscale
        height_out = height / downscale
        out_yuv_resolution = "%d" % width_out + "x" + "%d" % height_out

        jsvm_out = (
            out_path + os.sep + os.path.basename(one_yuv)[0:-4] + "_to_" + out_yuv_resolution + "_downConvert.yuv"
        )
        downsampler1_out = (
            out_path + os.sep + os.path.basename(one_yuv)[0:-4] + "_to_" + out_yuv_resolution + "_downsampler1.yuv"
        )
        downsampler2_out = (
            out_path + os.sep + os.path.basename(one_yuv)[0:-4] + "_to_" + out_yuv_resolution + "_downsampler2.yuv"
        )

        jsvm_downsampler(width, height, one_yuv, width_out, height_out, jsvm_out)
        test_downsampler(one_yuv, width, height, downsampler1_out, downsampler2_out, width_out, height_out)

        # psnr ing
        frame_num, bitrate, psnr_y1, psnr_u1, psnr_v1 = CodecUtil.PSNRStaticd(
            width_out, height_out, jsvm_out, downsampler1_out, downsampler1_out + ".log"
        )
        if VQMT_ON:
            psnr2, ssim = CodecUtil.Vqmt(width_out, height_out, jsvm_out, downsampler1_out, frame_num)
        else:
            psnr2, ssim = 0, 0
        f1.write("%s,%f,%f,%f,%f,%f\n" % (os.path.basename(one_yuv), psnr_y1, psnr_u1, psnr_v1, psnr2, ssim))

        frame_num, bitrate, psnr_y2, psnr_u2, psnr_v2 = CodecUtil.PSNRStaticd(
            width_out, height_out, jsvm_out, downsampler2_out, downsampler2_out + ".log"
        )
        if VQMT_ON:
            psnr2, ssim = CodecUtil.Vqmt(width_out, height_out, jsvm_out, downsampler2_out, frame_num)
        else:
            psnr2, ssim = 0, 0
        f2.write("%s,%f,%f,%f,%f,%f\n" % (os.path.basename(one_yuv), psnr_y2, psnr_u2, psnr_v2, psnr2, ssim))

        frame_num, bitrate, psnr_y3, psnr_u3, psnr_v3 = CodecUtil.PSNRStaticd(
            width_out, height_out, downsampler1_out, downsampler2_out, downsampler1_out + downsampler2_out + ".log"
        )
        f3.write("%s,%f,%f,%f\n" % (os.path.basename(one_yuv), psnr_y3, psnr_u3, psnr_v3))
        # TODO: output psnr into a file, csv is the best

    f1.close()
    f2.close()
    f3.close()
Пример #2
0
def encode_one_yuv(exe_path, one_yuv, usage_type=0, qp=24):
    name = ((one_yuv.split(os.sep))[-1])

    width, height, frame_rate = __init__.get_resolution_from_name(name)
    if frame_rate == 0:
        frame_rate = 30

    # encoding
    current_path = os.getcwd()
    os.chdir(exe_path)
    print("current path is %s\n" %exe_path)

    if not SKIP_ENCODING:
        if TEST_JM:
            bs_name, log_name = CodecUtil.jm_encoder(one_yuv, usage_type, width, height, qp, ' -p IDRPeriod=1 -p LevelIDC=51 ')
        else:
            bs_name, log_name, result_line = CodecUtil.openh264_encoder_qp(one_yuv, usage_type, width, height, qp, ' -iper 0 ')
    else:
        bs_name  = one_yuv.split(os.sep)[-1] + '_br' + str(qp) + '.264'
        log_name = one_yuv.split(os.sep)[-1] + '_br' + str(qp) + '.log'
    #deal with log file
    fps = CodecUtil.openh264_encoder_log_fps(log_name)

    if not PERFORMANCE_ONLY:
        # decoding
        rec_yuv = bs_name+'_dec.yuv'
        if TEST_JM:
            CodecUtil.jm_decode(bs_name, rec_yuv)
        else:
            CodecUtil.decode(bs_name, rec_yuv)

        # psnr ing
        frame_num, bitrate, psnr_y, psnr_u, psnr_v = CodecUtil.PSNRStaticd(width, height, one_yuv, rec_yuv,
                                                         rec_yuv+'.log', bs_name, frame_rate)
        ssim, msssim = 0,0
        if VQMT_ON:
            psnr2, ssim, msssim = CodecUtil.Vqmt(width, height, one_yuv, rec_yuv, frame_num)

        file_size = os.path.getsize(bs_name)
        current_test_point = OneTestPoint(width, height, frame_rate, frame_num, qp, file_size, 0, fps, bitrate, psnr_y, psnr_u, psnr_v, ssim, msssim)
        os.remove(rec_yuv)
    else:
        current_test_point = OneTestPoint(width, height, frame_rate, 0, qp, 0, 0, fps, 0, 0, 0, 0, 0, 0)
        if DEBUG==0:
            os.remove(bs_name)
            os.remove(log_name)

    os.chdir(current_path)
    return current_test_point
Пример #3
0
def process_compare_enc(yuv_list, downscale):
    TestPoint_dict = {}
    out_path = __init__.OUT_DATA_PATH

    BitRateTable = CodecUtil.cBitRateTable()

    for one_yuv in yuv_list:
        width, height, frame_rate = __init__.get_resolution_from_name(one_yuv)
        width_out = width / downscale
        height_out = height / downscale
        out_yuv_resolution = "%d" % width_out + "x" + "%d" % height_out

        jsvm_out = (
            out_path + os.sep + os.path.basename(one_yuv)[0:-4] + "_to_" + out_yuv_resolution + "_downConvert.yuv"
        )
        downsampler1_out = (
            out_path + os.sep + os.path.basename(one_yuv)[0:-4] + "_to_" + out_yuv_resolution + "_downsampler1.yuv"
        )
        downsampler2_out = (
            out_path + os.sep + os.path.basename(one_yuv)[0:-4] + "_to_" + out_yuv_resolution + "_downsampler2.yuv"
        )

        # encoder three yuv files
        qp = 36
        usage_type = 0
        result_path = os.path.abspath(__init__.OUT_DATA_PATH)
        jsvm_out = os.path.abspath(jsvm_out)
        downsampler1_out = os.path.abspath(downsampler1_out)
        downsampler2_out = os.path.abspath(downsampler2_out)

        current_path = os.getcwd()
        os.chdir(H264CODEC_PATH)
        for source in (jsvm_out, downsampler1_out, downsampler2_out):
            if RC_ON:
                bs_name, log_name, result_line = CodecUtil.openh264_encoder_rc(
                    source,
                    usage_type,
                    width_out,
                    height_out,
                    frame_rate,
                    BitRateTable.get_one_camera_point(width_out, height_out),
                    BitRateTable.get_one_camera_point(width_out, height_out) * 2,
                    0,
                    0,
                )
            else:
                bs_name, log_name, result_line = CodecUtil.openh264_encoder_qp(
                    source, usage_type, width_out, height_out, qp
                )

            bs_name = __init__.move_to_result_path(bs_name, result_path)
            log_name = __init__.move_to_result_path(log_name, result_path)

            rec_yuv = bs_name[0:-4] + "_dec.yuv"
            CodecUtil.decode(bs_name, rec_yuv)

            # encoder information
            frames, encode_time, fps = CodecUtil.openh264_encoder_log_all(log_name)

            # psnr ing
            frame_num, bitrate, psnr_y, psnr_u, psnr_v = CodecUtil.PSNRStaticd(
                width_out, height_out, source, rec_yuv, rec_yuv + ".log", bs_name, frame_rate
            )
            psnr2, ssim = 0, 0
            if VQMT_ON:
                psnr2, ssim = CodecUtil.Vqmt(width_out, height_out, source, rec_yuv, frame_num)

            file_size = os.path.getsize(bs_name)
            current_test_point = OneTestPoint(
                width_out,
                height_out,
                frame_rate,
                frames,
                qp,
                file_size,
                encode_time,
                fps,
                bitrate,
                psnr_y,
                psnr_u,
                psnr_v,
                psnr2,
                ssim,
            )

            if not TestPoint_dict.has_key(source):
                TestPoint_dict[source] = {}
            if not TestPoint_dict[source].has_key(qp):
                TestPoint_dict[source][qp] = {}
            TestPoint_dict[source][qp] = current_test_point
            os.remove(rec_yuv)

        for source in (downsampler1_out, downsampler2_out):
            bs_name, log_name, result_line = CodecUtil.openh264_encoder_qp(
                source, usage_type, width_out, height_out, qp
            )
            bs_name = __init__.move_to_result_path(bs_name, result_path)
            rec_yuv = bs_name[0:-4] + "_dec.yuv"
            CodecUtil.decode(bs_name, rec_yuv)
            frame_num, bitrate, psnr_y, psnr_u, psnr_v = CodecUtil.PSNRStaticd(width_out, height_out, jsvm_out, rec_yuv)
            psnr2, ssim = 0, 0
            if VQMT_ON:
                psnr2, ssim = CodecUtil.Vqmt(width_out, height_out, source, rec_yuv, frame_num)

            current_test_point = OneTestPoint(
                width_out, height_out, frame_rate, frame_num, qp, 0, 0, 0, bitrate, psnr_y, psnr_u, psnr_v, psnr2, ssim
            )

            current_name = str(os.path.basename(source) + "_comparejsvm")
            if not TestPoint_dict.has_key(current_name):
                TestPoint_dict[current_name] = {}
            if not TestPoint_dict[current_name].has_key(qp):
                TestPoint_dict[current_name][qp] = {}
            TestPoint_dict[current_name][qp] = current_test_point
            os.remove(rec_yuv)

        os.chdir(current_path)

    write_testpoint_to_csv(str("encCompare" + "_%d" % downscale), __init__.OUT_DATA_PATH, TestPoint_dict)
Пример #4
0
def batch_encoder_test(enc_path, usage_type, bit_rate_list, common_fps, multi_layer_flag=False):
    current_path = os.getcwd()
    os.chdir(enc_path)
    for f in glob.glob(enc_path + os.sep + '*.log'):
        os.remove(f)
    for f in glob.glob(enc_path + os.sep + '*.264'):
        os.remove(f)

    fout = open('Results.csv', 'w')
    fout.write('bs_name, rc_mode, frame_skip, target_br, average_br, average_br_ratio, max_qp, psnr_y, '
               'max_burst_ratio, avg_burst_ratio, max_exceed_times, max_exceed_times_ratio, max_br_burst_ratio, period_exceed_ratio, skip_ratio, skip_successive\n')

    if usage_type == 0:
        seq_path = CAMERA_SEQ_PATH
    elif usage_type == 1:
        seq_path = SCREEN_SEQ_PATH

    for frame_skip_iter in frame_skip_list:
        for rc_mode_iter in RC_MODE_LIST:
            for f in glob.glob(seq_path + os.sep + '*.yuv'):
                width, height, framerate = __init__.get_resolution_from_name(f)

                max_item = 0
                cur_bit_rate_list = []
                for item in bit_rate_list:
                    if cur_bit_rate_list == [] or ( (width*height/256) >= item and item > max_item ):
                        cur_bit_rate_list = bit_rate_list[item]
                        max_item = item

                for bit_rate_item in cur_bit_rate_list:
                    if multi_layer_flag is False:
                        target_br = int(bit_rate_item*framerate/common_fps)
                        max_br = int(target_br * float(MAX_BR_RATIO))

                        # process each file
                        bs_name, log_name = CodecUtil.openh264_encoder_rc(f, usage_type,
                                    width, height, framerate,
                                    target_br, max_br, rc_mode_iter, frame_skip_iter)

                        #encoded
                        current_log = cCurrentLog()
                        current_log.read_logs(log_name)

                        max_exceed_times, max_exceed_times_ratio, max_br_burst_ratio, max_burst_ratio, avg_burst_ratio, period_exceed_ratio = current_log.check_one_setting(target_br, max_br)
                        skip_ratio, skip_successive = current_log.get_skip_status()
                        skip_list = current_log.get_skip_list()
                        if frame_skip_iter == 0 and skip_list!=[]:
                            sys.stdout.write("Error! Frameskip(%d) not allowed but there is skipped: %s\n"
                                             %(frame_skip_iter, str(skip_list)))
                            return
                        elif skip_list != [] and skip_list[0] == 0:
                            sys.stdout.write("Incorrect Skip Idx = 0!\n")
                            return

                        average_bit_rate = current_log.get_single_layer_average_bit_rate()
                        if average_bit_rate <= 0:
                            continue

                        rec_yuv = generate_yuv(bs_name, width, height, skip_list)
                        frame_num, bitrate, psnr_y, psnr_u, psnr_v = CodecUtil.PSNRStaticd(width, height, f, rec_yuv,
                                             'Results_PSNR', bs_name, framerate)

                        fout.write('%s, %d, %d, %d, %d, %f, %d, %f, %f, %f, %d, %f, %d, %f, %f, %d\n'
                                   %(bs_name, rc_mode_iter, frame_skip_iter, target_br,
                                     average_bit_rate, average_bit_rate*100/(target_br*1000), current_log.get_max_qp(),
                                     psnr_y, max_burst_ratio, avg_burst_ratio, max_exceed_times, max_exceed_times_ratio, max_br_burst_ratio, period_exceed_ratio, skip_ratio, skip_successive))

                        os.remove(rec_yuv)
                    else:
                        target_br = [ int(item*framerate/common_fps) for item in bit_rate_item ]
                        max_br = [ int(item * float(MAX_BR_RATIO)) for item in target_br ]

                        bs_name, log_name = CodecUtil.openh264_multilayer_encoder(f, usage_type,
                                    width, height, framerate,
                                    target_br, max_br, rc_mode_iter, frame_skip_iter)

                        #encoded
                        current_log = cCurrentLog()
                        current_log.read_logs(log_name)
                        average_bit_rate = current_log.get_average_bit_rate()
                        for did in range(4):
                            if average_bit_rate[did] <= 0:
                                continue
                            max_exceed_times, max_exceed_times_ratio, max_br_burst_ratio, max_burst_ratio, average_burst_ratio, period_exceed_flag \
                                = current_log.check_one_setting_multi_layer(did, target_br[did], max_br[did])

                            skip_ratio, skip_successive = current_log.get_skip_status()
                            fout.write('%s_layer%d, %s, %d, %d, %d, %f, %f, %f, %f, %d, %f, %f, %f, %d\n'
                                       %(bs_name, did, rc_mode_iter, frame_skip_iter, target_br[did],
                                         average_bit_rate[did], average_bit_rate[did]*100/(target_br[did]*1000),
                                         0, max_burst_ratio, average_burst_ratio, max_exceed_times, max_exceed_times_ratio, period_exceed_flag, skip_ratio, skip_successive))



    fout.close()
    os.chdir(current_path)
Пример #5
0
    media_type_re = re.compile(r'mediaType: (NV12|H264|I420)')
    frame_re = re.compile(r'FrameIdx:(\d+) timestamp:(\d+):(\d+) Resolution:(\d+)x(\d+)')
    frame_re2 = re.compile(r'FrameIdx:(\d+) timestamp:(\d+):(\d+)')
    sys.stdout.write('Current Test Sequences at: %s\n' %args.test_seq_path)
    yuv_list = []

    os.chdir(args.test_seq_path)
    target_file_name = 'SequencesList.csv'
    with open(target_file_name,'w+') as list_file:
        list_file.write('file_name, width, height, frame_rate, meta_type, frms, resolution_change, min_fr, max_fr, average_fr,'
                        'min_frame_delta, max_frame_delta\n')

    for yuv_file in glob.glob('*.yuv'):
        print('dealing with %s\n' %yuv_file)
        meta_file_name = os.path.basename(yuv_file)[0:-4] + '.meta'
        width, height, frame_rate = __init__.get_resolution_from_name(yuv_file)
        frame_ts_list = []
        media_type = None
        resolution_change = 0
        frame_width = 0
        frame_height = 0
        frame_idx = 0
        frame_count = 0
        try:
            with open(meta_file_name) as meta_file:
                lines = meta_file.readlines()
                for line in lines:
                    r = media_type_re.search(line)
                    if r is not None:
                        media_type = r.group(1)
                        continue