Skip to content

Commit cf6d052

Browse files
committed
Use AVPacket.time_base
1 parent 91c6013 commit cf6d052

File tree

5 files changed

+12
-23
lines changed

5 files changed

+12
-23
lines changed

av/codec/context.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ cdef class CodecContext:
428428
#
429429
# NOTE: if the CodecContext's time_base is altered during encoding, all bets
430430
# are off!
431-
packet._time_base = self.ptr.time_base
431+
packet.ptr.time_base = self.ptr.time_base
432432

433433
cpdef decode(self, Packet packet=None):
434434
"""Decode a list of :class:`.Frame` from the given :class:`.Packet`.
@@ -469,7 +469,7 @@ cdef class CodecContext:
469469
# TODO: Somehow get this from the stream so we can not pass the
470470
# packet here (because flushing packets are bogus).
471471
if packet is not None:
472-
frame._time_base = packet._time_base
472+
frame._time_base = packet.ptr.time_base
473473

474474
@property
475475
def name(self):

av/container/input.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ cdef class InputContainer(Container):
183183
if packet.ptr.stream_index < len(self.streams):
184184
packet._stream = self.streams[packet.ptr.stream_index]
185185
# Keep track of this so that remuxing is easier.
186-
packet._time_base = packet._stream.ptr.time_base
186+
packet.ptr.time_base = packet._stream.ptr.time_base
187187
yield packet
188188

189189
# Flush!
190190
for i in range(self.ptr.nb_streams):
191191
if include_stream[i]:
192192
packet = Packet()
193193
packet._stream = self.streams[i]
194-
packet._time_base = packet._stream.ptr.time_base
194+
packet.ptr.time_base = packet._stream.ptr.time_base
195195
yield packet
196196

197197
finally:

av/packet.pxd

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ from av.stream cimport Stream
66

77

88
cdef class Packet(Buffer):
9-
109
cdef lib.AVPacket* ptr
11-
1210
cdef Stream _stream
13-
14-
# We track our own time.
15-
cdef lib.AVRational _time_base
1611
cdef _rebase_time(self, lib.AVRational)
17-
1812
# Hold onto the original reference.
1913
cdef ByteSource source
2014
cdef size_t _buffer_size(self)

av/packet.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ def _rebase_time(self, dst: lib.AVRational):
6565
if not dst.num:
6666
raise ValueError("Cannot rebase to zero time.")
6767

68-
if not self._time_base.num:
69-
self._time_base = dst
68+
if not self.ptr.time_base.num:
69+
self.ptr.time_base = dst
7070
return
7171

72-
if self._time_base.num == dst.num and self._time_base.den == dst.den:
72+
if self.ptr.time_base.num == dst.num and self.ptr.time_base.den == dst.den:
7373
return
7474

75-
lib.av_packet_rescale_ts(self.ptr, self._time_base, dst)
76-
77-
self._time_base = dst
75+
lib.av_packet_rescale_ts(self.ptr, self.ptr.time_base, dst)
76+
self.ptr.time_base = dst
7877

7978
def decode(self):
8079
"""
@@ -106,11 +105,11 @@ def time_base(self):
106105
107106
:type: fractions.Fraction
108107
"""
109-
return avrational_to_fraction(cython.address(self._time_base))
108+
return avrational_to_fraction(cython.address(self.ptr.time_base))
110109

111110
@time_base.setter
112111
def time_base(self, value):
113-
to_avrational(value, cython.address(self._time_base))
112+
to_avrational(value, cython.address(self.ptr.time_base))
114113

115114
@property
116115
def pts(self):

include/libavcodec/avcodec.pxd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,19 +466,15 @@ cdef extern from "libavcodec/avcodec.h" nogil:
466466
cdef AVFrame* avcodec_alloc_frame()
467467

468468
cdef struct AVPacket:
469-
470469
int64_t pts
471470
int64_t dts
472471
uint8_t *data
473-
472+
AVRational time_base
474473
int size
475474
int stream_index
476475
int flags
477-
478476
int duration
479-
480477
int64_t pos
481-
482478
void *opaque
483479
AVBufferRef *opaque_ref
484480

0 commit comments

Comments
 (0)