Esempio n. 1
0
    def _assert_an_asset(cls, asset):

        # needed by _generate_result, and by _open_dis_workfile if called
        assert asset.quality_width_height is not None

        if cls._need_ffmpeg(asset):
            VmafExternalConfig.get_and_assert_ffmpeg()

        # if crop_cmd or pad_cmd is specified, make sure quality_width and
        # quality_height are EXPLICITLY specified in asset_dict
        if asset.crop_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If crop_cmd is specified, must also EXPLICITLY specify quality_width and quality_height.'
        if asset.pad_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If pad_cmd is specified, must also EXPLICITLY specify quality_width and quality_height.'
Esempio n. 2
0
    def _assert_an_asset(cls, asset):

        # needed by _generate_result, and by _open_dis_workfile if called
        assert asset.quality_width_height is not None

        if cls._need_ffmpeg(asset):
            VmafExternalConfig.get_and_assert_ffmpeg()

        # if crop_cmd or pad_cmd or etc. is specified, make sure quality_width and
        # quality_height are EXPLICITLY specified in asset_dict
        if asset.dis_crop_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If crop_cmd etc. is specified, must also EXPLICITLY specify quality_width and quality_height.'
        if asset.dis_pad_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If pad_cmd etc. is specified, must also EXPLICITLY specify quality_width and quality_height.'
Esempio n. 3
0
    def _open_ref_workfile(self, asset, fifo_mode):
        # For now, only works for YUV format -- all need is to copy from ref
        # file to ref workfile

        # only need to open ref workfile if the path is different from ref path
        assert asset.use_path_as_workpath is False and asset.ref_path != asset.ref_workfile_path

        # if fifo mode, mkfifo
        if fifo_mode:
            os.mkfifo(asset.ref_workfile_path)

        quality_width, quality_height = self._get_quality_width_height(asset)
        yuv_type = asset.ref_yuv_type
        resampling_type = self._get_resampling_type(asset)

        if yuv_type != 'notyuv':
            # in this case, for sure has ref_width_height
            width, height = asset.ref_width_height
            src_fmt_cmd = self._get_yuv_src_fmt_cmd(asset, height, width,
                                                    'ref')
        else:
            src_fmt_cmd = self._get_notyuv_src_fmt_cmd(asset, 'ref')

        workfile_yuv_type = self._get_workfile_yuv_type(asset)

        vframes_cmd, select_cmd = self._get_vframes_cmd(asset, 'ref')
        crop_cmd = self._get_filter_cmd(asset, 'crop', 'ref')
        pad_cmd = self._get_filter_cmd(asset, 'pad', 'ref')
        scale_cmd = 'scale={width}x{height}'.format(width=quality_width,
                                                    height=quality_height)

        filter_cmds = []
        for key in Asset.ORDERED_FILTER_LIST:
            if key is not 'crop' and key is not 'pad':
                filter_cmds.append(self._get_filter_cmd(asset, key, 'ref'))

        vf_cmd = ','.join(
            filter(lambda s: s != '',
                   [select_cmd, crop_cmd, pad_cmd, scale_cmd] + filter_cmds))

        ffmpeg_cmd = '{ffmpeg} {src_fmt_cmd} -i {src} -an -vsync 0 ' \
                     '-pix_fmt {yuv_type} {vframes_cmd} -vf {vf_cmd} -f rawvideo ' \
                     '-sws_flags {resampling_type} -y {dst}'
        ffmpeg_cmd = ffmpeg_cmd.format(
            ffmpeg=VmafExternalConfig.get_and_assert_ffmpeg(),
            src=asset.ref_path,
            dst=asset.ref_workfile_path,
            src_fmt_cmd=src_fmt_cmd,
            vf_cmd=vf_cmd,
            yuv_type=workfile_yuv_type,
            resampling_type=resampling_type,
            vframes_cmd=vframes_cmd,
        )

        if self.logger:
            self.logger.info(ffmpeg_cmd)

        run_process(ffmpeg_cmd, shell=True)
