From 7503c38ddd22034ec0d52905deb6a4dde7b13061 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 7 May 2021 12:59:49 +0200 Subject: [PATCH 1/4] implemented function which determine what args are used --- openpype/scripts/otio_burnin.py | 43 ++++++++++++++------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/openpype/scripts/otio_burnin.py b/openpype/scripts/otio_burnin.py index 8826f1af0c8..1c0b31d3a5b 100644 --- a/openpype/scripts/otio_burnin.py +++ b/openpype/scripts/otio_burnin.py @@ -69,6 +69,23 @@ def get_fps(str_value): return str(fps) +def get_codec_args(ffprobe_data): + codec_name = ffprobe_data.get("codec_name") + output = [] + if codec_name: + output.extend(["-codec:v", codec_name]) + + bit_rate = ffprobe_data.get("bit_rate") + if bit_rate: + output.extend(["-b:v", bit_rate]) + + pix_fmt = ffprobe_data.get("pix_fmt") + if pix_fmt: + output.extend(["-pix_fmt", pix_fmt]) + + return output + + class ModifiedBurnins(ffmpeg_burnins.Burnins): ''' This is modification of OTIO FFmpeg Burnin adapter. @@ -561,31 +578,7 @@ def burnins_from_data( else: ffprobe_data = burnin._streams[0] - codec_name = ffprobe_data.get("codec_name") - if codec_name: - if codec_name == "prores": - tags = ffprobe_data.get("tags") or {} - encoder = tags.get("encoder") or "" - if encoder.endswith("prores_ks"): - codec_name = "prores_ks" - - elif encoder.endswith("prores_aw"): - codec_name = "prores_aw" - ffmpeg_args.append("-codec:v {}".format(codec_name)) - - profile_name = ffprobe_data.get("profile") - if profile_name: - # lower profile name and repalce spaces with underscore - profile_name = profile_name.replace(" ", "_").lower() - ffmpeg_args.append("-profile:v {}".format(profile_name)) - - bit_rate = ffprobe_data.get("bit_rate") - if bit_rate: - ffmpeg_args.append("-b:v {}".format(bit_rate)) - - pix_fmt = ffprobe_data.get("pix_fmt") - if pix_fmt: - ffmpeg_args.append("-pix_fmt {}".format(pix_fmt)) + ffmpeg_args.extend(get_codec_args(ffprobe_data)) # Use group one (same as `-intra` argument, which is deprecated) ffmpeg_args.append("-g 1") From 378d43463b5c1ffa946c6ce5f5372253411b915d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 7 May 2021 13:00:15 +0200 Subject: [PATCH 2/4] implemented function handling prores codec --- openpype/scripts/otio_burnin.py | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/openpype/scripts/otio_burnin.py b/openpype/scripts/otio_burnin.py index 1c0b31d3a5b..6c6bd6ff435 100644 --- a/openpype/scripts/otio_burnin.py +++ b/openpype/scripts/otio_burnin.py @@ -69,8 +69,51 @@ def get_fps(str_value): return str(fps) +def _prores_codec_args(ffprobe_data): + output = [] + + tags = ffprobe_data.get("tags") or {} + encoder = tags.get("encoder") or "" + if encoder.endswith("prores_ks"): + codec_name = "prores_ks" + + elif encoder.endswith("prores_aw"): + codec_name = "prores_aw" + + else: + codec_name = "prores" + + output.extend(["-codec:v", codec_name]) + + pix_fmt = ffprobe_data.get("pix_fmt") + if pix_fmt: + output.extend(["-pix_fmt", pix_fmt]) + + # Rest of arguments is prores_kw specific + if codec_name == "prores_ks": + codec_tag_to_profile_map = { + "apco": "proxy", + "apcs": "lt", + "apcn": "standard", + "apch": "hq", + "ap4h": "4444", + "ap4x": "4444xq" + } + codec_tag_str = ffprobe_data.get("codec_tag_string") + if codec_tag_str: + profile = codec_tag_to_profile_map.get(codec_tag_str) + if profile: + output.extend(["-profile:v", profile]) + + return output + + def get_codec_args(ffprobe_data): codec_name = ffprobe_data.get("codec_name") + # Handle prores + if codec_name == "prores": + return _prores_codec_args(ffprobe_data) + output = [] if codec_name: output.extend(["-codec:v", codec_name]) From 159ac20708c963f9f5fe8902995add91bd227d6a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 7 May 2021 13:02:25 +0200 Subject: [PATCH 3/4] implemented function for h264 inputs --- openpype/scripts/otio_burnin.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/openpype/scripts/otio_burnin.py b/openpype/scripts/otio_burnin.py index 6c6bd6ff435..942d48d00ab 100644 --- a/openpype/scripts/otio_burnin.py +++ b/openpype/scripts/otio_burnin.py @@ -108,12 +108,31 @@ def _prores_codec_args(ffprobe_data): return output +def _h264_codec_args(ffprobe_data): + output = [] + + output.extend(["-codec:v", "h264"]) + + pix_fmt = ffprobe_data.get("pix_fmt") + if pix_fmt: + output.extend(["-pix_fmt", pix_fmt]) + + output.extend(["-intra"]) + output.extend(["-g", "1"]) + + return output + + def get_codec_args(ffprobe_data): codec_name = ffprobe_data.get("codec_name") - # Handle prores + # Codec "prores" if codec_name == "prores": return _prores_codec_args(ffprobe_data) + # Codec "h264" + if codec_name == "h264": + return _h264_codec_args(ffprobe_data) + output = [] if codec_name: output.extend(["-codec:v", codec_name]) From 64093f271134241e9353404b9efc5b0733756b2d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 7 May 2021 13:02:45 +0200 Subject: [PATCH 4/4] modified adding of -g argument --- openpype/scripts/otio_burnin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openpype/scripts/otio_burnin.py b/openpype/scripts/otio_burnin.py index 942d48d00ab..ca771719811 100644 --- a/openpype/scripts/otio_burnin.py +++ b/openpype/scripts/otio_burnin.py @@ -145,6 +145,8 @@ def get_codec_args(ffprobe_data): if pix_fmt: output.extend(["-pix_fmt", pix_fmt]) + output.extend(["-g", "1"]) + return output @@ -637,14 +639,13 @@ def burnins_from_data( if codec_data: # Use codec definition from method arguments ffmpeg_args = codec_data + ffmpeg_args.append("-g 1") else: ffprobe_data = burnin._streams[0] ffmpeg_args.extend(get_codec_args(ffprobe_data)) # Use group one (same as `-intra` argument, which is deprecated) - ffmpeg_args.append("-g 1") - ffmpeg_args_str = " ".join(ffmpeg_args) burnin.render( output_path, args=ffmpeg_args_str, overwrite=overwrite, **data