Skip to content

Commit

Permalink
Use canonical name
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Feb 21, 2025
1 parent 71f4636 commit 7c35d13
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 40 deletions.
41 changes: 6 additions & 35 deletions auto_editor/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,6 @@ def set_audio_codec(
return codec


def normalize_encoder(codec: str) -> tuple[str, bool]:
is_hardware = False
if "_" in codec:
is_hardware = codec.split("_")[-1] in {"videotoolbox", "cuvid", "nvec"}

id = av.Codec(codec, "w").id
name = {
27: "h264",
97: "gif",
173: "hevc",
167: "vp9",
139: "vp8",
86018: "aac",
}.get(id, codec)

return name, is_hardware


def parse_export(export: str, log: Log) -> dict[str, Any]:
exploded = export.split(":", maxsplit=1)
if len(exploded) == 1:
Expand Down Expand Up @@ -391,25 +373,14 @@ def make_media(tl: v3, output_path: str) -> None:
no_color = log.no_color or log.machine
encoder_titles = []
if output_stream is not None:
name, h = normalize_encoder(output_stream.name)
if no_color:
encoder_titles.append(name)
else:
is_bold = ";1" if h else ""
encoder_titles.append(f"\033[95{is_bold}m{name}")
name = output_stream.codec.canonical_name
encoder_titles.append(name if no_color else f"\033[95m{name}")
if audio_streams:
name, h = normalize_encoder(audio_streams[0].name) # type: ignore
if no_color:
encoder_titles.append(name)
else:
is_bold = ";1" if h else ""
encoder_titles.append(f"\033[96{is_bold}m{name}")
name = audio_streams[0].name
encoder_titles.append(name if no_color else f"\033[96m{name}")
if subtitle_streams:
name = subtitle_streams[0].name # type: ignore
if no_color:
encoder_titles.append(name)
else:
encoder_titles.append(f"\033[32m{name}")
name = subtitle_streams[0].name
encoder_titles.append(name if no_color else f"\033[32m{name}")

title = f"({os.path.splitext(output_path)[1][1:]}) "
if no_color:
Expand Down
3 changes: 1 addition & 2 deletions auto_editor/ffwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ def initFileInfo(path: str, log: Log) -> FileInfo:
adur = float(a.duration * a.time_base)

a_cc = a.codec_context
name = a_cc.name if a_cc.name != "mp3float" else "mp3"
audios += (
AudioStream(
name,
a_cc.codec.canonical_name,
0 if a_cc.sample_rate is None else a_cc.sample_rate,
a.layout.name,
a_cc.channels,
Expand Down
4 changes: 2 additions & 2 deletions auto_editor/render/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ def render_av(

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

if codec.id == 97: # gif
if codec.canonical_name == "gif":
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"
elif codec.id == 147: # prores
elif codec.canonical_name == "prores":
target_pix_fmt = "yuv422p10le"
else:
target_pix_fmt = (
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/utils/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def tick(self, index: float) -> None:
percent = round(progress * 100, 1)
p_pad = " " * (4 - len(str(percent)))
columns = get_terminal_size().columns
bar_len = max(1, columns - (len_title + 32))
bar_len = max(1, columns - len_title - 32)
bar_str = self._bar_str(progress, bar_len)

bar = f" {self.icon}{title} {bar_str} {p_pad}{percent}% ETA {new_time}"
Expand Down

0 comments on commit 7c35d13

Please sign in to comment.