To export a Manim animation with a transparent background you have to pass the CLI flag -t (or its long form –transparent) into the terminal.
Let’s go over what that means and how to do it within VS Code.
How to export Manim video with a transparent background with Visual Studio Code?
Every time you run a Manim Python file in Visual Studio Code you will see the terminal tab open up at the bottom. This tab acts just like the MacOS terminal or Windows CMD.
This is where you need to pass the -t flag to export a Manim video with a transparent background.
Here’s the Terminal command:
manim -t [FILE NAME] [SCENE NAME]
Example:
manim -t manim_file.py hello
“manim_file.py” is the name of the Manim Python file where I write code to create Manim animations and “hello” is the name of the scene that I want to export with the transparent background.
This will not work if you haven’t navigated to the directory where your Manim Python file is located on your computer through the terminal.
So let’s find out how to get there.
How to navigate to the Manim Python file directory through the Terminal
First, here are a few useful Terminal commands:
cd
– “change directory” – in very simple terms it lets you open a folder.
If you type only cd
it will take you to your home directory.
Also, you can only change to a directory (or folder) that is inside the current directory (or folder) that you’re in.
For instance, if you’re inside of your Downloads folder you can’t change to your Desktop folder because there is no Desktop folder inside of your Downloads folder.
Example 1:
cd Desktop
Will take you to the Desktop folder if you’re inside a folder that houses your Desktop folder.
Example 2:
cd ..
This will take you to your parent directory. Essentially, to a folder that houses the folder that you’re currently in.
For instance, if you’re inside of your Desktop folder putting cd .. in the Terminal will take you back to your User folder.
pwd
– “print working directory” – show where you are in your file system.
Example:
Here I put pwd inside the Terminal and it showed me that I’m currently in the /Users/dog folder.
ls
– “list” (lists all the available folders that are in your current directory, shows where you can go next).
Example:
Here I put ls in the Terminal and it showed me all the folders that are in the current folder that I’m in. I’m currently inside of the /Users/dog folder and these are all the folders that are available to me inside that folder.
Using these three commands you can navigate your file system and get to your Manim Python file location to be able to export it with a transparent background.
For example, let’s say that:
- Your Manim Python file is inside a folder called “Manim” on your Desktop
- Your Manim Python file is called “Manim_python_file.py”
- The scene you want to export with a transparent background is called “Hello”
This is how you would export it with a transparent background:
First, check your current directory by typing pwd. Here I saw that my current directory is my C:\Users\dog.
- Run your Manim Python code within VS Code
- Go to the Terminal tab that opens up at the bottom and type:
- cd Desktop
- cd Manim
- manim -t Manim_python_file.py hello
Then, you’ll find the video with the transparent background inside the location where your Manim python file is located.
Let me help you learn Manim
If you want to skip the headache of trying to learn Manim from a bunch of scattered information, I put together a comprehensive 3-hour Manim course for complete beginners.
It will give you all the foundational skills you need to start creating stunning animations with code.
Enroll In Manim Course For Beginners