Esempio n. 4
0
    def _open_dis_workfile(self, asset, fifo_mode):
        # For now, only works for YUV format -- all need is to copy from dis
        # file to dis workfile

        # only need to open dis workfile if the path is different from dis path
        assert asset.use_path_as_workpath is False and asset.dis_path != asset.dis_workfile_path

        # if fifo mode, mkfifo
        if fifo_mode:
            os.mkfifo(asset.dis_workfile_path)

        quality_width, quality_height = self._get_quality_width_height(asset)
        yuv_type = asset.dis_yuv_type
        resampling_type = self._get_resampling_type(asset)

        if yuv_type != 'notyuv':
            # in this case, for sure has dis_width_height
            width, height = asset.dis_width_height
            src_fmt_cmd = self._get_yuv_src_fmt_cmd(asset, height, width,
                                                    'dis')
        else:
            src_fmt_cmd = self._get_notyuv_src_fmt_cmd(asset, 'dis')

        workfile_yuv_type = self._get_workfile_yuv_type(asset)

        crop_cmd = self._get_dis_crop_cmd(asset)
        pad_cmd = self._get_dis_pad_cmd(asset)
        gblur_cmd = self._get_dis_gblur_cmd(asset)

        vframes_cmd, select_cmd = self._get_vframes_cmd(asset, 'dis')

        scale_cmd = 'scale={width}x{height}'.format(width=quality_width,
                                                    height=quality_height)

        vf_cmd = ','.join(
            filter(lambda s: s != '',
                   [select_cmd, crop_cmd, pad_cmd, scale_cmd, gblur_cmd]))

        ffmpeg_cmd = '{ffmpeg} {src_fmt_cmd} -i {src} -an -vsync 0 ' \
                     '-pix_fmt {yuv_type} {vframes_cmd} -vf {vf_cmd} -f rawvideo ' \
                     '-sws_flags {resampling_type} -y {dst}'.format(
            ffmpeg=VmafExternalConfig.get_and_assert_ffmpeg(),
            src=asset.dis_path, dst=asset.dis_workfile_path,
            src_fmt_cmd=src_fmt_cmd,
            vf_cmd=vf_cmd,
            yuv_type=workfile_yuv_type,
            resampling_type=resampling_type,
            vframes_cmd=vframes_cmd,
        )

        if self.logger:
            self.logger.info(ffmpeg_cmd)

        run_process(ffmpeg_cmd, shell=True)
Esempio n. 5
0
    def _assert_an_asset(cls, asset):

        # needed by _generate_result, and by _open_ref_workfile or
        # _open_dis_workfile if called
        assert asset.quality_width_height is not None

        # if quality width/height do not to agree with ref/dis width/height,
        # must rely on ffmpeg for scaling
        if cls._need_ffmpeg(asset):
            VmafExternalConfig.get_and_assert_ffmpeg()

        # if crop_cmd or pad_cmd is specified, make sure quality_width and
        # quality_height are EXPLICITLY specified in asset_dict
        if asset.crop_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If crop_cmd is specified, must also EXPLICITLY specify quality_width and quality_height.'
        if asset.pad_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If pad_cmd is specified, must also EXPLICITLY specify quality_width and quality_height.'

        pass
Esempio n. 6
0
    def _open_ref_workfile(self, asset, fifo_mode):
        # For now, only works for YUV format -- all need is to copy from ref
        # file to ref workfile

        # only need to open ref workfile if the path is different from ref path
        assert asset.use_path_as_workpath is False and asset.ref_path != asset.ref_workfile_path

        # if fifo mode, mkfifo
        if fifo_mode:
            os.mkfifo(asset.ref_workfile_path)

        quality_width, quality_height = asset.quality_width_height
        yuv_type = asset.ref_yuv_type
        resampling_type = asset.resampling_type

        if yuv_type != 'notyuv':
            # in this case, for sure has ref_width_height
            width, height = asset.ref_width_height
            src_fmt_cmd = self._get_yuv_src_fmt_cmd(asset, height, width,
                                                    'ref')
        else:
            src_fmt_cmd = self._get_notyuv_src_fmt_cmd(asset, 'ref')

        workfile_yuv_type = self._get_workfile_yuv_type(asset)

        crop_cmd = self._get_crop_cmd(asset)
        pad_cmd = self._get_pad_cmd(asset)

        vframes_cmd, select_cmd = self._get_vframes_cmd(asset, 'ref')

        ffmpeg_cmd = '{ffmpeg} {src_fmt_cmd} -i {src} -an -vsync 0 ' \
                     '-pix_fmt {yuv_type} {vframes_cmd} -vf {select_cmd}{crop_cmd}{pad_cmd}scale={width}x{height} -f rawvideo ' \
                     '-sws_flags {resampling_type} -y {dst}'
        ffmpeg_cmd = ffmpeg_cmd.format(
            ffmpeg=VmafExternalConfig.get_and_assert_ffmpeg(),
            src=asset.ref_path,
            dst=asset.ref_workfile_path,
            width=quality_width,
            height=quality_height,
            src_fmt_cmd=src_fmt_cmd,
            crop_cmd=crop_cmd,
            pad_cmd=pad_cmd,
            yuv_type=workfile_yuv_type,
            resampling_type=resampling_type,
            vframes_cmd=vframes_cmd,
            select_cmd=select_cmd,
        )

        if self.logger:
            self.logger.info(ffmpeg_cmd)

        run_process(ffmpeg_cmd, shell=True)
