Skip to content

Commit d0cb574

Browse files
committed
Re-use outputStream codec
1 parent 7abd6d8 commit d0cb574

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

auto_editor/edit.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def set_video_codec(
9999
log.error(f"Unknown encoder: {codec}")
100100
# Normalize encoder names
101101
if cobj.id not in (Codec(x, "w").id for x in ctr.vcodecs):
102-
log.error(codec_error.format(codec, out_ext))
102+
log.error(
103+
f"'{codec}' video encoder is not supported in the '{out_ext}' container"
104+
)
103105

104106
return codec
105107

@@ -127,8 +129,9 @@ def set_audio_codec(
127129
log.error(f"Unknown encoder: {codec}")
128130
# Normalize encoder names
129131
if cobj.id not in (Codec(x, "w").id for x in ctr.acodecs):
130-
log.error(codec_error.format(codec, out_ext))
131-
132+
log.error(
133+
f"'{codec}' audio encoder is not supported in the '{out_ext}' container"
134+
)
132135
return codec
133136

134137

auto_editor/render/video.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,22 @@ def render_av(
101101
log.debug(f"Tous: {tous}")
102102
log.debug(f"Clips: {tl.v}")
103103

104-
codec = av.Codec(args.video_codec, "w")
105-
106-
need_valid_fmt = True
107-
if codec.video_formats is not None:
108-
for video_format in codec.video_formats:
109-
if pix_fmt == video_format.name:
110-
need_valid_fmt = False
111-
break
112-
113-
if need_valid_fmt:
114-
if codec.canonical_name == "gif":
115-
pix_fmt = "rgb8"
116-
elif codec.canonical_name == "prores":
117-
pix_fmt = "yuv422p10le"
118-
else:
119-
pix_fmt = "yuv420p"
120-
121-
del codec
122104
output_stream = output.add_stream(args.video_codec, rate=target_fps)
123105
output_stream.options = {"x265-params": "log-level=error"}
124106

107+
need_valid_fmt = not (
108+
output_stream.codec.video_formats
109+
and any(pix_fmt == vfmt.name for vfmt in output_stream.codec.video_formats)
110+
)
111+
if need_valid_fmt:
112+
match output_stream.codec.canonical_name:
113+
case "gif":
114+
pix_fmt = "rgb8"
115+
case "prores":
116+
pix_fmt = "yuv422p10le"
117+
case _:
118+
pix_fmt = "yuv420p"
119+
125120
cc = output_stream.codec_context
126121
if args.vprofile is not None:
127122
if args.vprofile.title() not in cc.profiles:

0 commit comments

Comments
 (0)