Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

You can create some custom Python hook files to do some custom scripting.

In order to find the hook files the file name must match exactly. Please see list below.

Script

Description

pre_render.py

Gets executed before each transcoding task

post_render.py

Gets executed after each transcoding task

The software follows this order looking for Python Hook files.

  1. directory defined in the DASELEMENT_RESOURCE environment variable

  2. your local .das-element folder (for Linux: ~/.das-element/scripts/hooks or for Windows %homepath%/.das-element/scripts/hooks)

Pre Render Hook

The input is the resolver data dictionary which will be used to resolve the path pattern. You can modify it here before the transcoding task gets processed.

You will need to return the same dictionary with your changes included.

In the example below, in order to resolve a path pattern like <custom.dependecy> you need to add some value for the custom data. If that is not provided the resolve would otherwise fail if you re-render the proxies and there is no main task to provide the dependency which we normally would get from the post render hook after sending the task to the render farm.

# Example file if you use some custom dependency in your submission scripts.
# To resolve a path pattern like <custom.dependecy> you need to add some value for the custom data.
# If that is not provided the resolve would otherwise fail if you re-render the proxies and there is no main task to provide the depdency.

import sys

def main(*args):
    data = args[0]
    # make sure to set some value for the dependency.
    # otherwise it will failed when resolving the path pattern '<custom.dependency>'
    if not data['template_values'].get('custom'):
        data['template_values']['custom'] = {'dependency': ''}
    return data

if __name__ == '__main__':
    main(sys.argv[1:])

Post Render Hook

The input is the output of the process called by the custom command task.

You will have to return a Dictionary which will be added as custom to the resolver data and can later be accessed in the Path Builder. return {'dependency': job_id} can later be resolved with <custom.dependency>

# Example Python script for post render hook (post_render.py):
import sys
import re

def main(*args):
    # args[0] is the output from the process calling the 'exec' and 'params'
    job_output = args[0]
    job_id = ''
    if job_output:
        match = re.search(r'JobID=([a-zA-Z0-9]*)', job_output)
        if match:
            job_id = match.group(1)
        print('Job ID: {}'.format(job_id))
    # returns data that can later be access as "custom"
    # in this example: <custom.dependency>
    return {'dependency': job_id}

if __name__ == '__main__':
    main(sys.argv[1:])

Pre Ingest Load

This hook can be used to parse the file paths to set tags and the category from the file path before the items are loaded into the ingest list. These tags and the category will automatically populate the ingest list items.

The input is a List of Dictionaries and the same has to be returned from the function.

# Example Python script for pre ingest load hook (pre_ingest_load.py):
import sys
import re

TAGS = ['assets', 'environments', 'hdri', 'photogrammetry', 'texture']

def main(*args):
    # args will be a List of Dicts:
    # [{'path': '/path/to/some/file.mov', 'category': '', 'tags': []}]
    items = args[0]
    result = []

    for item in items:
        path_items = path.split('/')
        for path_item in path_items:
            # search for keywords in file path  
            if path_item in TAGS:
                item.get('tags', []).append(path_item)

            # example regular expression to search for a pattern in the file path
            regex_asset = r'(prp|env|veh_\w*)'
            match = re.search(regex_asset, path_item)
            if match:
                item.get('tags', []).append(path_item)

        if item.get('tags'):
            # set last tag as the category
            item['category'] = item['tags'][-1]

        result.append(item)
    return result

if __name__ == '__main__':
    main(sys.argv[1:])

  • No labels