Esempio n. 1
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "aomenc",
                 "--passes=2",
                 "--pass=1",
                 *a.video_params,
                 f"--fpf={c.fpf}.log",
                 "-o",
                 os.devnull,
                 "-",
             ],
         ),
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "aomenc",
                 "--passes=2",
                 "--pass=2",
                 *a.video_params,
                 f"--fpf={c.fpf}.log",
                 "-o",
                 output,
                 "-",
             ],
         ),
     ]
Esempio n. 2
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "rav1e",
                 "-",
                 "-q",
                 "-y",
                 "--first-pass",
                 f"{c.fpf}.stat",
                 *a.video_params,
                 "--output",
                 os.devnull,
             ],
         ),
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "rav1e",
                 "-",
                 "-y",
                 "--second-pass",
                 f"{c.fpf}.stat",
                 *a.video_params,
                 "--output",
                 output,
             ],
         ),
     ]
Esempio n. 3
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'vpxenc', '--passes=2', '--pass=1', *a.video_params,
             f'--fpf={c.fpf}', '-o', os.devnull, '-'
         ]),
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'vpxenc', '--passes=2', '--pass=2', *a.video_params,
             f'--fpf={c.fpf}', '-o', output, '-'
         ])
     ]
Esempio n. 4
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'rav1e', '-', '-q', '-y', '--first-pass', f'{c.fpf}.stat',
             *a.video_params, '--output', os.devnull
         ]),
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'rav1e', '-', '-y', '--second-pass', f'{c.fpf}.stat',
             *a.video_params, '--output', output
         ])
     ]
Esempio n. 5
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'SvtAv1EncApp', '-i', 'stdin', '--progress', '2',
             '--irefresh-type', '2', *a.video_params, '--pass', '1',
             '--stats', f'{c.fpf}.stat', '-b', os.devnull, '-'
         ]),
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'SvtAv1EncApp', '-i', 'stdin', '--progress', '2',
             '--irefresh-type', '2', *a.video_params, '--pass', '2',
             '--stats', f'{c.fpf}.stat', '-b', output, '-'
         ])
     ]
Esempio n. 6
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'x264', '--stitchable', '--log-level', 'error', '--pass', '1',
             '--demuxer', 'y4m', *a.video_params, '-', '--stats',
             f'{c.fpf}.log', '-', '-o', os.devnull
         ]),
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'x264', '--stitchable', '--log-level', 'error', '--pass', '2',
             '--demuxer', 'y4m', *a.video_params, '-', '--stats',
             f'{c.fpf}.log', '-', '-o', output
         ])
     ]
Esempio n. 7
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'x265', '--log-level', 'error', '--no-progress', '--pass', '1',
             '--y4m', '--frames',
             str(c.frames), *a.video_params, '--stats', f'{c.fpf}.log', '-',
             '-o', os.devnull
         ]),
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'x265', '--log-level', 'error', '--pass', '2', '--y4m',
             '--frames',
             str(c.frames), *a.video_params, '--stats', f'{c.fpf}.log', '-',
             '-o', output
         ])
     ]
Esempio n. 8
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'SvtAv1EncApp', '-i', 'stdin', '--progress', '2',
             *a.video_params, '-b', output, '-'
         ])
     ]
Esempio n. 9
0
def compose_aomsplit_first_pass_command(video_path: Path, stat_file: Path, ffmpeg_pipe, video_params, is_vs) -> CommandPair:
    """
    Generates the command for the first pass of the entire video used for aom keyframe split

    :param video_path: the video path
    :param stat_file: the stat_file output
    :param ffmpeg_pipe: the av1an.ffmpeg_pipe with pix_fmt and -ff option
    :param video_params: the video params for aomenc first pass
    :param is_vs: is video_path a vapoursynth script
    :return: ffmpeg, encode
    """

    if is_vs:
        f = compose_vapoursynth_pipe(video_path)
    else:
        f = ['ffmpeg', '-y', '-hide_banner', '-loglevel', 'error', '-i', video_path.as_posix(), *ffmpeg_pipe]
    # removed -w -h from aomenc since ffmpeg filters can change it and it can be added into video_params
    # TODO(n9Mtq4): if an encoder other than aom is being used, video_params becomes the default so -w -h may be needed again


    # Adjust number of threads
    video_params = ' '.join(video_params)

    video_params = re.sub(r'(--threads=[0-9]+)', f'--threads={min(32 ,os.cpu_count() * 3)}', video_params)

    e = ['aomenc', '--passes=2', '--pass=1', *video_params.split(), f'--fpf={stat_file.as_posix()}', '-o', os.devnull, '-']
    return CommandPair(f, e)
