Skip to content

Commit

Permalink
Fix thread_type setter
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Nov 18, 2024
1 parent 75ff931 commit 48e72b6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion av/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "14.0.0rc1"
__version__ = "14.0.0rc2"
2 changes: 2 additions & 0 deletions av/codec/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ThreadType(Flag):
FRAME: ClassVar[ThreadType]
SLICE: ClassVar[ThreadType]
AUTO: ClassVar[ThreadType]
def __get__(self, i: object | None, owner: type | None = None) -> ThreadType: ...
def __set__(self, instance: object, value: int | str | ThreadType) -> None: ...

class SkipType(Enum):
NONE: ClassVar[SkipType]
Expand Down
13 changes: 8 additions & 5 deletions av/codec/context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ cdef class CodecContext:
self.codec = wrap_codec(codec if codec != NULL else self.ptr.codec)

# Set reasonable threading defaults.
# count == 0 -> use as many threads as there are CPUs.
# type == 2 -> thread within a frame. This does not change the API.
self.ptr.thread_count = 0
self.ptr.thread_type = 2
self.ptr.thread_count = 0 # use as many threads as there are CPUs.
self.ptr.thread_type = 0x02 # thread within a frame. Does not change the API.

def _get_flags(self):
return self.ptr.flags
Expand Down Expand Up @@ -623,7 +621,12 @@ cdef class CodecContext:
def thread_type(self, value):
if self.is_open:
raise RuntimeError("Cannot change thread_type after codec is open.")
self.ptr.thread_type = value.value
if type(value) is int:
self.ptr.thread_type = value
elif type(value) is str:
self.ptr.thread_type = ThreadType[value].value
else:
self.ptr.thread_type = value.value

@property
def skip_frame(self):
Expand Down
7 changes: 4 additions & 3 deletions av/video/stream.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fractions import Fraction
from typing import Any, Iterator, Literal
from typing import Iterator, Literal

from av.codec.context import ThreadType
from av.packet import Packet
from av.stream import Stream

Expand All @@ -12,8 +13,6 @@ class VideoStream(Stream):
bit_rate: int | None
max_bit_rate: int | None
bit_rate_tolerance: int
thread_count: int
thread_type: Any
sample_aspect_ratio: Fraction | None
display_aspect_ratio: Fraction | None
codec_context: VideoCodecContext
Expand All @@ -24,6 +23,8 @@ class VideoStream(Stream):

# from codec context
format: VideoFormat
thread_count: int
thread_type: ThreadType
width: int
height: int
bits_per_coded_sample: int
Expand Down
Binary file added data.ts
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ def test_selection(self) -> None:
fate_suite("amv/MTV_high_res_320x240_sample_Penguin_Joke_MTV_from_WMV.amv")
)
video = container.streams.video[0]

video.thread_type = av.codec.context.ThreadType.AUTO
assert video.thread_type == av.codec.context.ThreadType.AUTO

video.thread_type = 0x03
assert video.thread_type == av.codec.context.ThreadType.AUTO

video.thread_type = "AUTO"
assert video.thread_type == av.codec.context.ThreadType.AUTO

audio = container.streams.audio[0]

assert [video] == container.streams.get(video=0)
Expand Down

0 comments on commit 48e72b6

Please sign in to comment.