def call_vmaf( self, chunk: Chunk, encoded: Path, vmaf_rate: int = None, fl_path: Path = None ): """ Runs vmaf for Av1an """ cmd = "" if fl_path is None: fl_path = chunk.fake_input_path.with_name(encoded.stem).with_suffix(".json") fl = fl_path.as_posix() cmd_in = ( "ffmpeg", "-loglevel", "error", "-y", "-thread_queue_size", "1024", "-hide_banner", "-r", "60", "-i", encoded.as_posix(), "-r", "60", "-i", "-", ) filter_complex = ("-filter_complex",) # Change framerate of comparison to framerate of probe n_subsamples = f":n_subsample={vmaf_rate}" if vmaf_rate else "" distorted = f"[0:v]scale={self.res}:flags=bicubic:force_original_aspect_ratio=decrease,setpts=PTS-STARTPTS[distorted];" ref = fr"[1:v]{self.vmaf_filter}scale={self.res}:flags=bicubic:force_original_aspect_ratio=decrease,setpts=PTS-STARTPTS[ref];" vmaf_filter = f"[distorted][ref]libvmaf=log_fmt='json'{n_subsamples}:eof_action=endall:log_path={shlex.quote(fl)}{self.model}{self.n_threads}" cmd_out = ("-f", "null", "-") cmd = (*cmd_in, *filter_complex, distorted + ref + vmaf_filter, *cmd_out) ffmpeg_gen_pipe = subprocess.Popen( chunk.ffmpeg_gen_cmd, stdout=PIPE, stderr=STDOUT ) pipe = subprocess.Popen( cmd, stdin=ffmpeg_gen_pipe.stdout, stdout=PIPE, stderr=STDOUT, universal_newlines=True, ) utility = (ffmpeg_gen_pipe,) process_pipe(pipe, chunk, utility) return fl_path
def per_frame_probe(self, q_list, q, chunk): qfile = chunk.make_q_file(q_list) cmd = self.per_frame_probe_cmd(chunk, q, self.encoder, 1, qfile) pipe = self.make_pipes(chunk.ffmpeg_gen_cmd, cmd) process_pipe(pipe, chunk) fl = self.vmaf_runner.call_vmaf(chunk, self.gen_probes_names(chunk, q)) jsn = VMAF.read_json(fl) vmafs = [x['metrics']['vmaf'] for x in jsn['frames']] return vmafs
def per_frame_probe(q_list, q, chunk, project): qfile = chunk.make_q_file(q_list) cmd = per_frame_probe_cmd(chunk, q, project.ffmpeg_pipe, project.encoder, 1, qfile) pipe = make_pipes(chunk.ffmpeg_gen_cmd, cmd) process_pipe(pipe, chunk) vm = VMAF(n_threads=project.n_threads, model=project.vmaf_path, res=project.vmaf_res, vmaf_filter=project.vmaf_filter) fl = vm.call_vmaf(chunk, gen_probes_names(chunk, q)) jsn = VMAF.read_json(fl) vmafs = [x['metrics']['vmaf'] for x in jsn['frames']] return vmafs
def call_vmaf(self, chunk: Chunk, encoded: Path, vmaf_rate: int = None, fl_path: Path = None): """ Runs vmaf for Av1an """ cmd = '' if fl_path is None: fl_path = chunk.fake_input_path.with_name( encoded.stem).with_suffix('.json') fl = fl_path.as_posix() cmd_in = ('ffmpeg', '-loglevel', 'error', '-y', '-thread_queue_size', '1024', '-hide_banner', '-r', '60', '-i', encoded.as_posix(), '-r', '60', '-i', '-') filter_complex = ('-filter_complex', ) # Change framerate of comparison to framerate of probe n_subsamples = f':n_subsample={vmaf_rate}' if vmaf_rate else '' distorted = f'[0:v]scale={self.res}:flags=bicubic:force_original_aspect_ratio=decrease,setpts=PTS-STARTPTS[distorted];' ref = fr'[1:v]{self.vmaf_filter}scale={self.res}:flags=bicubic:force_original_aspect_ratio=decrease,setpts=PTS-STARTPTS[ref];' vmaf_filter = f"[distorted][ref]libvmaf=log_fmt='json'{n_subsamples}:eof_action=endall:log_path={shlex.quote(fl)}{self.model}{self.n_threads}" cmd_out = ('-f', 'null', '-') cmd = (*cmd_in, *filter_complex, distorted + ref + vmaf_filter, *cmd_out) ffmpeg_gen_pipe = subprocess.Popen(chunk.ffmpeg_gen_cmd, stdout=PIPE, stderr=STDOUT) pipe = subprocess.Popen(cmd, stdin=ffmpeg_gen_pipe.stdout, stdout=PIPE, stderr=STDOUT, universal_newlines=True) process_pipe(pipe, chunk) return fl_path
def vmaf_probe(self, chunk: Chunk, q): """ Calculates vmaf and returns path to json file :param chunk: the Chunk :param q: Value to make probe :param project: the Project :return : path to json file with vmaf scores """ n_threads = self.n_threads if self.n_threads else 12 cmd = self.probe_cmd(chunk, q, self.ffmpeg_pipe, self.encoder, self.probing_rate, n_threads) pipe = self.make_pipes(chunk.ffmpeg_gen_cmd, cmd) process_pipe(pipe, chunk) fl = self.vmaf_runner.call_vmaf(chunk, self.gen_probes_names(chunk, q), vmaf_rate=self.probing_rate) return fl
def vmaf_probe(chunk: Chunk, q, project: Project, probing_rate): """ Calculates vmaf and returns path to json file :param chunk: the Chunk :param q: Value to make probe :param project: the Project :param probing_rate: 1 out of every N frames should be encoded for analysis :return : path to json file with vmaf scores """ n_threads = project.n_threads if project.n_threads else 12 cmd = probe_cmd(chunk, q, project.ffmpeg_pipe, project.encoder, probing_rate, n_threads) pipe = make_pipes(chunk.ffmpeg_gen_cmd, cmd) process_pipe(pipe, chunk) vm = VMAF(n_threads=project.n_threads, model=project.vmaf_path, res=project.vmaf_res, vmaf_filter=project.vmaf_filter) file = vm.call_vmaf(chunk, gen_probes_names(chunk, q), vmaf_rate=probing_rate) return file