Skip to content

Commit

Permalink
Rescale packet times when re-assigning the stream
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeboers committed Jun 9, 2016
1 parent c7b23cd commit c22a5ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions av/packet.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cimport libav as lib


cdef class Packet(object):

Expand Down Expand Up @@ -47,11 +49,22 @@ cdef class Packet(object):
def __get__(self):
return self.stream
def __set__(self, Stream value):

# Rescale times.
cdef lib.AVStream *old = self.stream._stream
cdef lib.AVStream *new = value._stream
self.struct.pts = lib.av_rescale_q_rnd(self.struct.pts, old.time_base, new.time_base,
lib.AV_ROUND_NEAR_INF | lib.AV_ROUND_PASS_MINMAX)
self.struct.dts = lib.av_rescale_q_rnd(self.struct.dts, old.time_base, new.time_base,
lib.AV_ROUND_NEAR_INF | lib.AV_ROUND_PASS_MINMAX)
self.struct.duration = lib.av_rescale_q(self.struct.duration, old.time_base, new.time_base)

self.stream = value
self.struct.stream_index = value.index

property pts:
def __get__(self): return None if self.struct.pts == lib.AV_NOPTS_VALUE else self.struct.pts

property dts:
def __get__(self):
return None if self.struct.dts == lib.AV_NOPTS_VALUE else self.struct.dts
Expand Down
9 changes: 8 additions & 1 deletion include/libavutil/avutil.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ cdef extern from "libavutil/avutil.pyav.h" nogil:
int64_t a,
int64_t b,
int64_t c,
AVRounding r
int r # should be AVRounding, but then we can't use bitwise logic.
)

cdef int64_t av_rescale_q_rnd(
int64_t a,
AVRational bq,
AVRational cq,
int r # should be AVRounding, but then we can't use bitwise logic.
)

cdef int64_t av_rescale(
Expand Down

0 comments on commit c22a5ee

Please sign in to comment.