From 55beecc52a4ce6c0542a3b19e6c983c7f6c510e9 Mon Sep 17 00:00:00 2001 From: exwm Date: Fri, 8 Dec 2023 17:47:13 -0500 Subject: [PATCH] feat(clipper/h264): add --h264-disable-reduce-stutter/--h264-drs flag for opting in to a consistent framerate with duplicate frames when slowing down clips for potentially smoother merged video transitions --- src/clipper/argparser.py | 13 +++++++++++++ src/clipper/clip_maker.py | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/clipper/argparser.py b/src/clipper/argparser.py index e5e111a..9842e7d 100644 --- a/src/clipper/argparser.py +++ b/src/clipper/argparser.py @@ -460,6 +460,19 @@ def getArgParser() -> argparse.ArgumentParser: ] ), ) + parser.add_argument( + "--h264-disable-reduce-stutter", + "-h264-drs", + dest="h264DisableReduceStutter", + action="store_true", + help=" ".join( + [ + "Disable reducing output clip sutter when using the h264 output video codec.", + "When disabled, output clips will all use the input video framerate and slowed down clips may have duplicate frames that cause some stuttering.", + "This may be useful when merging h264 videos however as in some cases keeping the same framerate results in smoother transitions between clips." + ] + ), + ) parser.add_argument( "--auto-subs-lang", "-asl", diff --git a/src/clipper/clip_maker.py b/src/clipper/clip_maker.py index 07d353a..ac14f0f 100644 --- a/src/clipper/clip_maker.py +++ b/src/clipper/clip_maker.py @@ -600,11 +600,14 @@ def getFfmpegVideoCodecH264( qmin: int, ) -> Tuple[str, str]: """Following recommendations from https://www.lighterra.com/papers/videoencodingh264""" - if mps["minterpFPS"] is not None: - fps_arg = f'-r {mps["minterpFPS"]}' - elif not mp["isVariableSpeed"]: - fps_arg = f'-r ({mps["r_frame_rate"]}*{mp["speed"]})' - else: + fps_arg = "" + if not mps["h264DisableReduceStutter"]: + if mps["minterpFPS"] is not None: + fps_arg = f'-r {mps["minterpFPS"]}' + elif not mp["isVariableSpeed"]: + fps_arg = f'-r ({mps["r_frame_rate"]}*{mp["speed"]})' + + if mp["isVariableSpeed"]: fps_arg = "-fps_mode vfr" pixel_count = mps["width"] * mps["height"]