Esempio n. 10
0
File: aom.py Progetto: natis1/Pav1n
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             ['aomenc', '--passes=1', *a.video_params, '-o', output, '-']
         )
     ]
Esempio n. 11
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'x264', '--stitchable', '--log-level', 'error', '--demuxer',
             'y4m', *a.video_params, '-', '-o', output
         ])
     ]
Esempio n. 12
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(Encoder.compose_ffmpeg_pipe(a), [
             'x265', '--y4m', '--frames',
             str(c.frames), *a.video_params, '-', '-o', output
         ])
     ]
Esempio n. 13
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             ["rav1e", "-", "-y", *a.video_params, "--output", output],
         )
     ]
Esempio n. 14
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             ["aomenc", "--passes=1", *a.video_params, "-o", output, "-"],
         )
     ]
Esempio n. 15
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(SvtVp9.compose_ffmpeg_raw_pipe(a), [
             'SvtVp9EncApp', '-i', 'stdin', '-n', f'{c.frames}',
             *a.video_params, '-b', output
         ])
     ]
Esempio n. 16
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "x264",
                 "--stitchable",
                 "--log-level",
                 "error",
                 "--pass",
                 "1",
                 "--demuxer",
                 "y4m",
                 *a.video_params,
                 "-",
                 "--stats",
                 f"{c.fpf}.log",
                 "-",
                 "-o",
                 os.devnull,
             ],
         ),
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "x264",
                 "--stitchable",
                 "--log-level",
                 "error",
                 "--pass",
                 "2",
                 "--demuxer",
                 "y4m",
                 *a.video_params,
                 "-",
                 "--stats",
                 f"{c.fpf}.log",
                 "-",
                 "-o",
                 output,
             ],
         ),
     ]
Esempio n. 17
0
File: vvc.py Progetto: natis1/Pav1n
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     yuv_file: str = Vvc.get_yuv_file_path(c).as_posix()
     return [
         CommandPair([], [
             'vvc_encoder', '-c', a.vvc_conf, '-i', yuv_file,
             *a.video_params, '-f',
             str(c.frames), '--InputBitDepth=10', '--OutputBitDepth=10',
             '-b', output
         ])
     ]
Esempio n. 18
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "SvtAv1EncApp",
                 "-i",
                 "stdin",
                 "--progress",
                 "2",
                 "--irefresh-type",
                 "2",
                 *a.video_params,
                 "--pass",
                 "1",
                 "--stats",
                 f"{c.fpf}.stat",
                 "-b",
                 os.devnull,
                 "-",
             ],
         ),
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "SvtAv1EncApp",
                 "-i",
                 "stdin",
                 "--progress",
                 "2",
                 "--irefresh-type",
                 "2",
                 *a.video_params,
                 "--pass",
                 "2",
                 "--stats",
                 f"{c.fpf}.stat",
                 "-b",
                 output,
                 "-",
             ],
         ),
     ]
