Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
matrix:
config:
- {os: ubuntu-24.04, python: "3.12", ffmpeg: "8.0.1", extras: true}
- {os: ubuntu-24.04, python: "3.10", ffmpeg: "8.0.1"}
- {os: ubuntu-24.04, python: "3.11", ffmpeg: "8.0.1"}
- {os: ubuntu-24.04, python: "3.13", ffmpeg: "8.1"}
- {os: macos-14, python: "3.11", ffmpeg: "8.0.1"}
- {os: macos-14, python: "3.14", ffmpeg: "8.1"}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ jobs:
CIBW_ENVIRONMENT_MACOS: PKG_CONFIG_PATH=/tmp/vendor/lib/pkgconfig LDFLAGS=-headerpad_max_install_names
CIBW_ENVIRONMENT_WINDOWS: INCLUDE=C:\\cibw\\vendor\\include LIB=C:\\cibw\\vendor\\lib PYAV_SKIP_TESTS=unicode_filename
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: delvewheel repair --add-path C:\cibw\vendor\bin -w {dest_dir} {wheel}
CIBW_BUILD: "cp310* cp311* cp314t*"
CIBW_SKIP: "cp310-win_arm64"
CIBW_BUILD: "cp311* cp314t*"
CIBW_TEST_COMMAND: mv {project}/av {project}/av.disabled && python -m pytest {package}/tests && mv {project}/av.disabled {project}/av
CIBW_TEST_REQUIRES: pytest numpy
CIBW_TEST_SKIP: "*_armv7l"
Expand Down
3 changes: 2 additions & 1 deletion av/audio/codeccontext.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterator, Literal
from collections.abc import Iterator
from typing import Literal

from av.codec.context import CodecContext
from av.packet import Packet
Expand Down
4 changes: 2 additions & 2 deletions av/audio/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def write(self, frame: AudioFrame | None):
)
if frame.ptr.pts != expected_pts:
raise ValueError(
"Frame.pts (%d) != expected (%d); fix or set to None."
% (frame.ptr.pts, expected_pts)
f"Frame.pts ({frame.ptr.pts}) != expected ({expected_pts}); "
"fix or set to None."
)

