diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 370870485..d92389458 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -57,6 +57,7 @@ Fixes: - ``AudioFrame.planes`` no longer counts one plane too many for 8-channel planar audio (e.g. ``fltp`` with ``7.1``), which made ``planes``, ``to_ndarray()``, and ``from_ndarray()`` raise ``ValueError``, and no longer reads past the end of ``extended_data`` for more channels. By :gh-user:`ChandraChaan` in (:pr:`2502`). - ``AudioFifo.write()`` now raises ``ValueError`` for a frame whose channel layout differs from the first frame's, instead of reading the wrong number of channels and scrambling or over-reading the samples. By :gh-user:`ChandraChaan` in (:pr:`2505`). - A failed ``CodecContext.open()`` no longer clears the selected codec, so ``codec``, ``name``, ``is_encoder``, and ``is_decoder`` keep working and the context can be reused after fixing the offending parameters. +- :class:`.BitStreamFilterContext` now passes ``in_stream``'s time base to the filter, so filters that read it, such as ``setts`` with ``TB`` and ``pcm_rechunk``, no longer return ``None`` timestamps. By :gh-user:`NotAFlightRisk`. v19.0.2 ------- diff --git a/av/bitstream.py b/av/bitstream.py index 9266f348a..2763cc6ed 100644 --- a/av/bitstream.py +++ b/av/bitstream.py @@ -42,6 +42,7 @@ def __cinit__( self.ptr.par_in, cython.cast(Stream, in_stream).ptr.codecpar ) err_check(res) + self.ptr.time_base_in = cython.cast(Stream, in_stream).ptr.time_base elif in_stream is not None: # A Codec or codec name only pins the input codec, which is enough for # codec-specific filters (e.g. h264_mp4toannexb) to initialize. diff --git a/include/avcodec.pxd b/include/avcodec.pxd index 045600db1..935fc00da 100644 --- a/include/avcodec.pxd +++ b/include/avcodec.pxd @@ -534,6 +534,7 @@ cdef extern from "libavcodec/bsf.h" nogil: const AVBitStreamFilter *filter AVCodecParameters *par_in AVCodecParameters *par_out + AVRational time_base_in cdef int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf) cdef int av_bsf_init(AVBSFContext *ctx) diff --git a/tests/test_bitstream.py b/tests/test_bitstream.py index 3d4fca651..94d960257 100644 --- a/tests/test_bitstream.py +++ b/tests/test_bitstream.py @@ -74,6 +74,22 @@ def test_filter_h264_mp4toannexb() -> None: assert is_annexb(res_packet) +def test_filter_setts_uses_stream_time_base() -> None: + with av.open(fate_suite("h264/interlaced_crop.mp4"), "r") as container: + stream = container.streams.video[0] + ctx = BitStreamFilterContext("setts=pts=PTS+10/TB", stream) + + offset = int(10 / stream.time_base) + expected = [] + res_packets = [] + for p in container.demux(stream): + if p.pts is not None: + expected.append(p.pts + offset) + res_packets.extend(ctx.filter(p)) + + assert [p.pts for p in res_packets] == expected + + def test_filter_in_stream_codec_and_name() -> None: # A Codec or codec-name str can stand in for a Stream to pin the input codec, # which is all a codec-specific filter needs to initialize.