Esempio n. 19
0
    def per_frame_probe_cmd(self, chunk: Chunk, q, encoder, probing_rate,
                            qp_file) -> CommandPair:
        """
        Generate and return commands for probes at set Q values
        These are specifically not the commands that are generated
        by the user or encoder defaults, since these
        should be faster than the actual encoding commands.
        These should not be moved into encoder classes at this point.
        """
        pipe = [
            "ffmpeg",
            "-y",
            "-hide_banner",
            "-loglevel",
            "error",
            "-i",
            "-",
            "-vf",
            f"select=not(mod(n\\,{probing_rate}))",
            *self.ffmpeg_pipe,
        ]

        probe_name = self.gen_probes_names(chunk,
                                           q).with_suffix(".ivf").as_posix()
        if encoder == "svt_av1":
            params = [
                "SvtAv1EncApp",
                "-i",
                "stdin",
                "--preset",
                "8",
                "--rc",
                "0",
                "--passes",
                "1",
                "--use-q-file",
                "1",
                "--qpfile",
                f"{qp_file.as_posix()}",
            ]

            cmd = CommandPair(pipe, [*params, "-b", probe_name, "-"])
        else:
            print("supported only by SVT-AV1")
            exit()
        """
        elif encoder == 'x265':
            params = [
                'x265', '--log-level', '0', '--no-progress', '--y4m', '--preset',
                'fast', '--crf', f'{q}'
            ]
            cmd = CommandPair(pipe, [*params, '-o', probe_name, '-'])
        """

        return cmd
Esempio n. 20
0
 def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "x265",
                 "--log-level",
                 "error",
                 "--no-progress",
                 "--pass",
                 "1",
                 "--y4m",
                 "--frames",
                 str(c.frames),
                 *a.video_params,
                 "--stats",
                 f"{c.fpf}.log",
                 "-",
                 "-o",
                 os.devnull,
             ],
         ),
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "x265",
                 "--log-level",
                 "error",
                 "--pass",
                 "2",
                 "--y4m",
                 "--frames",
                 str(c.frames),
                 *a.video_params,
                 "--stats",
                 f"{c.fpf}.log",
                 "-",
                 "-o",
                 output,
             ],
         ),
     ]
Esempio n. 21
0
    def probe_cmd(
        self, chunk: Chunk, q, ffmpeg_pipe, encoder, probing_rate, n_threads
    ) -> CommandPair:
        """
        Generate and return commands for probes at set Q values
        These are specifically not the commands that are generated
        by the user or encoder defaults, since these
        should be faster than the actual encoding commands.
        These should not be moved into encoder classes at this point.
        """
        pipe = [
            "ffmpeg",
            "-y",
            "-hide_banner",
            "-loglevel",
            "error",
            "-i",
            "-",
            "-vf",
            f"select=not(mod(n\\,{probing_rate}))",
            *ffmpeg_pipe,
        ]

        probe_name = self.gen_probes_names(chunk, q).with_suffix(".ivf").as_posix()

        if encoder == "aom":
            params = construct_target_quality_command("aom", str(n_threads), str(q))
            cmd = CommandPair(pipe, [*params, "-o", probe_name, "-"])

        elif encoder == "x265":
            params = construct_target_quality_command("x265", str(n_threads), str(q))
            cmd = CommandPair(pipe, [*params, "-o", probe_name, "-"])

        elif encoder == "rav1e":
            params = construct_target_quality_command("rav1e", str(n_threads), str(q))
            cmd = CommandPair(pipe, [*params, "-o", probe_name, "-"])

        elif encoder == "vpx":
            params = construct_target_quality_command("vpx", str(n_threads), str(q))
            cmd = CommandPair(pipe, [*params, "-o", probe_name, "-"])

        elif encoder == "svt_av1":
            params = construct_target_quality_command("svt_av1", str(n_threads), str(q))
            cmd = CommandPair(pipe, [*params, "-b", probe_name])

        elif encoder == "svt_vp9":
            params = construct_target_quality_command("svt_vp9", str(n_threads), str(q))
            # TODO: pipe needs to output rawvideo
            cmd = CommandPair(pipe, [*params, "-b", probe_name, "-"])

        elif encoder == "x264":
            params = construct_target_quality_command("x264", str(n_threads), str(q))
            cmd = CommandPair(pipe, [*params, "-o", probe_name, "-"])

        return cmd
