Skip to content

Commit

Permalink
Add vprofile option
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Feb 2, 2025
1 parent 7c28a54 commit 3ef0653
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions auto_editor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ def main_options(parser: ArgumentParser) -> ArgumentParser:
metavar="BITRATE",
help="Set the number of bits per second for video",
)
parser.add_argument(
"-vprofile",
"-profile:v",
metavar="PROFILE",
help="Set the video profile. For h264: high, main, or baseline",
)
parser.add_argument(
"--scale",
type=number,
Expand Down
20 changes: 16 additions & 4 deletions auto_editor/render/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,34 @@ def render_av(
log.debug(f"Tous: {tous}")
log.debug(f"Clips: {tl.v}")

codec = av.Codec(args.video_codec, "w")

if args.video_codec == "gif":
_c = av.Codec("gif", "w")
if _c.video_formats is not None and target_pix_fmt in (
f.name for f in _c.video_formats
if codec.video_formats is not None and target_pix_fmt in (
f.name for f in codec.video_formats
):
target_pix_fmt = target_pix_fmt
else:
target_pix_fmt = "rgb8"
del _c
else:
target_pix_fmt = (
target_pix_fmt if target_pix_fmt in allowed_pix_fmt else "yuv420p"
)

del codec
ops = {"mov_flags": "faststart"}
output_stream = output.add_stream(args.video_codec, rate=target_fps, options=ops)

if args.vprofile is not None:
if args.vprofile.title() not in output_stream.codec_context.profiles:
a = [f'"{x.lower()}"' for x in output_stream.codec_context.profiles]
b = " ".join(a)
log.error(
f"`{args.vprofile}` is not a valid profile.\nprofiles supported: {b}"
)

output_stream.codec_context.profile = args.vprofile.title()

yield output_stream
if not isinstance(output_stream, av.VideoStream):
log.error(f"Not a known video codec: {args.video_codec}")
Expand Down
1 change: 1 addition & 0 deletions auto_editor/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Args:
video_codec: str = "auto"
audio_codec: str = "auto"
video_bitrate: str = "auto"
vprofile: str | None = None
audio_bitrate: str = "auto"
scale: float = 1.0
sn: bool = False
Expand Down

0 comments on commit 3ef0653

Please sign in to comment.