There are still the optional arguments:
"-i", "--save_as_gif" for saving scences into gif.
This feature was added to 3b1b's repo here https://github.com/3b1b/manim/commit/c42ae8a55bb2f1ef8259a719f17eaf519c46f3f8
and removed here https://github.com/3b1b/manim/commit/61bb4944fad2ee889145bbf8a3253fb07c71bf7d where Grant wrote:
It seems strange to me that the "-c copy" line breaks things when you're trying to make a gif, is there a more natural way to address whatever the underlying issue is here? In a perfect world, we should be able to make things so that if you set "movie_file_extension" in the SceneFileWriter to ".gif", it figures out the settings it needs and renders the gif. Having a bunch of extra attributes for gifs strikes me as redundant.
So my idea would be to add to manim/scene/scene_file_writer.py something like
if self.save_as_gif:
os.system("ffmpeg -i PATH_TO_VIDEO/input.mp4 output.gif")
This way, the video get's first rendered to mp4 and then to gif, but I think that's the most forward option.
This is indeed the best solution for exporting gifs. I think it also needs to support controlling the bit rate and setting the default bit rate.
In some cases, high-resolution and high-bitrate gifs may not look good.
Here is a first idea of the implementation:
from manim import *
class WriteStuff(Scene):
def construct(self):
dot = Dot()
circ = Circle()
squ = Square()
self.play(Write(dot))
self.play(Write(circ))
self.play(Write(squ))
from pathlib import Path
if __name__ == "__main__":
scene_name= "WriteStuff"
script = f"{Path(__file__).resolve()}"
os.system(f"manim -i -l -p -c 'BLACK' --video_dir ~/Downloads/ " + script + " " + scene_name)
os.system("ffmpeg -i ~/Downloads/" + scene_name + ".mp4" + " "+ "~/Downloads/"+ scene_name + ".gif")

with an adjusted output dir in scene_file_writer.py:
# Output directories and files
def init_output_directories(self):
module_directory = self.output_directory or self.get_default_module_directory()
scene_name = self.file_name or self.get_default_scene_name()
if self.save_last_frame:
image_dir = guarantee_existence(os.path.join(
dirs.VIDEO_DIR,
#module_directory, #removed here
#scene_name,
#"images",
))
self.image_file_path = os.path.join(
image_dir,
add_extension_if_not_present(scene_name, ".png")
)
if self.write_to_movie:
movie_dir = guarantee_existence(os.path.join(
dirs.VIDEO_DIR,
# module_directory, #removed here
# scene_name,
# self.get_resolution_directory(),
))
I'm not sure I follow your original post. Are you saying the -i flag is broken? If so, yes we should fix it. Grant's comment is about the -c flag so I'm not sure how that is related.
@leotrs Yes, --save_as_gif seems to be broken (as it is not used in the code at all).
I think that the idea of Grant was to actually use a flag to set the extension of the movie file generated (maybe this is the -c that he is talking about) , and then to use this flag with gifto create a .gif.
I am not sure that this is the correct way to do that. We should (re ?) implement --save_as_gif.
Agreed, let's just implement -i for now. Any takers?
Sounds good to me.
I also want to point out that having a flag that changes the file type of the output would be useful for add-ons. For example, my PowerPoint add-on adds the --save_as_pptx flag, which could be removed in favor of adding .pptx as a valid output format. E.g. `-c [ mp4 | mov | gif | pptx | ... ]
Agreed, let's just implement
-ifor now. Any takers?
I re-added it in the fix-gifs branch some time ago.
It can be merged, unless it can be implemented in a better way.
@Aathish04, I just came across this again when working on #98. Any quick fixes we can PR here? If I understand this part of the code correctly, it seems the member gif_file_path is correctly set in scene_file_writer.py (or at least it's correctly set in the latest commit of #98...), but it's just never used.
@leotrs Yeah, I just made one.
Most helpful comment
Sounds good to me.
I also want to point out that having a flag that changes the file type of the output would be useful for add-ons. For example, my PowerPoint add-on adds the
--save_as_pptxflag, which could be removed in favor of adding.pptxas a valid output format. E.g. `-c [ mp4 | mov | gif | pptx | ... ]