in python/vmaf/core/executor.py [0:0]
def _run_on_asset(self, asset):
# Wraper around the essential function _generate_result, to
# do housekeeping work including 1) asserts of asset, 2) skip run if
# log already exist, 3) creating fifo, 4) delete work file and dir
if self.result_store:
result = self.result_store.load(asset, self.executor_id)
qw, qh = asset.quality_width_height
if result is not None and self.save_workfiles is True \
and not self.result_store.has_workfile(asset, self.executor_id, f'_dis.{qw}x{qh}.{self._get_workfile_yuv_type(asset)}.yuv'):
result = None # if save_workfiles is True and has_workfile is False, invalidate result and rerun
else:
result = None
# if result can be retrieved from result_store, skip log file
# generation and reading result from log file, but directly
# return the retrieved result
if result is not None:
if self.logger:
self.logger.info('{id} result exists. Skip {id} run.'.
format(id=self.executor_id))
else:
if self.logger:
self.logger.info('{id} result does\'t exist. Perform {id} '
'calculation.'.format(id=self.executor_id))
# at this stage, it is certain that asset.ref_path and
# asset.dis_path will be used. must early determine that
# they exists
self._assert_paths(asset)
# if no FFmpeg is involved, directly work on ref_path/dis_path,
# instead of opening workfiles
self._set_asset_use_path_as_workpath(asset)
# if no ref/dis_proc_callback is involved, directly work on ref/dis_workfile_path,
# instead of opening procfiles
self._set_asset_use_workpath_as_procpath(asset)
# remove workfiles if exist (do early here to avoid race condition
# when ref path and dis path have some overlap)
if asset.use_path_as_workpath:
# do nothing
pass
else:
self._close_workfiles(asset)
# remove procfiles if exist (do early here to avoid race condition
# when ref path and dis path have some overlap)
if asset.use_workpath_as_procpath:
# do nothing
pass
else:
self._close_procfiles(asset)
log_file_path = self._get_log_file_path(asset)
make_parent_dirs_if_nonexist(log_file_path)
if asset.use_path_as_workpath:
# do nothing
pass
else:
if self.fifo_mode:
self._open_workfiles_in_fifo_mode(asset)
else:
self._open_workfiles(asset)
if asset.use_workpath_as_procpath:
# do nothing
pass
else:
if self.fifo_mode:
self._open_procfiles_in_fifo_mode(asset)
else:
self._open_procfiles(asset)
self._prepare_log_file(asset)
self._generate_result(asset)
if self.logger:
self.logger.info("Read {id} log file, get scores...".
format(id=self.executor_id))
# collect result from each asset's log file
result = self._read_result(asset)
# save result
if self.result_store:
result = self._save_result(result)
# clean up workfiles
if self.delete_workdir:
if asset.use_path_as_workpath:
# do nothing
pass
else:
self._close_workfiles(asset)
if asset.use_workpath_as_procpath:
# do nothing
pass
else:
self._close_procfiles(asset)
# clean up workdir and log files in it
if self.delete_workdir:
# remove log file
self._remove_log(asset)
# remove dir
log_file_path = self._get_log_file_path(asset)
log_dir = get_dir_without_last_slash(log_file_path)
shutil.rmtree(log_dir)
result = self._post_process_result(result)
return result