diff --git a/av/packet.pyi b/av/packet.pyi index 690dc8374..cca33009c 100644 --- a/av/packet.pyi +++ b/av/packet.pyi @@ -16,6 +16,9 @@ class Packet: duration: int | None is_keyframe: bool is_corrupt: bool + is_discard: bool + is_trusted: bool + is_disposable: bool def __init__(self, input: int | None = None) -> None: ... def decode(self) -> Iterator[SubtitleSet]: ... diff --git a/av/packet.pyx b/av/packet.pyx index 116fab6b7..24fd5581b 100644 --- a/av/packet.pyx +++ b/av/packet.pyx @@ -189,7 +189,8 @@ cdef class Packet(Buffer): self.ptr.flags &= ~(lib.AV_PKT_FLAG_KEY) @property - def is_corrupt(self): return bool(self.ptr.flags & lib.AV_PKT_FLAG_CORRUPT) + def is_corrupt(self): + return bool(self.ptr.flags & lib.AV_PKT_FLAG_CORRUPT) @is_corrupt.setter def is_corrupt(self, v): @@ -197,3 +198,16 @@ cdef class Packet(Buffer): self.ptr.flags |= lib.AV_PKT_FLAG_CORRUPT else: self.ptr.flags &= ~(lib.AV_PKT_FLAG_CORRUPT) + + @property + def is_discard(self): + return bool(self.ptr.flags & lib.AV_PKT_FLAG_DISCARD) + + @property + def is_trusted(self): + return bool(self.ptr.flags & lib.AV_PKT_FLAG_TRUSTED) + + @property + def is_disposable(self): + return bool(self.ptr.flags & lib.AV_PKT_FLAG_DISPOSABLE) + diff --git a/include/libavcodec/avcodec.pxd b/include/libavcodec/avcodec.pxd index 7d841559d..b58047014 100644 --- a/include/libavcodec/avcodec.pxd +++ b/include/libavcodec/avcodec.pxd @@ -90,6 +90,9 @@ cdef extern from "libavcodec/avcodec.h" nogil: cdef enum: AV_PKT_FLAG_KEY AV_PKT_FLAG_CORRUPT + AV_PKT_FLAG_DISCARD + AV_PKT_FLAG_TRUSTED + AV_PKT_FLAG_DISPOSABLE cdef enum: AV_FRAME_FLAG_CORRUPT diff --git a/tests/test_packet.py b/tests/test_packet.py new file mode 100644 index 000000000..8a2b6266c --- /dev/null +++ b/tests/test_packet.py @@ -0,0 +1,41 @@ +import av + +from .common import TestCase, fate_suite + + +class TestProperties(TestCase): + def test_is_keyframe(self): + with av.open(fate_suite("h264/interlaced_crop.mp4")) as container: + stream = container.streams.video[0] + for i, packet in enumerate(container.demux(stream)): + if i in (0, 21, 45, 69, 93, 117): + self.assertTrue(packet.is_keyframe) + else: + self.assertFalse(packet.is_keyframe) + + def test_is_corrupt(self): + with av.open(fate_suite("mov/white_zombie_scrunch-part.mov")) as container: + stream = container.streams.video[0] + for i, packet in enumerate(container.demux(stream)): + if i == 65: + self.assertTrue(packet.is_corrupt) + else: + self.assertFalse(packet.is_corrupt) + + def test_is_discard(self): + with av.open(fate_suite("mov/mov-1elist-ends-last-bframe.mov")) as container: + stream = container.streams.video[0] + for i, packet in enumerate(container.demux(stream)): + if i == 46: + self.assertTrue(packet.is_discard) + else: + self.assertFalse(packet.is_discard) + + def test_is_disposable(self): + with av.open(fate_suite("hap/HAPQA_NoSnappy_127x1.mov")) as container: + stream = container.streams.video[0] + for i, packet in enumerate(container.demux(stream)): + if i == 0: + self.assertTrue(packet.is_disposable) + else: + self.assertFalse(packet.is_disposable)