mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Add CLI args for setting video codec and pixel forma
This commit is contained in:
parent
12dc124d72
commit
e1bb360e0b
2 changed files with 33 additions and 14 deletions
|
@ -93,6 +93,14 @@ def parse_cli():
|
|||
action="store_true",
|
||||
help="Render to a movie file with an alpha channel",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--vcodec",
|
||||
help="Video codec to use with ffmpeg",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--pix_fmt",
|
||||
help="Pixel format to use for the output of ffmpeg, defaults to `yuv420p`",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-q", "--quiet",
|
||||
action="store_true",
|
||||
|
@ -392,7 +400,7 @@ def get_output_directory(args: Namespace, custom_config: dict) -> str:
|
|||
|
||||
|
||||
def get_file_writer_config(args: Namespace, custom_config: dict) -> dict:
|
||||
return {
|
||||
result = {
|
||||
"write_to_movie": not args.skip_animations and args.write_file,
|
||||
"break_into_partial_movies": custom_config["break_into_partial_movies"],
|
||||
"save_last_frame": args.skip_animations and args.write_file,
|
||||
|
@ -408,6 +416,18 @@ def get_file_writer_config(args: Namespace, custom_config: dict) -> dict:
|
|||
"quiet": args.quiet,
|
||||
}
|
||||
|
||||
if args.vcodec:
|
||||
result["video_codec"] = args.vcodec
|
||||
elif args.transparent:
|
||||
result["video_codec"] = 'prores_ks'
|
||||
elif args.gif:
|
||||
result["video_codec"] = ''
|
||||
|
||||
if args.pix_fmt:
|
||||
result["pix_fmt"] = args.pix_fmt
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_window_config(args: Namespace, custom_config: dict, camera_config: dict) -> dict:
|
||||
# Default to making window half the screen size
|
||||
|
|
|
@ -47,6 +47,8 @@ class SceneFileWriter(object):
|
|||
quiet: bool = False,
|
||||
total_frames: int = 0,
|
||||
progress_description_len: int = 40,
|
||||
video_codec: str = "libx264",
|
||||
pixel_format: str = "yuvj422p",
|
||||
):
|
||||
self.scene: Scene = scene
|
||||
self.write_to_movie = write_to_movie
|
||||
|
@ -63,6 +65,8 @@ class SceneFileWriter(object):
|
|||
self.quiet = quiet
|
||||
self.total_frames = total_frames
|
||||
self.progress_description_len = progress_description_len
|
||||
self.video_codec = video_codec
|
||||
self.pixel_format = pixel_format
|
||||
|
||||
# State during file writing
|
||||
self.writing_process: sp.Popen | None = None
|
||||
|
@ -262,19 +266,10 @@ class SceneFileWriter(object):
|
|||
'-an', # Tells FFMPEG not to expect any audio
|
||||
'-loglevel', 'error',
|
||||
]
|
||||
if self.movie_file_extension == ".mov":
|
||||
# This is if the background of the exported
|
||||
# video should be transparent.
|
||||
command += [
|
||||
'-vcodec', 'prores_ks',
|
||||
]
|
||||
elif self.movie_file_extension == ".gif":
|
||||
command += []
|
||||
else:
|
||||
command += [
|
||||
'-vcodec', 'libx264',
|
||||
'-pix_fmt', 'yuv420p',
|
||||
]
|
||||
if self.video_codec:
|
||||
command += ['-vcodec', self.video_codec]
|
||||
if self.pixel_format:
|
||||
command += ['-pix_fmt', self.pixel_format]
|
||||
command += [self.temp_file_path]
|
||||
self.writing_process = sp.Popen(command, stdin=sp.PIPE)
|
||||
|
||||
|
@ -287,6 +282,10 @@ class SceneFileWriter(object):
|
|||
)
|
||||
self.set_progress_display_description()
|
||||
|
||||
def use_fast_encoding(self):
|
||||
self.video_codec = "libx264rgb"
|
||||
self.pixel_format = "rgb32"
|
||||
|
||||
def begin_insert(self):
|
||||
# Begin writing process
|
||||
self.write_to_movie = True
|
||||
|
|
Loading…
Add table
Reference in a new issue