Skip to content

Commit 3ef0653

Browse files
committed
Add vprofile option
1 parent 7c28a54 commit 3ef0653

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

auto_editor/__main__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ def main_options(parser: ArgumentParser) -> ArgumentParser:
188188
metavar="BITRATE",
189189
help="Set the number of bits per second for video",
190190
)
191+
parser.add_argument(
192+
"-vprofile",
193+
"-profile:v",
194+
metavar="PROFILE",
195+
help="Set the video profile. For h264: high, main, or baseline",
196+
)
191197
parser.add_argument(
192198
"--scale",
193199
type=number,

auto_editor/render/video.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,34 @@ def render_av(
130130
log.debug(f"Tous: {tous}")
131131
log.debug(f"Clips: {tl.v}")
132132

133+
codec = av.Codec(args.video_codec, "w")
134+
133135
if args.video_codec == "gif":
134-
_c = av.Codec("gif", "w")
135-
if _c.video_formats is not None and target_pix_fmt in (
136-
f.name for f in _c.video_formats
136+
if codec.video_formats is not None and target_pix_fmt in (
137+
f.name for f in codec.video_formats
137138
):
138139
target_pix_fmt = target_pix_fmt
139140
else:
140141
target_pix_fmt = "rgb8"
141-
del _c
142142
else:
143143
target_pix_fmt = (
144144
target_pix_fmt if target_pix_fmt in allowed_pix_fmt else "yuv420p"
145145
)
146146

147+
del codec
147148
ops = {"mov_flags": "faststart"}
148149
output_stream = output.add_stream(args.video_codec, rate=target_fps, options=ops)
150+
151+
if args.vprofile is not None:
152+
if args.vprofile.title() not in output_stream.codec_context.profiles:
153+
a = [f'"{x.lower()}"' for x in output_stream.codec_context.profiles]
154+
b = " ".join(a)
155+
log.error(
156+
f"`{args.vprofile}` is not a valid profile.\nprofiles supported: {b}"
157+
)
158+
159+
output_stream.codec_context.profile = args.vprofile.title()
160+
149161
yield output_stream
150162
if not isinstance(output_stream, av.VideoStream):
151163
log.error(f"Not a known video codec: {args.video_codec}")

auto_editor/utils/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class Args:
198198
video_codec: str = "auto"
199199
audio_codec: str = "auto"
200200
video_bitrate: str = "auto"
201+
vprofile: str | None = None
201202
audio_bitrate: str = "auto"
202203
scale: float = 1.0
203204
sn: bool = False

0 commit comments

Comments
 (0)