Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option -i to save as gif #529

Merged
merged 3 commits into from Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions manimlib/config.py
Expand Up @@ -52,6 +52,11 @@ def parse_cli():
action="store_true",
help="Save each frame as a png",
),
parser.add_argument(
"-i", "--save_as_gif",
action="store_true",
help="Save the video as gif",
),
parser.add_argument(
"-f", "--show_file_in_finder",
action="store_true",
Expand Down Expand Up @@ -161,6 +166,7 @@ def get_configuration(args):
"write_to_movie": args.write_to_movie or not args.save_last_frame,
"save_last_frame": args.save_last_frame,
"save_pngs": args.save_pngs,
"save_as_gif": args.save_as_gif,
# If -t is passed in (for transparent), this will be RGBA
"png_mode": "RGBA" if args.transparent else "RGB",
"movie_file_extension": ".mov" if args.transparent else ".mp4",
Expand Down
20 changes: 18 additions & 2 deletions manimlib/scene/scene_file_writer.py
Expand Up @@ -27,6 +27,7 @@ class SceneFileWriter(object):
"png_mode": "RGBA",
"save_last_frame": False,
"movie_file_extension": ".mp4",
"gif_file_extension": ".gif",
"livestreaming": False,
"to_twitch": False,
"twitch_key": None,
Expand Down Expand Up @@ -69,6 +70,12 @@ def init_output_directories(self):
file_name, self.movie_file_extension
)
)
self.gif_file_path = os.path.join(
movie_dir,
add_extension_if_not_present(
file_name, self.gif_file_extension
)
)
self.partial_movie_directory = guarantee_existance(os.path.join(
movie_dir,
self.get_partial_movie_directory(),
Expand Down Expand Up @@ -299,10 +306,19 @@ def combine_movie_files(self):
'-f', 'concat',
'-safe', '0',
'-i', file_list,
'-c', 'copy',
'-loglevel', 'error',
movie_file_path

]
if not self.save_as_gif:
commands +=[
'-c', 'copy',
movie_file_path
]
if self.save_as_gif:
movie_file_path=self.gif_file_path
commands +=[
movie_file_path,
]
if not self.includes_sound:
commands.insert(-1, '-an')

Expand Down