Skip to content

Commit

Permalink
Allow packet.duration to be writable
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed May 9, 2024
1 parent 471fc13 commit f42cc88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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
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 f42cc88

Please sign in to comment.