err_check(
Expand Down
16 changes: 8 additions & 8 deletions av/audio/frame.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Union
from typing import Any

import numpy as np

Expand All @@ -9,13 +9,13 @@ from .layout import AudioLayout
from .plane import AudioPlane

format_dtypes: dict[str, str]
_SupportedNDarray = Union[
np.ndarray[Any, np.dtype[np.float64]], # f8
np.ndarray[Any, np.dtype[np.float32]], # f4
np.ndarray[Any, np.dtype[np.int32]], # i4
np.ndarray[Any, np.dtype[np.int16]], # i2
np.ndarray[Any, np.dtype[np.uint8]], # u1
]
_SupportedNDarray = (
np.ndarray[Any, np.dtype[np.float64]] # f8
| np.ndarray[Any, np.dtype[np.float32]] # f4
| np.ndarray[Any, np.dtype[np.int32]] # i4
| np.ndarray[Any, np.dtype[np.int16]] # i2
| np.ndarray[Any, np.dtype[np.uint8]] # u1
)

class _Format:
def __get__(self, i: object | None, owner: type | None = None) -> AudioFormat: ...
Expand Down
16 changes: 4 additions & 12 deletions av/codec/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _init(self, name=None):
if not self.desc:
self.desc = lib.avcodec_descriptor_get(self.ptr.id)
if not self.desc:
raise RuntimeError("No codec descriptor for %r." % name)
raise RuntimeError(f"No codec descriptor for {name!r}.")

self.is_encoder = lib.av_codec_is_encoder(self.ptr)

Expand Down Expand Up @@ -384,17 +384,9 @@ def dump_codecs():

try:
print(
" %s%s%s%s%s%s %-18s %s"
% (
".D"[bool(d_codec)],
".E"[bool(e_codec)],
codec.type[0].upper(),
".I"[codec.intra_only],
".L"[codec.lossy],
".S"[codec.lossless],
codec.name,
codec.long_name,
)
f" {'.D'[bool(d_codec)]}{'.E'[bool(e_codec)]}{codec.type[0].upper()}"
f"{'.I'[codec.intra_only]}{'.L'[codec.lossy]}{'.S'[codec.lossless]}"
f" {codec.name:<18} {codec.long_name}"
)
except Exception as e:
print(f"...... {codec.name:<18} ERROR: {e}")
Expand Down
3 changes: 2 additions & 1 deletion av/codec/codec.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Sequence
from enum import Flag, IntEnum
from fractions import Fraction
from typing import ClassVar, Literal, Sequence, cast, overload
from typing import ClassVar, Literal, cast, overload

from av.audio.codeccontext import AudioCodecContext
from av.audio.format import AudioFormat
Expand Down
7 changes: 4 additions & 3 deletions av/container/core.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from collections.abc import Callable
from enum import Flag, IntEnum
from fractions import Fraction
from pathlib import Path
from types import TracebackType
from typing import Any, Callable, ClassVar, Literal, Type, TypedDict, cast, overload
from typing import Any, ClassVar, Literal, Self, TypedDict, cast, overload

from av.codec.hwaccel import HWAccel
from av.format import ContainerFormat
Expand Down Expand Up @@ -92,10 +93,10 @@ class Container:
read_timeout: Real | None
flags: int
video_codec_id: int
def __enter__(self) -> Container: ...
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: Type[BaseException] | None,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None: ...
Expand Down
3 changes: 1 addition & 2 deletions av/container/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def decode(self, *args, **kwargs):
"""
self._assert_open()
for packet in self.demux(*args, **kwargs):
for frame in packet.decode():
yield frame
yield from packet.decode()

def seek(
self,
Expand Down
4 changes: 2 additions & 2 deletions av/container/input.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Iterator, overload
from collections.abc import Iterator
from typing import Any, overload

from av.audio.frame import AudioFrame
from av.audio.stream import AudioStream
Expand All @@ -17,7 +18,6 @@ class InputContainer(Container):
bit_rate: int
size: int

def __enter__(self) -> InputContainer: ...
@overload
def demux(self, video_stream: VideoStream) -> Iterator[Packet[VideoStream]]: ...
@overload
Expand Down
2 changes: 1 addition & 1 deletion av/container/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def start_encoding(self):
import logging

log = logging.getLogger(__name__)
log.warning("Some options were not used: %s" % unused_options)
log.warning(f"Some options were not used: {unused_options}")

self._myflag |= 4

Expand Down
4 changes: 2 additions & 2 deletions av/container/output.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence
from fractions import Fraction
from typing import Sequence, TypeVar, overload
from typing import TypeVar, overload

from av.audio import _AudioCodecName
from av.audio.stream import AudioStream
Expand All @@ -14,7 +15,6 @@ from .core import Container
_StreamT = TypeVar("_StreamT", bound=Stream)

class OutputContainer(Container):
def __enter__(self) -> OutputContainer: ...
@overload
def add_stream(
self,
Expand Down
2 changes: 1 addition & 1 deletion av/container/streams.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterator
from collections.abc import Iterator

import cython
import cython.cimports.libav as lib
Expand Down
3 changes: 2 additions & 1 deletion av/container/streams.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterator, Literal, overload
from collections.abc import Iterator
from typing import Literal, overload

from av.audio.stream import AudioStream
from av.stream import AttachmentStream, DataStream, Stream
Expand Down
2 changes: 1 addition & 1 deletion av/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
import sys
from typing import Iterator
from collections.abc import Iterator
from urllib.request import urlopen

log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion av/dictionary.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable, Iterator, Mapping
from collections.abc import Iterable, Iterator, Mapping

class Dictionary:
def __getitem__(self, key: str) -> str: ...
Expand Down
2 changes: 1 addition & 1 deletion av/filter/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _get_unique_name(self, name: str) -> str:
count = self._name_counts.get(name, 0)
self._name_counts[name] = count + 1
if count:
return "%s_%s" % (name, count)
return f"{name}_{count}"
else:
return name

Expand Down
3 changes: 2 additions & 1 deletion av/index.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterator, overload
from collections.abc import Iterator
from typing import overload

class IndexEntry:
pos: int
Expand Down
2 changes: 1 addition & 1 deletion av/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def log_callback_gil(
repeat_log = (
last_log[0],
last_log[1],
"%s (repeated %d more times)" % (last_log[2], skip_count),
f"{last_log[2]} (repeated {skip_count} more times)",
)
skip_count = 0

Expand Down
3 changes: 2 additions & 1 deletion av/logging.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Callable
from collections.abc import Callable
from typing import Any

PANIC: int
FATAL: int
Expand Down
3 changes: 2 additions & 1 deletion av/packet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterator, Literal, get_args
from collections.abc import Iterator
from typing import Literal, get_args

import cython
from cython.cimports import libav as lib
Expand Down
3 changes: 2 additions & 1 deletion av/packet.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Iterator
from fractions import Fraction
from typing import Generic, Iterator, Literal, TypeVar, overload
from typing import Generic, Literal, TypeVar, overload

from av.audio.frame import AudioFrame
from av.audio.stream import AudioStream
Expand Down
4 changes: 2 additions & 2 deletions av/sidedata/sidedata.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Mapping
from collections.abc import Iterator, Mapping, Sequence
from enum import Enum
from typing import ClassVar, Iterator, Sequence, cast, overload
from typing import ClassVar, cast, overload

from av.buffer import Buffer
from av.frame import Frame
Expand Down
2 changes: 1 addition & 1 deletion av/subtitles/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def build_subtitle(subtitle: SubtitleSet, index: cython.int) -> Subtitle:
if ptr.type == lib.SUBTITLE_ASS or ptr.type == lib.SUBTITLE_TEXT:
return AssSubtitle(subtitle, index)

raise ValueError("unknown subtitle type %r" % ptr.type)
raise ValueError(f"unknown subtitle type {ptr.type!r}")


@cython.cclass
Expand Down
3 changes: 2 additions & 1 deletion av/subtitles/subtitle.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterator, Literal
from collections.abc import Iterator
from typing import Literal

class SubtitleSet:
format: int
Expand Down
3 changes: 2 additions & 1 deletion av/video/codeccontext.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Iterator
from fractions import Fraction
from typing import Iterator, Literal
from typing import Literal

from av.codec.context import CodecContext
from av.packet import Packet
Expand Down
2 changes: 1 addition & 1 deletion av/video/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_pix_fmt(name: cython.p_const_char) -> lib.AVPixelFormat:

pix_fmt: lib.AVPixelFormat = lib.av_get_pix_fmt(name)
if pix_fmt == lib.AV_PIX_FMT_NONE:
raise ValueError("not a pixel format: %r" % name)
raise ValueError(f"not a pixel format: {name!r}")
return pix_fmt


Expand Down
14 changes: 7 additions & 7 deletions av/video/frame.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import IntEnum
from pathlib import Path
from typing import Any, Union
from typing import Any

import numpy as np

Expand All @@ -10,12 +10,12 @@ from .format import VideoFormat
from .plane import VideoPlane
from .reformatter import ColorPrimaries, ColorTrc

_SupportedNDarray = Union[
np.ndarray[Any, np.dtype[np.uint8]],
np.ndarray[Any, np.dtype[np.uint16]],
np.ndarray[Any, np.dtype[np.float16]],
np.ndarray[Any, np.dtype[np.float32]],
]
_SupportedNDarray = (
np.ndarray[Any, np.dtype[np.uint8]]
| np.ndarray[Any, np.dtype[np.uint16]]
| np.ndarray[Any, np.dtype[np.float16]]
| np.ndarray[Any, np.dtype[np.float32]]
)

supported_np_pix_fmts: set[str]

Expand Down
4 changes: 2 additions & 2 deletions av/video/stream.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Sequence
from collections.abc import Iterator, Sequence
from fractions import Fraction
from typing import Iterator, Literal
from typing import Literal

from av.codec.context import ThreadType
from av.packet import Packet
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
chunk = fh.read(1 << 16)

packets = codec.parse(chunk)
print("Parsed {} packets from {} bytes:".format(len(packets), len(chunk)))
print(f"Parsed {len(packets)} packets from {len(chunk)} bytes:")

for packet in packets:
print(" ", packet)
Expand Down
4 changes: 2 additions & 2 deletions examples/basics/thread_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
container.close()


print("Decoded with default threading in {:.2f}s.".format(default_time))
print("Decoded with auto threading in {:.2f}s.".format(auto_time))
print(f"Decoded with default threading in {default_time:.2f}s.")
print(f"Decoded with auto threading in {auto_time:.2f}s.")
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
{name = "WyattBlue", email = "wyattblue@auto-editor.com"},
{name = "Jeremy Lainé", email = "jeremy.laine@m4x.org"},
]
requires-python = ">=3.10"
requires-python = ">=3.11"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand All @@ -20,7 +20,6 @@ classifiers = [
"Operating System :: Unix",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Cython",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_config_from_pkg_config():

known, unknown = parse_cflags(raw_cflags.decode("utf-8"))
if unknown:
print("pkg-config returned flags we don't understand: {}".format(unknown))
print(f"pkg-config returned flags we don't understand: {unknown}")
if "-pthread" in unknown:
print("Building PyAV against static FFmpeg libraries is not supported.")
exit(1)
Expand Down
9 changes: 3 additions & 6 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
has_pillow = False

if TYPE_CHECKING:
from typing import Any, Callable, TypeVar
from collections.abc import Callable
from typing import Any, TypeVar

from PIL.Image import Image

Expand Down Expand Up @@ -105,11 +106,7 @@ def assertNdarraysEqual(a: np.ndarray, b: np.ndarray) -> None:
msg = ""
for equal in it:
if not equal:
msg += "- arrays differ at index {}; {} {}\n".format(
it.multi_index,
a[it.multi_index],
b[it.multi_index],
)
msg += f"- arrays differ at index {it.multi_index}; {a[it.multi_index]} {b[it.multi_index]}\n"
assert False, f"ndarrays contents differ\n{msg}"


Expand Down
Loading
Loading