Esempio n. 22
0
def per_frame_probe_cmd(chunk: Chunk, q, ffmpeg_pipe, encoder, probing_rate,
                        qp_file) -> CommandPair:
    """
    Generate and return commands for probes at set Q values
    These are specifically not the commands that are generated
    by the user or encoder defaults, since these
    should be faster than the actual encoding commands.
    These should not be moved into encoder classes at this point.
    """
    pipe = [
        'ffmpeg', '-y', '-hide_banner', '-loglevel', 'error', '-i', '-', '-vf',
        f'select=not(mod(n\\,{probing_rate}))', *ffmpeg_pipe
    ]

    probe_name = gen_probes_names(chunk, q).with_suffix('.ivf').as_posix()
    if encoder == 'svt_av1':
        params = [
            'SvtAv1EncApp', '-i', 'stdin', '--preset', '8', '--rc', '0',
            '--passes', '1', '--use-q-file', '1', '--qpfile',
            f'{qp_file.as_posix()}'
        ]

        cmd = CommandPair(pipe, [*params, '-b', probe_name, '-'])

    elif encoder == 'x265':
        params = [
            'x265', '--log-level', '0', '--no-progress', '--y4m', '--preset',
            'fast', '--crf', f'{q}'
        ]
        cmd = CommandPair(pipe, [*params, '-o', probe_name, '-'])

    else:
        print('supported only by SVT-AV1 and x265')
        exit()

    return cmd
Esempio n. 23
0
def get_scene_scores(chunk, ffmpeg_pipe):
    """
    Run ffmpeg scenedetection filter to get average amount of motion in scene
    """

    pipecmd = [
        'ffmpeg', '-y', '-hide_banner', '-loglevel', 'error', '-i', '-',
        *ffmpeg_pipe
    ]

    params = [
        'ffmpeg', '-hide_banner', '-i', '-', '-vf',
        'fps=fps=5,scale=\'min(960,iw)\':-1,hqdn3d=4:4:0:0,select=\'gte(scene,0)\',metadata=print',
        '-f', 'null', '-'
    ]
    cmd = CommandPair(pipecmd, [*params])
    pipe = make_pipes(chunk.ffmpeg_gen_cmd, cmd)

    history = []

    while True:
        line = pipe.stdout.readline().strip()
        if len(line) == 0 and pipe.poll() is not None:
            break
        if len(line) == 0:
            continue
        if line:
            history.append(line)

    if pipe.returncode != 0 and pipe.returncode != -2:
        print(f"\n:: Encoder in getting scene score {pipe.returncode}")
        print(f"\n:: Chunk: {chunk.index}")
        print('\n'.join(history))

    pp = pprint.PrettyPrinter(indent=2).pprint

    scores = [x for x in history if 'score' in x]

    results = []
    for x in scores:
        matches = re.findall(r"=\s*([\S\s]+)", x)
        var = float(matches[-1])
        if var < 0.3:
            results.append(var)

    result = (round(np.average(results), 4))

    pp(result * 1000)
Esempio n. 24
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "x265",
                 "--y4m",
                 "--frames",
                 str(c.frames),
                 *a.video_params,
                 "-",
                 "-o",
                 output,
             ],
         )
     ]
Esempio n. 25
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "SvtAv1EncApp",
                 "-i",
                 "stdin",
                 "--progress",
                 "2",
                 *a.video_params,
                 "-b",
                 output,
             ],
         )
     ]
Esempio n. 26
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             SvtVp9.compose_ffmpeg_raw_pipe(a),
             [
                 "SvtVp9EncApp",
                 "-i",
                 "stdin",
                 "-n",
                 f"{c.frames}",
                 *a.video_params,
                 "-b",
                 output,
             ],
         )
     ]
Esempio n. 27
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             Encoder.compose_ffmpeg_pipe(a),
             [
                 "x264",
                 "--stitchable",
                 "--log-level",
                 "error",
                 "--demuxer",
                 "y4m",
                 *a.video_params,
                 "-",
                 "-o",
                 output,
             ],
         )
     ]
