Esempio n. 1
0
    def video_model_function_mode2(coding_res, display_res, framerate, frames, quant=None, avg_qp_per_noni_frame=[]):
        """
        Mode 2 model

        Arguments:
            coding_res {int} -- number of pixels in coding resolution
            display_res {int} -- number of display resolution pixels
            framerate {float} -- frame rate
            frames {list} -- frames
            quant {float} -- quant parameter, only used for debugging [default: None]
            avg_qp_per_noni_frame {list} -- average QP per non-I frame, only used for debugging [default: []]
        Returns:
            float -- O22 score
        """

        if not quant:
            if not avg_qp_per_noni_frame:
                types = []
                qp_values = []
                for frame in frames:
                    qp_values.append(frame["qpValues"])
                    frame_type = frame["type"]
                    if frame_type not in ["I", "P", "B", "Non-I"]:
                        raise P1203StandaloneError("frame type " + str(frame_type) + " not valid; must be I/P/B or I/Non-I")
                    types.append(frame_type)

                qppb = []
                for index, frame_type in enumerate(types):
                    if frame_type in ["P", "B", "Non-I"]:
                        qppb.extend(qp_values[index])
                avg_qp = np.mean(qppb)
            else:
                avg_qp = np.mean(avg_qp_per_noni_frame)
            quant = avg_qp / 51.0

        mos_cod_v = P1203Pv.VIDEO_COEFFS[0] + P1203Pv.VIDEO_COEFFS[1] * math.exp(P1203Pv.VIDEO_COEFFS[2] * quant)
        mos_cod_v = max(min(mos_cod_v, 5), 1)
        deg_cod_v = 100 - utils.r_from_mos(mos_cod_v)
        deg_cod_v = max(min(deg_cod_v, 100), 0)

        # scaling, framerate degradation
        deg_scal_v = P1203Pv.degradation_due_to_upscaling(coding_res, display_res)
        deg_frame_rate_v = P1203Pv.degradation_due_to_frame_rate_reduction(deg_cod_v, deg_scal_v, framerate)

        # degradation integration
        score = P1203Pv.degradation_integration(mos_cod_v, deg_cod_v, deg_scal_v, deg_frame_rate_v)

        logger.debug(json.dumps({
            'coding_res': round(coding_res, 2),
            'display_res': round(display_res, 2),
            'framerate': round(framerate, 2),
            'quant': round(quant, 2),
            'mos_cod_v': round(mos_cod_v, 2),
            'deg_cod_v': round(deg_cod_v, 2),
            'deg_scal_v': round(deg_scal_v, 2),
            'deg_frame_rate_v': round(deg_frame_rate_v, 2),
            'score': round(score, 2)
        }, indent=True))

        return score
Esempio n. 2
0
    def video_model_function_mode0(coding_res, display_res, bitrate_kbps_segment_size, framerate):
        """
        Mode 0 model

        Arguments:
            coding_res {int} -- number of pixels in coding resolution
            display_res {int} -- number of display resolution pixels
            bitrate_kbps_segment_size {float} -- bitrate in kBit/s
            framerate {float} -- frame rate

        Returns:
            float -- O22 score
        """

        # compression degradation
        a1 = 11.9983519
        a2 = -2.99991847
        a3 = 41.2475074001
        a4 = 0.13183165961
        q1 = 4.66
        q2 = -0.07
        q3 = 4.06
        quant = a1 + a2 * np.log(a3 + np.log(bitrate_kbps_segment_size) + np.log(bitrate_kbps_segment_size * bitrate_kbps_segment_size / (coding_res * framerate) + a4))
        mos_cod_v = q1 + q2 * np.exp(q3 * quant)
        mos_cod_v = utils.constrain(mos_cod_v, 1.0, 5.0)
        deg_cod_v = 100.0 - utils.r_from_mos(mos_cod_v)
        deg_cod_v = utils.constrain(deg_cod_v, 0.0, 100.0)

        # scaling, framerate degradation
        deg_scal_v = P1203Pv.degradation_due_to_upscaling(coding_res, display_res)
        deg_frame_rate_v = P1203Pv.degradation_due_to_frame_rate_reduction(deg_cod_v, deg_scal_v, framerate)

        # degradation integration
        score = P1203Pv.degradation_integration(mos_cod_v, deg_cod_v, deg_scal_v, deg_frame_rate_v)

        logger.debug(json.dumps({
            'coding_res': round(coding_res, 2),
            'display_res': round(display_res, 2),
            'bitrate_kbps_segment_size': round(bitrate_kbps_segment_size, 2),
            'framerate': round(framerate, 2),
            'mos_cod_v': round(mos_cod_v, 2),
            'deg_cod_v': round(deg_cod_v, 2),
            'deg_scal_v': round(deg_scal_v, 2),
            'deg_frame_rate_v': round(deg_frame_rate_v, 2),
            'score': round(score, 2)
        }, indent=True))

        return score
