diff --git a/ovgenpy/outputs.py b/ovgenpy/outputs.py index 191b50f..fbddd90 100644 --- a/ovgenpy/outputs.py +++ b/ovgenpy/outputs.py @@ -41,28 +41,7 @@ def register_output(config_t: Type[OutputConfig]): return inner -FFMPEG = 'ffmpeg' -FFPLAY = 'ffplay' - - -assert RGB_DEPTH == 3 -def ffmpeg_input_video(cfg: 'Config') -> List[str]: - fps = cfg.fps - width = cfg.render.width - height = cfg.render.height - - return [f'-f rawvideo -pixel_format rgb24 -video_size {width}x{height}', - f'-framerate {fps}', - '-i -'] - - -def ffmpeg_input_audio(audio_path: str) -> List[str]: - return ['-i', audio_path] - - -FFMPEG_OUTPUT_VIDEO_DEFAULT = '-c:v libx264 -crf 18 -bf 2 -flags +cgop -pix_fmt yuv420p -movflags faststart' -FFMPEG_OUTPUT_AUDIO_DEFAULT = '-c:a aac -b:a 384k' - +# FFmpeg input format class _FFmpegCommand: def __init__(self, templates: List[str], ovgen_cfg: 'Config'): @@ -82,7 +61,8 @@ class _FFmpegCommand: if process_args is None: process_args = [] - return subprocess.Popen(self._generate_args() + process_args, stdin=subprocess.PIPE, **kwargs) + return subprocess.Popen(self._generate_args() + process_args, + stdin=subprocess.PIPE, **kwargs) def _generate_args(self) -> List[str]: return [arg @@ -90,6 +70,21 @@ class _FFmpegCommand: for arg in shlex.split(template)] +assert RGB_DEPTH == 3 +def ffmpeg_input_video(cfg: 'Config') -> List[str]: + fps = cfg.fps + width = cfg.render.width + height = cfg.render.height + + return [f'-f rawvideo -pixel_format rgb24 -video_size {width}x{height}', + f'-framerate {fps}', + '-i -'] + + +def ffmpeg_input_audio(audio_path: str) -> List[str]: + return ['-i', audio_path] + + class ProcessOutput(Output): def open(self, popen: subprocess.Popen): self._popen = popen @@ -109,10 +104,12 @@ class ProcessOutput(Output): @dataclass class FFmpegOutputConfig(OutputConfig): path: str - video_template: str = FFMPEG_OUTPUT_VIDEO_DEFAULT - audio_template: str = FFMPEG_OUTPUT_AUDIO_DEFAULT + video_template: str = '-c:v libx264 -crf 18 -bf 2 -flags +cgop -pix_fmt yuv420p -movflags faststart' + audio_template: str = '-c:a aac -b:a 384k' +FFMPEG = 'ffmpeg' + @register_output(FFmpegOutputConfig) class FFmpegOutput(ProcessOutput): def __init__(self, ovgen_cfg: 'Config', cfg: FFmpegOutputConfig): @@ -129,6 +126,8 @@ class FFplayOutputConfig(OutputConfig): audio_template: str = '-c:a copy' +FFPLAY = 'ffplay' + @register_output(FFplayOutputConfig) class FFplayOutput(ProcessOutput): def __init__(self, ovgen_cfg: 'Config', cfg: FFplayOutputConfig):