예제 #1
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)
예제 #2
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)