diff --git a/openpype/plugins/publish/extract_review.py b/openpype/plugins/publish/extract_review.py index 048d16fabb..7569023e0c 100644 --- a/openpype/plugins/publish/extract_review.py +++ b/openpype/plugins/publish/extract_review.py @@ -48,6 +48,8 @@ class ExtractReview(pyblish.api.InstancePlugin): video_exts = ["mov", "mp4"] supported_exts = image_exts + video_exts + alpha_exts = ["exr", "png", "dpx"] + # FFmpeg tools paths ffmpeg_path = get_ffmpeg_tool_path("ffmpeg") @@ -296,6 +298,13 @@ class ExtractReview(pyblish.api.InstancePlugin): ): with_audio = False + input_is_sequence = self.input_is_sequence(repre) + input_allow_bg = False + if input_is_sequence and repre["files"]: + ext = os.path.splitext(repre["files"][0])[1].replace(".", "") + if ext in self.alpha_exts: + input_allow_bg = True + return { "fps": float(instance.data["fps"]), "frame_start": frame_start, @@ -310,7 +319,8 @@ class ExtractReview(pyblish.api.InstancePlugin): "resolution_width": instance.data.get("resolutionWidth"), "resolution_height": instance.data.get("resolutionHeight"), "origin_repre": repre, - "input_is_sequence": self.input_is_sequence(repre), + "input_is_sequence": input_is_sequence, + "input_allow_bg": input_allow_bg, "with_audio": with_audio, "without_handles": without_handles, "handles_are_set": handles_are_set @@ -470,6 +480,39 @@ class ExtractReview(pyblish.api.InstancePlugin): lut_filters = self.lut_filters(new_repre, instance, ffmpeg_input_args) ffmpeg_video_filters.extend(lut_filters) + bg_alpha = 0 + bg_color = output_def.get("bg_color") + if bg_color: + bg_red, bg_green, bg_blue, bg_alpha = bg_color + + if bg_alpha > 0: + if not temp_data["input_allow_bg"]: + self.log.info(( + "Output definition has defined BG color input was" + " resolved as does not support adding BG." + )) + else: + bg_color_hex = "#{0:0>2X}{1:0>2X}{2:0>2X}".format( + bg_red, bg_green, bg_blue + ) + bg_color_alpha = float(bg_alpha) / 255 + bg_color_str = "{}@{}".format(bg_color_hex, bg_color_alpha) + + self.log.info("Applying BG color {}".format(bg_color_str)) + color_args = [ + "split=2[bg][fg]", + "[bg]drawbox=c={}:replace=1:t=fill[bg]".format( + bg_color_str + ), + "[bg][fg]overlay=format=auto" + ] + # Prepend bg color change before all video filters + # NOTE at the time of creation it is required as video filters + # from settings may affect color of BG + # e.g. `eq` can remove alpha from input + for arg in reversed(color_args): + ffmpeg_video_filters.insert(0, arg) + # Add argument to override output file ffmpeg_output_args.append("-y") diff --git a/openpype/settings/defaults/project_settings/global.json b/openpype/settings/defaults/project_settings/global.json index 1f54bed03c..d3b8c55d07 100644 --- a/openpype/settings/defaults/project_settings/global.json +++ b/openpype/settings/defaults/project_settings/global.json @@ -37,11 +37,11 @@ "ftrackreview" ], "ffmpeg_args": { - "video_filters": [ - "eq=gamma=2.2" - ], + "video_filters": [], "audio_filters": [], - "input": [], + "input": [ + "-apply_trc gamma22" + ], "output": [ "-pix_fmt yuv420p", "-crf 18", @@ -57,6 +57,12 @@ }, "width": 0, "height": 0, + "bg_color": [ + 0, + 0, + 0, + 0 + ], "letter_box": { "enabled": false, "ratio": 0.0, diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json index 426da4b71e..11b95862fa 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json @@ -193,6 +193,15 @@ "minimum": 0, "maximum": 100000 }, + { + "type": "label", + "label": "Background color is used only when input have transparency and Alpha is higher than 0." + }, + { + "type": "color", + "label": "Background color", + "key": "bg_color" + }, { "key": "letter_box", "label": "Letter box", @@ -280,24 +289,14 @@ "minimum": 0 }, { - "type": "schema_template", - "name": "template_rgba_color", - "template_data": [ - { - "label": "Font Color", - "name": "font_color" - } - ] + "type": "color", + "key": "font_color", + "label": "Font Color" }, { - "type": "schema_template", - "name": "template_rgba_color", - "template_data": [ - { - "label": "Background Color", - "name": "bg_color" - } - ] + "type": "color", + "key": "bg_color", + "label": "Background Color" }, { "type": "number", diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/template_rgba_color.json b/openpype/settings/entities/schemas/projects_schema/schemas/template_rgba_color.json deleted file mode 100644 index ffe530175a..0000000000 --- a/openpype/settings/entities/schemas/projects_schema/schemas/template_rgba_color.json +++ /dev/null @@ -1,33 +0,0 @@ -[ - { - "type": "list-strict", - "key": "{name}", - "label": "{label}", - "object_types": [ - { - "label": "R", - "type": "number", - "minimum": 0, - "maximum": 255 - }, - { - "label": "G", - "type": "number", - "minimum": 0, - "maximum": 255 - }, - { - "label": "B", - "type": "number", - "minimum": 0, - "maximum": 255 - }, - { - "label": "A", - "type": "number", - "minimum": 0, - "maximum": 255 - } - ] - } -]