能否通过CMD命令行调用Adobe After Effects脚本生成指定视频?求示例
Absolutely! While After Effects doesn’t natively accept raw parameters like red HelloWorld directly in the command line, you can achieve this by pairing a JSX script (After Effects’ native scripting language) with a CMD command that passes your desired parameters to the script. Here’s a complete, working example to make it happen:
Step 1: Create the JSX Script
First, make a new text file named generateVideo.jsx and paste the following code. This script reads your command-line arguments, builds a composition with the specified background color and text, then renders the final video:
// Check if required arguments are provided if ($.argv.length < 3) { alert("Missing arguments! Usage: afterfx.exe -r generateVideo.jsx [color] [text]"); app.quit(); } // Pull arguments from command line const bgColorName = $.argv[1].toLowerCase(); const displayText = $.argv[2]; // Map common color names to RGB values (add more as needed) const colorMap = { red: [1, 0, 0], blue: [0, 0, 1], green: [0, 1, 0], white: [1, 1, 1], black: [0, 0, 0] }; // Default to red if color name is unrecognized const bgColor = colorMap[bgColorName] || colorMap.red; // Create a new AE project app.newProject(); // Set up a 1920x1080 composition (10 seconds, 30fps) const comp = app.project.items.addComp( "HelloWorldComp", 1920, 1080, 1, 10, 30 ); // Add solid background layer with chosen color const bgSolid = comp.layers.addSolid( new Color(bgColor[0], bgColor[1], bgColor[2]), "Background", comp.width, comp.height, 1 ); // Add and style the text layer const textLayer = comp.layers.addText(displayText); // Center text on screen textLayer.property("Position").setValue([comp.width/2, comp.height/2]); // Customize text appearance (adjust font/size as you like) const textProp = textLayer.property("Source Text").value; textProp.fontSize = 72; textProp.fillColor = new Color(1,1,1); // White text textLayer.property("Source Text").setValue(textProp); // Configure render queue for MP4 output const renderQueue = app.project.renderQueue.items.add(comp); const outputModule = renderQueue.outputModules[1]; outputModule.applyTemplate("H.264"); // Set your desired output path (create this folder first!) outputModule.file = new File("C:\\AE_Renders\\HelloWorldOutput.mp4"); // Start rendering renderQueue.render(); // Uncomment below to auto-close AE after rendering // app.quit();
Step 2: Run the CMD Command
Open Command Prompt and execute this command (adjust paths to match your system setup):
"C:\Program Files\Adobe\Adobe After Effects 2024\Support Files\afterfx.exe" -r "C:\Path\To\Your\generateVideo.jsx" red "Hello World"
Command Breakdown:
"C:\...\afterfx.exe": Full path to your After Effects executable (skip quotes if the path has no spaces).-r: Tells After Effects to run a script instead of opening the UI normally."C:\Path\To\Your\generateVideo.jsx": Full path to the JSX script you created.red: The background color (matches the names in the script’scolorMap)."Hello World": The text to display (wrap in quotes if it includes spaces).
Key Notes:
- Render Folder: Make sure the output folder (like
C:\AE_Renders) exists before running the command—AE won’t create it automatically. - Color Expansion: Add more entries to the
colorMapobject in the script to support additional colors (e.g.,purple: [0.5, 0, 0.5]). - AE Version: Update the path to
afterfx.exeto match your installed version (e.g., 2023, 2022). - Auto-Quit: Uncomment
app.quit();in the script if you want After Effects to close once rendering finishes.
This setup will generate a 10-second MP4 video with a red background and centered white "Hello World" text—all via the command line, just as you requested!
内容的提问来源于stack exchange,提问作者Sharon Watinsan