Esempio n. 7
0
    def _assert_an_asset(cls, asset):

        # needed by _generate_result, and by _open_ref_workfile or
        # _open_dis_workfile if called
        assert asset.quality_width_height is not None

        if cls._need_ffmpeg(asset):
            VmafExternalConfig.get_and_assert_ffmpeg()

        # ref_yuv_type and dis_yuv_type must match, unless any of them is notyuv.
        # also check the logic in _get_workfile_yuv_type
        assert (asset.ref_yuv_type == 'notyuv' or asset.dis_yuv_type == 'notyuv') \
               or (asset.ref_yuv_type == asset.dis_yuv_type)

        # if crop_cmd or pad_cmd or etc. is specified, make sure quality_width and
        # quality_height are EXPLICITLY specified in asset_dict
        if asset.ref_crop_cmd is not None or asset.dis_crop_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If crop_cmd or etc. is specified, must also EXPLICITLY specify quality_width and quality_height.'
        if asset.ref_pad_cmd is not None or asset.dis_pad_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If pad_cmd or etc. is specified, must also EXPLICITLY specify quality_width and quality_height.'
Esempio n. 8
0
    def _assert_an_asset(cls, asset):

        # needed by _generate_result, and by _open_ref_workfile or
        # _open_dis_workfile if called
        assert asset.quality_width_height is not None

        if cls._need_ffmpeg(asset):
            VmafExternalConfig.get_and_assert_ffmpeg()

        # ref_yuv_type and dis_yuv_type must match, unless any of them is notyuv.
        # also check the logic in _get_workfile_yuv_type
        assert (asset.ref_yuv_type == 'notyuv' or asset.dis_yuv_type == 'notyuv') \
               or (asset.ref_yuv_type == asset.dis_yuv_type)

        # if crop_cmd or pad_cmd is specified, make sure quality_width and
        # quality_height are EXPLICITLY specified in asset_dict
        if asset.crop_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If crop_cmd is specified, must also EXPLICITLY specify quality_width and quality_height.'
        if asset.pad_cmd is not None:
            assert 'quality_width' in asset.asset_dict and 'quality_height' in asset.asset_dict, \
                'If pad_cmd is specified, must also EXPLICITLY specify quality_width and quality_height.'
Esempio n. 9
0
    def _open_ref_workfile(self, asset, fifo_mode):
        # For now, only works for YUV format -- all need is to copy from ref
        # file to ref workfile

        # only need to open ref workfile if the path is different from ref path
        assert asset.use_path_as_workpath is False and asset.ref_path != asset.ref_workfile_path

        # if fifo mode, mkfifo
        if fifo_mode:
            os.mkfifo(asset.ref_workfile_path)

        quality_width, quality_height = self._get_quality_width_height(asset)
        yuv_type = asset.ref_yuv_type
        resampling_type = self._get_resampling_type(asset)

        if yuv_type != 'notyuv':
            # in this case, for sure has ref_width_height
            width, height = asset.ref_width_height
            src_fmt_cmd = self._get_yuv_src_fmt_cmd(asset, height, width, 'ref')
        else:
            src_fmt_cmd = self._get_notyuv_src_fmt_cmd(asset, 'ref')

        workfile_yuv_type = self._get_workfile_yuv_type(asset)

        crop_cmd = self._get_crop_cmd(asset)
        pad_cmd = self._get_pad_cmd(asset)

        vframes_cmd, select_cmd = self._get_vframes_cmd(asset, 'ref')

        ffmpeg_cmd = '{ffmpeg} {src_fmt_cmd} -i {src} -an -vsync 0 ' \
                     '-pix_fmt {yuv_type} {vframes_cmd} -vf {select_cmd}{crop_cmd}{pad_cmd}scale={width}x{height} -f rawvideo ' \
                     '-sws_flags {resampling_type} -y {dst}'
        ffmpeg_cmd = ffmpeg_cmd.format(
            ffmpeg=VmafExternalConfig.get_and_assert_ffmpeg(),
            src=asset.ref_path,
            dst=asset.ref_workfile_path,
            width=quality_width,
            height=quality_height,
            src_fmt_cmd=src_fmt_cmd,
            crop_cmd=crop_cmd,
            pad_cmd=pad_cmd,
            yuv_type=workfile_yuv_type,
            resampling_type=resampling_type,
            vframes_cmd=vframes_cmd,
            select_cmd=select_cmd,
        )

        if self.logger:
            self.logger.info(ffmpeg_cmd)

        run_process(ffmpeg_cmd, shell=True)