Esempio n. 3
0
    def video_model_function_mode3(self,
                                   coding_res,
                                   display_res,
                                   framerate,
                                   frames,
                                   quant=None,
                                   avg_qp_per_noni_frame=[]):
        """
        Mode 3 model

        Arguments:
            coding_res {int} -- number of pixels in coding resolution
            display_res {int} -- number of display resolution pixels
            framerate {float} -- frame rate
            frames {list} -- frames
            quant {float} -- quant parameter, only used for debugging [default: None]
            avg_qp_per_noni_frame {list} -- average QP per non-I frame, only used for debugging [default: []]
        Returns:
            float -- O22 score
        """

        if not quant:
            # iterate through all frames and collect information
            if not avg_qp_per_noni_frame:
                types = []
                qp_values = []
                for frame in frames:
                    qp_values.append(frame["qpValues"])
                    frame_type = frame["type"]
                    if frame_type not in ["I", "P", "B", "Non-I"]:
                        raise P1203StandaloneError(
                            "frame type " + str(frame_type) +
                            " not valid; must be I/P/B or I/Non-I")
                    types.append(frame_type)

                qppb = []
                for index, frame_type in enumerate(types):
                    if frame_type in ["P", "B", "Non-I"]:
                        qppb.extend(qp_values[index])
                    elif frame_type == "I" and len(qppb) > 0:
                        if len(qppb) > 1:
                            # replace QP value of last P-frame before I frame with QP value of previous P-frame if there
                            # are more than one stored P frames
                            qppb[-1] = qppb[-2]
                        else:
                            # if there is only one stored P frame before I-frame, remove it
                            qppb = []
                avg_qp = np.mean(qppb)
            else:
                avg_qp = np.mean(avg_qp_per_noni_frame)
            quant = avg_qp / 51.0

        q1 = self.coeffs["q1"]
        q2 = self.coeffs["q2"]
        q3 = self.coeffs["q3"]

        mos_cod_v = q1 + q2 * math.exp(q3 * quant)
        mos_cod_v = max(min(mos_cod_v, 5), 1)
        deg_cod_v = 100 - utils.r_from_mos(mos_cod_v)
        deg_cod_v = max(min(deg_cod_v, 100), 0)

        # scaling, framerate degradation
        deg_scal_v = self.degradation_due_to_upscaling(coding_res, display_res)
        deg_frame_rate_v = self.degradation_due_to_frame_rate_reduction(
            deg_cod_v, deg_scal_v, framerate)

        # degradation integration
        score = self.degradation_integration(mos_cod_v, deg_cod_v, deg_scal_v,
                                             deg_frame_rate_v)

        logger.debug(
            json.dumps(
                {
                    'coding_res': round(coding_res, 2),
                    'display_res': round(display_res, 2),
                    'framerate': round(framerate, 2),
                    'quant': round(quant, 2),
                    'mos_cod_v': round(mos_cod_v, 2),
                    'deg_cod_v': round(deg_cod_v, 2),
                    'deg_scal_v': round(deg_scal_v, 2),
                    'deg_frame_rate_v': round(deg_frame_rate_v, 2),
                    'score': round(score, 2)
                },
                indent=True))

        return score
