diff --git a/openpype/hosts/aftereffects/api/extension.zxp b/openpype/hosts/aftereffects/api/extension.zxp index f80787fef8..b436f0ca0b 100644 Binary files a/openpype/hosts/aftereffects/api/extension.zxp and b/openpype/hosts/aftereffects/api/extension.zxp differ diff --git a/openpype/hosts/aftereffects/api/extension/jsx/hostscript.jsx b/openpype/hosts/aftereffects/api/extension/jsx/hostscript.jsx index cdaa2e3b83..9b211207de 100644 --- a/openpype/hosts/aftereffects/api/extension/jsx/hostscript.jsx +++ b/openpype/hosts/aftereffects/api/extension/jsx/hostscript.jsx @@ -395,13 +395,84 @@ function saveAs(path){ app.project.save(fp = new File(path)); } +function getRenderInfo(comp_id){ + /*** + Get info from render queue. + Currently pulls only file name to parse extension and + if it is sequence in Python + Args: + comp_id (int): id of composition + Return: + (list) [{file_name:"xx.png", width:00, height:00}] + **/ + var item = app.project.itemByID(comp_id); + if (!item){ + return _prepareError("Composition with '" + comp_id + "' wasn't found! Recreate publishable instance(s)") + } + + var comp_name = item.name; + var output_metadata = [] + try{ + // render_item.duplicate() should create new item on renderQueue + // BUT it works only sometimes, there are some weird synchronization issue + // this method will be called always before render, so prepare items here + // for render to spare the hassle + for (i = 1; i <= app.project.renderQueue.numItems; ++i){ + var render_item = app.project.renderQueue.item(i); + if (render_item.comp.id != comp_id){ + continue; + } + + if (render_item.status == RQItemStatus.DONE){ + render_item.duplicate(); // create new, cannot change status if DONE + render_item.remove(); // remove existing to limit duplications + continue; + } + } + + // properly validate as `numItems` won't change magically + var comp_id_count = 0; + for (i = 1; i <= app.project.renderQueue.numItems; ++i){ + var render_item = app.project.renderQueue.item(i); + if (render_item.comp.id != comp_id){ + continue; + } + comp_id_count += 1; + var item = render_item.outputModule(1); + + for (j = 1; j<= render_item.numOutputModules; ++j){ + var file_url = item.file.toString(); + output_metadata.push( + JSON.stringify({ + "file_name": file_url, + "width": render_item.comp.width, + "height": render_item.comp.height + }) + ); + } + } + } catch (error) { + return _prepareError("There is no render queue, create one"); + } + + if (comp_id_count > 1){ + return _prepareError("There cannot be more items in Render Queue for '" + comp_name + "'!") + } + + if (comp_id_count == 0){ + return _prepareError("There is no item in Render Queue for '" + comp_name + "'! Add composition to Render Queue.") + } + + return '[' + output_metadata.join() + ']'; +} + function getAudioUrlForComp(comp_id){ /** * Searches composition for audio layer - * + * * Only single AVLayer is expected! * Used for collecting Audio - * + * * Args: * comp_id (int): id of composition * Return: @@ -429,7 +500,7 @@ function addItemAsLayerToComp(comp_id, item_id, found_comp){ /** * Adds already imported FootageItem ('item_id') as a new * layer to composition ('comp_id'). - * + * * Args: * comp_id (int): id of target composition * item_id (int): FootageItem.id @@ -452,17 +523,17 @@ function addItemAsLayerToComp(comp_id, item_id, found_comp){ function importBackground(comp_id, composition_name, files_to_import){ /** * Imports backgrounds images to existing or new composition. - * + * * If comp_id is not provided, new composition is created, basic * values (width, heights, frameRatio) takes from first imported * image. - * + * * Args: * comp_id (int): id of existing composition (null if new) - * composition_name (str): used when new composition + * composition_name (str): used when new composition * files_to_import (list): list of absolute paths to import and * add as layers - * + * * Returns: * (str): json representation (id, name, members) */ @@ -484,7 +555,7 @@ function importBackground(comp_id, composition_name, files_to_import){ } } } - + if (files_to_import){ for (i = 0; i < files_to_import.length; ++i){ item = _importItem(files_to_import[i]); @@ -496,8 +567,8 @@ function importBackground(comp_id, composition_name, files_to_import){ if (!comp){ folder = app.project.items.addFolder(composition_name); imported_ids.push(folder.id); - comp = app.project.items.addComp(composition_name, item.width, - item.height, item.pixelAspect, + comp = app.project.items.addComp(composition_name, item.width, + item.height, item.pixelAspect, 1, 26.7); // hardcode defaults imported_ids.push(comp.id); comp.parentFolder = folder; @@ -506,7 +577,7 @@ function importBackground(comp_id, composition_name, files_to_import){ item.parentFolder = folder; addItemAsLayerToComp(comp.id, item.id, comp); - } + } } var item = {"name": comp.name, "id": folder.id, @@ -517,19 +588,19 @@ function importBackground(comp_id, composition_name, files_to_import){ function reloadBackground(comp_id, composition_name, files_to_import){ /** * Reloads existing composition. - * + * * It deletes complete composition with encompassing folder, recreates * from scratch via 'importBackground' functionality. - * + * * Args: * comp_id (int): id of existing composition (null if new) - * composition_name (str): used when new composition + * composition_name (str): used when new composition * files_to_import (list): list of absolute paths to import and * add as layers - * + * * Returns: * (str): json representation (id, name, members) - * + * */ var imported_ids = []; // keep track of members of composition comp = app.project.itemByID(comp_id); @@ -592,7 +663,7 @@ function reloadBackground(comp_id, composition_name, files_to_import){ function _get_file_name(file_url){ /** * Returns file name without extension from 'file_url' - * + * * Args: * file_url (str): full absolute url * Returns: @@ -607,7 +678,7 @@ function _delete_obsolete_items(folder, new_filenames){ /*** * Goes through 'folder' and removes layers not in new * background - * + * * Args: * folder (FolderItem) * new_filenames (array): list of layer names in new bg @@ -632,14 +703,14 @@ function _delete_obsolete_items(folder, new_filenames){ function _importItem(file_url){ /** * Imports 'file_url' as new FootageItem - * + * * Args: * file_url (str): file url with content * Returns: * (FootageItem) */ file_name = _get_file_name(file_url); - + //importFile prepared previously to return json item_json = importFile(file_url, file_name, JSON.stringify({"ImportAsType":"FOOTAGE"})); item_json = JSON.parse(item_json); @@ -661,71 +732,6 @@ function isFileSequence (item){ return false; } -function getRenderInfo(comp_id){ - /*** - Get info from render queue. - Currently pulls only file name to parse extension and - if it is sequence in Python - **/ - var item = app.project.itemByID(comp_id); - if (!item){ - return _prepareError("Composition with '" + comp_id + "' wasn't found! Recreate publishable instance(s)") - } - - var comp_name = item.name; - try{ - // render_item.duplicate() should create new item on renderQueue - // BUT it works only sometimes, there are some weird synchronization issue - // this method will be called always before render, so prepare items here - // for render to spare the hassle - for (i = 1; i <= app.project.renderQueue.numItems; ++i){ - var render_item = app.project.renderQueue.item(i); - if (render_item.comp.id != comp_id){ - continue; - } - - if (render_item.status == RQItemStatus.DONE){ - render_item.duplicate(); // create new, cannot change status if DONE - render_item.remove(); // remove existing to limit duplications - continue; - } - } - - // properly validate as `numItems` won't change magically - var comp_id_count = 0; - for (i = 1; i <= app.project.renderQueue.numItems; ++i){ - var render_item = app.project.renderQueue.item(i); - if (render_item.comp.id != comp_id){ - continue; - } - comp_id_count += 1; - var item = render_item.outputModule(1); - } - } catch (error) { - return _prepareError("There is no render queue, create one"); - } - - if (comp_id_count > 1){ - return _prepareError("There cannot be more items in Render Queue for '" + comp_name + "'!") - } - - if (comp_id_count == 0){ - return _prepareError("There is no item in Render Queue for '" + comp_name + "'! Add composition to Render Queue.") - } - - if (render_item.numOutputModules !=1){ - return _prepareError("There must be just 1 Output Module in Render Queue for '" + comp_name + "'! Keep only correct one.") - } - - var file_url = item.file.toString(); - - return JSON.stringify({ - "file_name": file_url, - "width": render_item.comp.width, - "height": render_item.comp.height - }) -} - function render(target_folder, comp_id){ var out_dir = new Folder(target_folder); var out_dir = out_dir.fsName; diff --git a/openpype/hosts/aftereffects/api/ws_stub.py b/openpype/hosts/aftereffects/api/ws_stub.py index 32125a7d99..e5d6d9ed89 100644 --- a/openpype/hosts/aftereffects/api/ws_stub.py +++ b/openpype/hosts/aftereffects/api/ws_stub.py @@ -422,15 +422,14 @@ class AfterEffectsServerStub(): """ Get render queue info for render purposes Returns: - (AEItem): with 'file_name' field + (list) of (AEItem): with 'file_name' field """ res = self.websocketserver.call(self.client.call ('AfterEffects.get_render_info', comp_id=comp_id)) records = self._to_records(self._handle_return(res)) - if records: - return records.pop() + return records def get_audio_url(self, item_id): """ Get audio layer absolute url for comp diff --git a/openpype/hosts/aftereffects/plugins/publish/collect_render.py b/openpype/hosts/aftereffects/plugins/publish/collect_render.py index 2b37c1f101..6153a426cf 100644 --- a/openpype/hosts/aftereffects/plugins/publish/collect_render.py +++ b/openpype/hosts/aftereffects/plugins/publish/collect_render.py @@ -22,7 +22,7 @@ class AERenderInstance(RenderInstance): stagingDir = attr.ib(default=None) app_version = attr.ib(default=None) publish_attributes = attr.ib(default={}) - file_name = attr.ib(default=None) + file_names = attr.ib(default=[]) class CollectAERender(publish.AbstractCollectRender): @@ -86,6 +86,7 @@ class CollectAERender(publish.AbstractCollectRender): render_q = CollectAERender.get_stub().get_render_info(comp_id) if not render_q: raise ValueError("No file extension set in Render Queue") + render_item = render_q[0] subset_name = inst.data["subset"] instance = AERenderInstance( @@ -102,8 +103,8 @@ class CollectAERender(publish.AbstractCollectRender): setMembers='', publish=True, name=subset_name, - resolutionWidth=render_q.width, - resolutionHeight=render_q.height, + resolutionWidth=render_item.width, + resolutionHeight=render_item.height, pixelAspect=1, tileRendering=False, tilesX=0, @@ -114,7 +115,7 @@ class CollectAERender(publish.AbstractCollectRender): fps=fps, app_version=app_version, publish_attributes=inst.data.get("publish_attributes", {}), - file_name=render_q.file_name + file_names=[item.file_name for item in render_q] ) comp = compositions_by_id.get(comp_id) @@ -162,28 +163,30 @@ class CollectAERender(publish.AbstractCollectRender): start = render_instance.frameStart end = render_instance.frameEnd - _, ext = os.path.splitext(os.path.basename(render_instance.file_name)) - base_dir = self._get_output_dir(render_instance) expected_files = [] - if "#" not in render_instance.file_name: # single frame (mov)W - path = os.path.join(base_dir, "{}_{}_{}.{}".format( - render_instance.asset, - render_instance.subset, - "v{:03d}".format(render_instance.version), - ext.replace('.', '') - )) - expected_files.append(path) - else: - for frame in range(start, end + 1): - path = os.path.join(base_dir, "{}_{}_{}.{}.{}".format( + for file_name in render_instance.file_names: + _, ext = os.path.splitext(os.path.basename(file_name)) + ext = ext.replace('.', '') + version_str = "v{:03d}".format(render_instance.version) + if "#" not in file_name: # single frame (mov)W + path = os.path.join(base_dir, "{}_{}_{}.{}".format( render_instance.asset, render_instance.subset, - "v{:03d}".format(render_instance.version), - str(frame).zfill(self.padding_width), - ext.replace('.', '') + version_str, + ext )) expected_files.append(path) + else: + for frame in range(start, end + 1): + path = os.path.join(base_dir, "{}_{}_{}.{}.{}".format( + render_instance.asset, + render_instance.subset, + version_str, + str(frame).zfill(self.padding_width), + ext + )) + expected_files.append(path) return expected_files def _get_output_dir(self, render_instance): diff --git a/openpype/hosts/aftereffects/plugins/publish/extract_local_render.py b/openpype/hosts/aftereffects/plugins/publish/extract_local_render.py index 309855f1c7..d535329eb4 100644 --- a/openpype/hosts/aftereffects/plugins/publish/extract_local_render.py +++ b/openpype/hosts/aftereffects/plugins/publish/extract_local_render.py @@ -24,46 +24,52 @@ class ExtractLocalRender(publish.Extractor): self.log.debug("staging_dir::{}".format(staging_dir)) # pull file name collected value from Render Queue Output module - if not instance.data["file_name"]: + if not instance.data["file_names"]: raise ValueError("No file extension set in Render Queue") comp_id = instance.data['comp_id'] stub.render(staging_dir, comp_id) - _, ext = os.path.splitext(os.path.basename(instance.data["file_name"])) - ext = ext[1:] + representations = [] + for file_name in instance.data["file_names"]: + _, ext = os.path.splitext(os.path.basename(file_name)) + ext = ext[1:] - first_file_path = None - files = [] - for file_name in os.listdir(staging_dir): - if not file_name.endswith(ext): - continue + first_file_path = None + files = [] + for found_file_name in os.listdir(staging_dir): + if not found_file_name.endswith(ext): + continue - files.append(file_name) - if first_file_path is None: - first_file_path = os.path.join(staging_dir, - file_name) + files.append(found_file_name) + if first_file_path is None: + first_file_path = os.path.join(staging_dir, + found_file_name) - if not files: - self.log.info("no files") - return + if not files: + self.log.info("no files") + return - resulting_files = files - if len(files) == 1: - resulting_files = files[0] + # single file cannot be wrapped in array + resulting_files = files + if len(files) == 1: + resulting_files = files[0] - repre_data = { - "frameStart": instance.data["frameStart"], - "frameEnd": instance.data["frameEnd"], - "name": ext, - "ext": ext, - "files": resulting_files, - "stagingDir": staging_dir - } - if instance.data["review"]: - repre_data["tags"] = ["review"] + repre_data = { + "frameStart": instance.data["frameStart"], + "frameEnd": instance.data["frameEnd"], + "name": ext, + "ext": ext, + "files": resulting_files, + "stagingDir": staging_dir + } + first_repre = not representations + if instance.data["review"] and first_repre: + repre_data["tags"] = ["review"] - instance.data["representations"] = [repre_data] + representations.append(repre_data) + + instance.data["representations"] = representations ffmpeg_path = get_ffmpeg_tool_path("ffmpeg") # Generate thumbnail.