Esempio n. 28
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     return [
         CommandPair(
             [Encoder.compose_ffmpeg_pipe(a)],
             [
                 "vvc_encoder",
                 "-c",
                 a.vvc_conf,
                 "-i",
                 "-",
                 *a.video_params,
                 "-f",
                 str(c.frames),
                 "--InputBitDepth=10",
                 "--OutputBitDepth=10",
                 "-b",
                 output,
             ],
         )
     ]
Esempio n. 29
0
 def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
     yuv_file: str = Vvc.get_yuv_file_path(c).as_posix()
     return [
         CommandPair(
             [],
             [
                 "vvc_encoder",
                 "-c",
                 a.vvc_conf,
                 "-i",
                 yuv_file,
                 *a.video_params,
                 "-f",
                 str(c.frames),
                 "--InputBitDepth=10",
                 "--OutputBitDepth=10",
                 "-b",
                 output,
             ],
         )
     ]
Esempio n. 30
0
def probe_cmd(chunk: Chunk, q, ffmpeg_pipe, encoder, probing_rate,
              n_threads) -> CommandPair:
    """
    Generate and return commands for probes at set Q values
    These are specifically not the commands that are generated
    by the user or encoder defaults, since these
    should be faster than the actual encoding commands.
    These should not be moved into encoder classes at this point.
    """
    pipe = [
        'ffmpeg', '-y', '-hide_banner', '-loglevel', 'error', '-i', '-', '-vf',
        f'select=not(mod(n\\,{probing_rate}))', *ffmpeg_pipe
    ]

    probe_name = gen_probes_names(chunk, q).with_suffix('.ivf').as_posix()

    if encoder == 'aom':
        params = [
            'aomenc', '--passes=1', f'--threads={n_threads}',
            '--tile-columns=1', '--end-usage=q', '-b', '8', '--cpu-used=6',
            f'--cq-level={q}'
        ]
        cmd = CommandPair(pipe, [*params, '-o', probe_name, '-'])

    elif encoder == 'x265':
        params = [
            'x265', '--log-level', '0', '--no-progress', '--y4m',
            '--frame-threads', f'{n_threads}', '--preset', 'fast', '--crf',
            f'{q}'
        ]
        cmd = CommandPair(pipe, [*params, '-o', probe_name, '-'])

    elif encoder == 'rav1e':
        params = [
            'rav1e', '-y', '-s', '10', '--threads', f'{n_threads}', '--tiles',
            '32', '--quantizer', f'{q}'
        ]
        cmd = CommandPair(pipe, [*params, '-o', probe_name, '-'])

    elif encoder == 'vpx':
        params = [
            'vpxenc', '-b', '10', '--profile=2', '--passes=1', '--pass=1',
            '--codec=vp9', f'--threads={n_threads}', '--cpu-used=9',
            '--end-usage=q', f'--cq-level={q}', '--row-mt=1'
        ]
        cmd = CommandPair(pipe, [*params, '-o', probe_name, '-'])

    elif encoder == 'svt_av1':
        params = [
            'SvtAv1EncApp', '-i', 'stdin', '--lp', f'{n_threads}', '--preset',
            '8', '--rc', '0', '--qp', f'{q}'
        ]
        cmd = CommandPair(pipe, [*params, '-b', probe_name, '-'])

    elif encoder == 'svt_vp9':
        params = [
            'SvtVp9EncApp', '-i', 'stdin', '--lp', f'{n_threads}', '-enc-mode',
            '8', '-q', f'{q}'
        ]
        # TODO: pipe needs to output rawvideo
        cmd = CommandPair(pipe, [*params, '-b', probe_name, '-'])

    elif encoder == 'x264':
        params = [
            'x264', '--log-level', 'error', '--demuxer', 'y4m', '-',
            '--no-progress', '--threads', f'{n_threads}', '--preset', 'medium',
            '--crf', f'{q}'
        ]
        cmd = CommandPair(pipe, [*params, '-o', probe_name, '-'])

    return cmd