Esempio n. 1
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
Esempio n. 2
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)