Skip to content

Commit 67ab549

Browse files
committed
Use PyAV 12.3.0
1 parent b0ab189 commit 67ab549

File tree

5 files changed

+17
-39
lines changed

5 files changed

+17
-39
lines changed

auto_editor/analyze.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from fractions import Fraction
1717
from typing import Any
1818

19-
from av.filter import FilterContext
2019
from numpy.typing import NDArray
2120

2221
from auto_editor.ffwrapper import FileInfo
@@ -40,11 +39,6 @@ class LevelError(Exception):
4039
pass
4140

4241

43-
def link_nodes(*nodes: FilterContext) -> None:
44-
for c, n in zip(nodes, nodes[1:]):
45-
c.link_to(n)
46-
47-
4842
def mut_remove_small(
4943
arr: NDArray[np.bool_], lim: int, replace: int, with_: int
5044
) -> None:
@@ -239,7 +233,7 @@ def subtitle(
239233
self.log.error(e)
240234

241235
import av
242-
from av.subtitles.subtitle import AssSubtitle, TextSubtitle
236+
from av.subtitles.subtitle import AssSubtitle
243237

244238
try:
245239
container = av.open(self.src.path, "r")
@@ -287,8 +281,6 @@ def subtitle(
287281
for sub in subset:
288282
if isinstance(sub, AssSubtitle):
289283
line = convert_ass_to_text(sub.ass.decode(errors="ignore"))
290-
elif isinstance(sub, TextSubtitle):
291-
line = sub.text.decode(errors="ignore")
292284
else:
293285
continue
294286

@@ -324,14 +316,13 @@ def motion(self, stream: int, blur: int, width: int) -> NDArray[np.float64]:
324316
index = 0
325317

326318
graph = av.filter.Graph()
327-
link_nodes(
319+
graph.link_nodes(
328320
graph.add_buffer(template=video),
329321
graph.add("scale", f"{width}:-1"),
330322
graph.add("format", "gray"),
331323
graph.add("gblur", f"sigma={blur}"),
332324
graph.add("buffersink"),
333-
)
334-
graph.configure()
325+
).configure()
335326

336327
threshold_list = np.zeros((1024), dtype=np.float64)
337328

auto_editor/output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def audio(self, src: FileInfo, stream: int) -> str:
5757
output_astream = out_container.add_stream("pcm_s16le", rate=sample_rate)
5858
assert isinstance(output_astream, av.audio.stream.AudioStream)
5959

60-
resampler = AudioResampler(format="s16", layout="stereo", rate=sample_rate) # type: ignore
60+
resampler = AudioResampler(format="s16", layout="stereo", rate=sample_rate)
6161
for i, frame in enumerate(in_container.decode(astream)):
6262
if i % 1500 == 0:
6363
bar.tick(0 if frame.time is None else frame.time)

auto_editor/render/video.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
if TYPE_CHECKING:
1818
from collections.abc import Iterator
1919

20-
from av.filter import FilterContext
21-
2220
from auto_editor.ffwrapper import FFmpeg, FileInfo
2321
from auto_editor.timeline import v3
2422
from auto_editor.utils.bar import Bar
@@ -33,11 +31,6 @@ class VideoFrame:
3331
src: FileInfo
3432

3533

36-
def link_nodes(*nodes: FilterContext) -> None:
37-
for c, n in zip(nodes, nodes[1:]):
38-
c.link_to(n)
39-
40-
4134
# From: github.com/PyAV-Org/PyAV/blob/main/av/video/frame.pyx
4235
allowed_pix_fmt = {
4336
"yuv420p",
@@ -98,12 +91,11 @@ def make_image_cache(tl: v3) -> dict[tuple[FileInfo, int], np.ndarray]:
9891
for frame in cn.decode(my_stream):
9992
if obj.width != 0:
10093
graph = av.filter.Graph()
101-
link_nodes(
94+
graph.link_nodes(
10295
graph.add_buffer(template=my_stream),
10396
graph.add("scale", f"{obj.width}:-1"),
10497
graph.add("buffersink"),
105-
)
106-
graph.vpush(frame)
98+
).vpush(frame)
10799
frame = graph.vpull()
108100
img_cache[(obj.src, obj.width)] = frame.to_ndarray(
109101
format="rgb24"
@@ -177,7 +169,7 @@ def render_av(
177169
target_width = max(round(tl.res[0] * args.scale), 2)
178170
target_height = max(round(tl.res[1] * args.scale), 2)
179171
scale_graph = av.filter.Graph()
180-
link_nodes(
172+
scale_graph.link_nodes(
181173
scale_graph.add(
182174
"buffer", video_size="1x1", time_base="1/1", pix_fmt=target_pix_fmt
183175
),
@@ -293,29 +285,27 @@ def render_av(
293285
if (frame.width, frame.height) != tl.res:
294286
width, height = tl.res
295287
graph = av.filter.Graph()
296-
link_nodes(
288+
graph.link_nodes(
297289
graph.add_buffer(template=my_stream),
298290
graph.add(
299291
"scale",
300292
f"{width}:{height}:force_original_aspect_ratio=decrease:eval=frame",
301293
),
302294
graph.add("pad", f"{width}:{height}:-1:-1:color={bg}"),
303295
graph.add("buffersink"),
304-
)
305-
graph.vpush(frame)
296+
).vpush(frame)
306297
frame = graph.vpull()
307298
elif isinstance(obj, TlRect):
308299
graph = av.filter.Graph()
309300
x, y = apply_anchor(obj.x, obj.y, obj.width, obj.height, obj.anchor)
310-
link_nodes(
301+
graph.link_nodes(
311302
graph.add_buffer(template=my_stream),
312303
graph.add(
313304
"drawbox",
314305
f"x={x}:y={y}:w={obj.width}:h={obj.height}:color={obj.fill}:t=fill",
315306
),
316307
graph.add("buffersink"),
317-
)
318-
graph.vpush(frame)
308+
).vpush(frame)
319309
frame = graph.vpull()
320310
elif isinstance(obj, TlImage):
321311
img = img_cache[(obj.src, obj.width)]

auto_editor/subcommands/subdump.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import sys
22

33
import av
4-
from av.subtitles.subtitle import AssSubtitle, TextSubtitle
4+
from av.subtitles.subtitle import AssSubtitle
55

66

77
def main(sys_args: list[str] = sys.argv[1:]) -> None:
88
for i, input_file in enumerate(sys_args):
99
with av.open(input_file) as container:
1010
for s in range(len(container.streams.subtitles)):
1111
print(f"file: {input_file} ({s}:{container.streams.subtitles[s].name})")
12-
for packet in container.demux(subtitles=s):
13-
for subset in packet.decode():
14-
for sub in subset.rects:
15-
if isinstance(sub, AssSubtitle):
16-
print(sub.ass.decode("utf-8", errors="ignore"))
17-
elif isinstance(sub, TextSubtitle):
18-
print(sub.text.decode("utf-8", errors="ignore"))
12+
for subset in container.decode(subtitles=s):
13+
for sub in subset:
14+
if isinstance(sub, AssSubtitle):
15+
print(sub.ass.decode("utf-8", errors="ignore"))
1916
print("------")
2017

2118

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors = [{ name = "WyattBlue", email = "[email protected]" }]
1010
requires-python = ">=3.10"
1111
dependencies = [
1212
"numpy>=1.23.0",
13-
"pyav==12.2.*",
13+
"pyav==12.3.*",
1414
"ae-ffmpeg==1.2.*",
1515
]
1616
keywords = [

0 commit comments

Comments
 (0)