Skip to content

Commit

Permalink
feat(clipper/h264): add --h264-disable-reduce-stutter/--h264-drs flag…
Browse files Browse the repository at this point in the history
… for opting in to a consistent framerate with duplicate frames when slowing down clips for potentially smoother merged video transitions
  • Loading branch information
exwm committed Dec 8, 2023
1 parent 352fc46 commit 55beecc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/clipper/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions src/clipper/clip_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 55beecc

Please sign in to comment.