Skip to content

Commit

Permalink
Make second release candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed May 9, 2024
1 parent de5240d commit 97e88c3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion av/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "12.1.0rc1"
__version__ = "12.1.0rc2"
3 changes: 1 addition & 2 deletions av/packet.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Buffer
from fractions import Fraction
from typing import Iterator

from av.subtitles.subtitle import SubtitleSet

Expand All @@ -22,5 +21,5 @@ class Packet(Buffer):
is_disposable: bool

def __init__(self, input: int | bytes | None = None) -> None: ...
def decode(self) -> Iterator[SubtitleSet]: ...
def decode(self) -> list[SubtitleSet]: ...
def __buffer__(self, arg1) -> memoryview: ...
7 changes: 7 additions & 0 deletions av/packet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ cdef class Packet(Buffer):
if self.ptr.duration != lib.AV_NOPTS_VALUE:
return self.ptr.duration

@duration.setter
def duration(self, v):
if v is None:
self.ptr.duration = lib.AV_NOPTS_VALUE
else:
self.ptr.duration = v

@property
def is_keyframe(self):
return bool(self.ptr.flags & lib.AV_PKT_FLAG_KEY)
Expand Down
13 changes: 7 additions & 6 deletions av/subtitles/codeccontext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ from av.subtitles.subtitle cimport SubtitleProxy, SubtitleSet
cdef class SubtitleCodecContext(CodecContext):
cdef _send_packet_and_recv(self, Packet packet):
cdef SubtitleProxy proxy = SubtitleProxy()

cdef int got_frame = 0
err_check(lib.avcodec_decode_subtitle2(
self.ptr,
&proxy.struct,
&got_frame,
packet.ptr if packet else NULL))

err_check(
lib.avcodec_decode_subtitle2(
self.ptr, &proxy.struct, &got_frame, packet.ptr if packet else NULL
)
)

if got_frame:
return [SubtitleSet(proxy)]
else:
Expand Down
5 changes: 0 additions & 5 deletions av/subtitles/subtitle.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ from av.packet cimport Packet


cdef class SubtitleProxy:

cdef lib.AVSubtitle struct


cdef class SubtitleSet:

cdef readonly Packet packet
cdef SubtitleProxy proxy
cdef readonly tuple rects


cdef class Subtitle:

cdef SubtitleProxy proxy
cdef lib.AVSubtitleRect *ptr
cdef readonly bytes type
Expand All @@ -28,11 +25,9 @@ cdef class ASSSubtitle(Subtitle):
pass

cdef class BitmapSubtitle(Subtitle):

cdef readonly planes

cdef class BitmapSubtitlePlane:

cdef readonly BitmapSubtitle subtitle
cdef readonly int index
cdef readonly long buffer_size
Expand Down
3 changes: 2 additions & 1 deletion av/subtitles/subtitle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SubtitleSet:
start_display_time: int
end_display_time: int
pts: int
rects: tuple[Subtitle]

def __len__(self) -> int: ...
def __iter__(self) -> Iterator[Subtitle]: ...
Expand All @@ -29,7 +30,7 @@ class BitmapSubtitlePlane:

class TextSubtitle(Subtitle):
type: Literal[b"text"]
text: str
text: bytes

class AssSubtitle(Subtitle):
type: Literal[b"ass"]
Expand Down
4 changes: 3 additions & 1 deletion av/subtitles/subtitle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ cdef class TextSubtitle(Subtitle):

@property
def text(self):
return self.ptr.text
if self.ptr.text is not NULL:
return PyBytes_FromString(self.ptr.text)
return b""


cdef class AssSubtitle(Subtitle):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ def test_is_disposable(self):
self.assertTrue(packet.is_disposable)
else:
self.assertFalse(packet.is_disposable)

def test_set_duration(self):
with av.open(fate_suite("h264/interlaced_crop.mp4")) as container:
for packet in container.demux():
old_duration = packet.duration
packet.duration += 10

self.assertEqual(packet.duration, old_duration + 10)

0 comments on commit 97e88c3

Please sign in to comment.