nexrender

repository·master·Indexed 23 days ago

https://github.com/inlife/nexrender

An automation tool for Adobe After Effects that enables data-driven, template-based video rendering. Designed for developers to build scalable rendering pipelines and render farms using a modular, CLI-first approach. Includes various action modules for caching, compression, encoding via ffmpeg, and file management.

Tokens
39.5K
Snippets
79
Records
180
Agent score
81%

What's inside nexrender

  1. Introduction to nexrender

    master

    nexrender is a lightweight application designed to automate Adobe After Effects rendering workflows. It enables data-driven, dynamic, and personalized video rendering by using After Effects' aerender command-line interface.

    Key features include:

    • Automated video management, processing, and delivery.
    • Network-oriented project structure supporting render farms.
    • Highly modular architecture with extensive plugin support.
    • CLI-only operation (does not launch the After Effects GUI).
    • Does not require After Effects licenses on worker machines.
    • Open-source and free to use.
  2. Use Assets to replace footage dynamically

    master

    To inject dynamic data into a render, add an assets array to your job. Each asset object includes:

    • src: URI of the asset file.
    • type: The type of asset (e.g., image).
    • layerName: The name of the footage/layer in the After Effects project that this asset should replace.

    When rendering, nexrender downloads/copies the asset and attempts to replace the specified footage entry in the project.

    {
        "template": {
            "src": "file:///d:/documents/myproject.aep",
            "composition": "main"
        },
        "assets": [
            {
                "src": "file:///d:/images/myimage.png",
                "type": "image",
                "layerName": "background.png"
            }
        ]
    }
  3. Understand the difference between init and render

    master

    The @nexrender/core module provides two main methods:

    1. init: Responsible for environment setup. It checks for required Adobe After Effects (AE) patches, automatically adds a render-only license file (unless disabled), and performs other initialization tasks.
    2. render: Responsible for the job lifecycle, including downloading, rendering, processing, and uploading.
  4. Replace footage items in After Effects

    master

    You can dynamically replace existing footage in an After Effects project by defining footage items in the assets array. You specify which asset to use via src and identify the target layer using either layerName or layerIndex. Nexrender downloads/copies the asset to the working directory and replaces the footage in the project just before rendering.

    Key Fields:

    • src: URI pointer to the resource.
    • type: Must be one of image, audio, or video.
    • layerName: The name of the target layer (must include the extension if used for a footage file).
    • layerIndex: Integer index of the layer (starting from 1).
    • composition: The composition containing the layer. Use the -> delimiter for nested compositions (e.g., "FULL_HD->intro->logo comp"). Defaults to * (wildcard).
    • name: Optional filename for the asset.
    • extension: Optional extension to append to the filename (useful if the source lacks one, as AE expects extensions to match content type).
    • sequence: Boolean; if true, the asset is treated as an image sequence.
    • removeOld: Boolean; if true, the original asset is removed from the project (note: this removes all instances of that asset from the project).
    • useOriginal: Boolean (for file:// protocol only); prevents copying to a local temp folder and uses the original file directly.
    {
        "assets": [
            {
                "src": "https://example.com/assets/image.jpg",
                "type": "image",
                "layerName": "MyNicePicture.jpg"
            },
            {
                "src": "https://example.com/assets/jpeg-without-extension",
                "type": "image",
                "layerName": "MyOtherNicePicture.jpg",
                "extension": "jpg"
            },
            {
                "src": "file:///home/assets/audio.mp3",
                "type": "audio",
                "name": "music.mp3",
                "layerIndex": 15
            }
        ]
    }
  5. Use Script Assets to execute custom JSX scripts

    master

    You can execute custom jsx scripts (using ExtendScript Toolkit syntax) just before rendering starts. This allows for dynamic composition restructuring, such as creating/removing layers or adding elements. To use a script asset, set the type to "script" and provide a src URI.

    Key Fields for Script Assets:

    • src: (string) URI pointer to the script resource.
    • type: (string) Must be "script".
    • keyword: (optional string) The name of the configuration object used in JSX to access parameters. Defaults to "NX".
    • parameters: (optional object) Defines dynamically injected parameters.
    • globalDefaultValue: (optional any) An override for the default value of unknown or undefined configuration values.
    {
        "assets": [
            {
                "src": "http://example.com/scripts/myscript.jsx",
                "type": "script"
            }
        ]
    }
  6. Handle Job lifecycle events with the API client

    master

    The object returned by client.addJob() is an EventEmitter that emits events corresponding to the job's lifecycle. Use these to react to rendering progress or errors:

    • created: Emitted when the project has been successfully created on the server.
    • started: Emitted when the rendering process has started.
    • progress: Emitted during rendering. Receives (job, percents) where percents is the completion percentage.
    • finished: Emitted when the rendering is complete.
    • error: Emitted if an error occurs during the job lifecycle.
  7. Modify non-footage data with Data Assets

    master

    Use assets with type: "data" to dynamically change properties (like text, position, or color) in After Effects. This allows for data-driven video generation.

    Key Fields:

    • type: Always "data".
    • layerName / layerIndex: Identifies the target layer.
    • property: The name of the property to change (e.g., "Position", "Source Text", or deep properties like "Effects.Skin_Color.Color").
    • value: The value to set. Can be a primitive or an array (e.g., [500, 100] for Position).
    • expression: An After Effects expression string to be evaluated every frame.
    • composition: The composition where the layer resides (supports -> for nested paths).
    • continueOnMissing: Boolean; if true, bypasses errors if the layer is not found.

    Deep Properties: To access nested properties, use a dot . separator (e.g., "Source Text.font"). If your property name contains a dot and causes parsing collisions, use an arrow -> instead.

    Warning: Errors in your expression will prevent the project from rendering. Check the After Effects binary error messages for details.

    {
        "assets": [
            {
                "type": "data",
                "layerName": "MyNicePicture.jpg",
                "property": "Position",
                "value": [500, 100]
            },
            {
                "type": "data",
                "layerName": "my text field",
                "property": "Source Text",
                "expression": "time > 100 ? 'Bye bye' : 'Hello world'"
            },
            {
                "type": "data",
                "layerName": "my text field",
                "property": "Source Text.font",
                "value": "Arial-BoldItalicMT"
            },
            {
                "type": "data",
                "layerName": "background",
                "property": "Effects.Skin_Color.Color",
                "value": [1, 0, 0]
            },
            {
                "type": "data",
                "layerIndex": 15,
                "property": "Scale",
                "expression": "[time * 0.1, time * 0.1]"
            }
        ]
    }
  8. How nexrender works

    master

    nexrender automates the rendering lifecycle through several mechanisms:

    • Rendering: Utilizes the Adobe After Effects aerender CLI.
    • Compositing: Creates temporary directories, copies projects, and replaces assets with provided ones.
    • Personalization: Leverages AE expressions, scripting, and compositing.
    • Scheduling: Manages projects via a local database accessible through an HTTP API.
    • Network/Farm: Supports rendering projects per machine or using a Multi-Machine Sequence to render a single project across several machines simultaneously.
  9. Configure Job Actions

    master

    Actions allow you to execute tasks at specific stages of the job lifecycle. Actions are order-sensitive within their respective lifecycle stage.

    Available lifecycle stages for actions:

    • predownload: Before assets are downloaded.
    • postdownload: After assets are downloaded.
    • prerender: Just before the actual render starts.
    • postrender: After the render is finished.

    Each action is an object containing a module (the package name or path to a Node.js module) and any specific parameters required by that module.

    {
        "template": {
            "src": "http://example.com/assets/myproject.aep",
            "composition": "main"
        },
        "actions": {
            "postrender": [
                {
                    "module": "@nexrender/action-encode",
                    "preset": "mp4",
                    "output": "encoded.mp4"
                },
                {
                    "module": "@nexrender/action-copy",
                    "input": "encoded.mp4",
                    "output": "d:/mydocuments/results/myresult.mp4"
                }
            ]
        }
    }
  10. Define custom actions in nexrender-worker

    master

    You can define custom actions programmatically within the start method of the @nexrender/worker package. This allows you to execute custom logic during the job lifecycle without needing to package the action as a separate npm module.

    To do this, provide an actions object where the keys correspond to the module field defined in your job's action list. Each value must be a function with the following signature:

    (job, settings, {input, params}, type) => void

    Example usage in the start configuration:

    actions: {
        "custom-action": (job, settings, {input, params}, type) => {
            // Custom action code logic here
        }
    }
    actions: {
        "custom-action": (job, settings, {input, params}, type) => {
            // Custom action code
        }
    }
  11. Install nexrender via npm

    master

    You can install nexrender using npm. Note that the standard npm installation of the binaries does not include all optional plugin packages. If you need specific actions (plugins), you must install them individually using their @nexrender/action-* names.

    To install the CLI and specific actions, use:

    npm i -g @nexrender/cli @nexrender/action-copy @nexrender/action-encode ...