Skip to content

Commit

Permalink
Merge pull request 3b1b#1994 from 3b1b/video-work
Browse files Browse the repository at this point in the history
Several bug fixes
  • Loading branch information
3b1b committed Feb 15, 2023
2 parents 41f0239 + 557cb66 commit d842858
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manimlib/animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def begin(self) -> None:
# preserved, since calling align_data will potentially
# change the structure of both arguments
self.target_copy = self.target_mobject.copy()
self.mobject.align_data_and_family(self.target_copy)
self.mobject.align_data_and_family(self.target_copy)
super().begin()
if not self.mobject.has_updaters:
self.mobject.lock_matching_data(
Expand Down
3 changes: 2 additions & 1 deletion manimlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,12 @@ def get_file_writer_config(args: Namespace, custom_config: dict) -> dict:
result["video_codec"] = args.vcodec
elif args.transparent:
result["video_codec"] = 'prores_ks'
result["pixel_format"] = ''
elif args.gif:
result["video_codec"] = ''

if args.pix_fmt:
result["pix_fmt"] = args.pix_fmt
result["pixel_format"] = args.pix_fmt

return result

Expand Down
5 changes: 2 additions & 3 deletions manimlib/mobject/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def __init__(
z_axis_config: dict = dict(),
z_normal: Vect3 = DOWN,
depth: float = 6.0,
num_axis_pieces: int = 20,
flat_stroke: bool = False,
**kwargs
):
Axes.__init__(self, x_range, y_range, **kwargs)
Expand All @@ -533,8 +533,7 @@ def __init__(
self.axes.add(self.z_axis)
self.add(self.z_axis)

for axis in self.axes:
axis.insert_n_curves(num_axis_pieces - 1)
self.set_flat_stroke(flat_stroke)

def get_all_ranges(self) -> list[Sequence[float]]:
return [self.x_range, self.y_range, self.z_range]
Expand Down
4 changes: 2 additions & 2 deletions manimlib/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ def __getattr__(self, method_name: str):

if (self.is_chaining and has_overridden_animation) or self.overridden_animation:
raise NotImplementedError(
"Method chaining is currently not supported for "
"Method chaining is currently not supported for " + \
"overridden animations"
)

Expand Down Expand Up @@ -2213,7 +2213,7 @@ def set_anim_args(self, **kwargs):

if not self.can_pass_args:
raise ValueError(
"Animation arguments can only be passed by calling ``animate`` "
"Animation arguments can only be passed by calling ``animate`` " + \
"or ``set_anim_args`` and can only be passed once",
)

Expand Down
2 changes: 1 addition & 1 deletion manimlib/mobject/mobject_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def turn_animation_into_updater(
the updater will be popped uplon completion
"""
mobject = animation.mobject
animation.update_config(**kwargs)
animation.update_rate_info(**kwargs)
animation.suspend_mobject_updating = False
animation.begin()
animation.total_time = 0
Expand Down
3 changes: 3 additions & 0 deletions manimlib/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ def add_smooth_cubic_curve_to(self, handle: Vect3, point: Vect3) -> Self:
else:
new_handle = self.get_reflection_of_last_handle()
self.add_cubic_bezier_curve_to(new_handle, handle, point)
return self

def has_new_path_started(self) -> bool:
points = self.get_points()
Expand Down Expand Up @@ -898,6 +899,8 @@ def align_points(self, vmobject: VMobject) -> Self:
self.has_same_shape_as(vmobject)
if match_tris:
vmobject.triangulation = self.triangulation
for mob in [self, vmobject]:
mob.get_joint_products()
return self

for mob in self, vmobject:
Expand Down
10 changes: 9 additions & 1 deletion manimlib/scene/scene_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def __init__(
progress_description_len: int = 40,
video_codec: str = "libx264",
pixel_format: str = "yuv420p",
saturation: float = 1.7,
gamma: float = 1.2,
):
self.scene: Scene = scene
self.write_to_movie = write_to_movie
Expand All @@ -67,6 +69,8 @@ def __init__(
self.progress_description_len = progress_description_len
self.video_codec = video_codec
self.pixel_format = pixel_format
self.saturation = saturation
self.gamma = gamma

# State during file writing
self.writing_process: sp.Popen | None = None
Expand Down Expand Up @@ -254,6 +258,10 @@ def open_movie_pipe(self, file_path: str) -> None:
fps = self.scene.camera.fps
width, height = self.scene.camera.get_pixel_shape()

vf_arg = 'vflip'
if self.pixel_format.startswith("yuv"):
vf_arg += f',eq=saturation={self.saturation}:gamma={self.gamma}'

command = [
FFMPEG_BIN,
'-y', # overwrite output file if it exists
Expand All @@ -262,7 +270,7 @@ def open_movie_pipe(self, file_path: str) -> None:
'-pix_fmt', 'rgba',
'-r', str(fps), # frames per second
'-i', '-', # The input comes from a pipe
'-vf', 'vflip',
'-vf', vf_arg,
'-an', # Tells FFMPEG not to expect any audio
'-loglevel', 'error',
]
Expand Down

0 comments on commit d842858

Please sign in to comment.