Esempio n. 4
0
    def video_model_function_mode1(self,
                                   coding_res,
                                   display_res,
                                   bitrate_kbps_segment_size,
                                   framerate,
                                   frames,
                                   iframe_ratio=None):
        """
        Mode 1 model

        Arguments:
            coding_res {int} -- number of pixels in coding resolution
            display_res {int} -- number of display resolution pixels
            bitrate_kbps_segment_size {float} -- bitrate in kBit/s
            framerate {float} -- frame rate
            frames {list} -- frames
            iframe_ratio {float} -- iframe ratio, only for debugging

        Returns:
            float -- O22 score
        """
        # compression degradation
        a1 = self.coeffs["mode1"]["a1"]
        a2 = self.coeffs["mode1"]["a2"]
        a3 = self.coeffs["mode1"]["a3"]
        a4 = self.coeffs["mode1"]["a4"]
        q1 = self.coeffs["q1"]
        q2 = self.coeffs["q2"]
        q3 = self.coeffs["q3"]
        quant = a1 + a2 * np.log(
            a3 + np.log(bitrate_kbps_segment_size) +
            np.log(bitrate_kbps_segment_size * bitrate_kbps_segment_size /
                   (coding_res * framerate) + a4))
        mos_cod_v = q1 + q2 * np.exp(q3 * quant)
        mos_cod_v = utils.constrain(mos_cod_v, 1.0, 5.0)

        # if iframe ratio is already set (debug mode)

        # complexity correction
        c0 = self.coeffs["mode1"]["c0"]
        c1 = self.coeffs["mode1"]["c1"]
        c2 = self.coeffs["mode1"]["c2"]
        c3 = self.coeffs["mode1"]["c3"]
        if not iframe_ratio:
            i_sizes = []
            noni_sizes = []
            for frame in frames:
                frame_size = utils.calculate_compensated_size(
                    frame["type"], frame["size"], frame["dts"])
                if frame["type"] == "I":
                    i_sizes.append(int(frame_size))
                else:
                    noni_sizes.append(int(frame_size))

            # only compute ratio when there are frames of both types
            if i_sizes and noni_sizes:
                iframe_ratio = np.mean(i_sizes) / np.mean(noni_sizes)
            else:
                iframe_ratio = 0
        complexity = utils.sigmoid(c0, c1, c2, c3, iframe_ratio)
        mos_cod_v += complexity

        deg_cod_v = 100.0 - utils.r_from_mos(mos_cod_v)
        deg_cod_v = utils.constrain(deg_cod_v, 0.0, 100.0)

        # scaling, framerate degradation
        deg_scal_v = self.degradation_due_to_upscaling(coding_res, display_res)
        deg_frame_rate_v = self.degradation_due_to_frame_rate_reduction(
            deg_cod_v, deg_scal_v, framerate)

        # degradation integration
        score = self.degradation_integration(mos_cod_v, deg_cod_v, deg_scal_v,
                                             deg_frame_rate_v)

        logger.debug(
            json.dumps(
                {
                    'coding_res':
                    round(coding_res, 2),
                    'display_res':
                    round(display_res, 2),
                    'bitrate_kbps_segment_size':
                    round(bitrate_kbps_segment_size, 2),
                    'framerate':
                    round(framerate, 2),
                    'mos_cod_v':
                    round(mos_cod_v, 2),
                    'deg_cod_v':
                    round(deg_cod_v, 2),
                    'iframe_ratio':
                    round(iframe_ratio, 2),
                    'complexity':
                    round(complexity, 2),
                    'deg_scal_v':
                    round(deg_scal_v, 2),
                    'deg_frame_rate_v':
                    round(deg_frame_rate_v, 2),
                    'score':
                    round(score, 2)
                },
                indent=True))

        return score
Esempio n. 5
0
    def video_model_function_mode0(self, coding_res, display_res,
                                   bitrate_kbps_segment_size, framerate):
        """
        Mode 0 model

        Arguments:
            coding_res {int} -- number of pixels in coding resolution
            display_res {int} -- number of display resolution pixels
            bitrate_kbps_segment_size {float} -- bitrate in kBit/s
            framerate {float} -- frame rate

        Returns:
            float -- O22 score
        """

        # compression degradation
        a1 = self.coeffs["mode0"]["a1"]
        a2 = self.coeffs["mode0"]["a2"]
        a3 = self.coeffs["mode0"]["a3"]
        a4 = self.coeffs["mode0"]["a4"]
        q1 = self.coeffs["q1"]
        q2 = self.coeffs["q2"]
        q3 = self.coeffs["q3"]
        quant = a1 + a2 * np.log(
            a3 + np.log(bitrate_kbps_segment_size) +
            np.log(bitrate_kbps_segment_size * bitrate_kbps_segment_size /
                   (coding_res * framerate) + a4))
        mos_cod_v = q1 + q2 * np.exp(q3 * quant)
        mos_cod_v = utils.constrain(mos_cod_v, 1.0, 5.0)
        deg_cod_v = 100.0 - utils.r_from_mos(mos_cod_v)
        deg_cod_v = utils.constrain(deg_cod_v, 0.0, 100.0)

        # scaling, framerate degradation
        deg_scal_v = self.degradation_due_to_upscaling(coding_res, display_res)
        deg_frame_rate_v = self.degradation_due_to_frame_rate_reduction(
            deg_cod_v, deg_scal_v, framerate)

        # degradation integration
        score = self.degradation_integration(mos_cod_v, deg_cod_v, deg_scal_v,
                                             deg_frame_rate_v)

        logger.debug(
            json.dumps(
                {
                    'coding_res':
                    round(coding_res, 2),
                    'display_res':
                    round(display_res, 2),
                    'bitrate_kbps_segment_size':
                    round(bitrate_kbps_segment_size, 2),
                    'framerate':
                    round(framerate, 2),
                    'mos_cod_v':
                    round(mos_cod_v, 2),
                    'deg_cod_v':
                    round(deg_cod_v, 2),
                    'deg_scal_v':
                    round(deg_scal_v, 2),
                    'deg_frame_rate_v':
                    round(deg_frame_rate_v, 2),
                    'score':
                    round(score, 2)
                },
                indent=True))

        return score