From bf3be5f7a4c4317af8b2bb4b28c353e9f43720c6 Mon Sep 17 00:00:00 2001 From: "Takeshi Ikuma (LSUHSC)" Date: Sat, 23 Aug 2025 22:32:44 -0500 Subject: [PATCH] fixed seek operation when not at eof --- av/container/input.pxd | 2 ++ av/container/input.pyx | 5 ++++- include/libavformat/avformat.pxd | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/av/container/input.pxd b/av/container/input.pxd index 8c369d8ad..f7fa75679 100644 --- a/av/container/input.pxd +++ b/av/container/input.pxd @@ -6,4 +6,6 @@ from av.stream cimport Stream cdef class InputContainer(Container): + cdef bint eof + cdef flush_buffers(self) diff --git a/av/container/input.pyx b/av/container/input.pyx index 943081e15..a2c9c1a9f 100644 --- a/av/container/input.pyx +++ b/av/container/input.pyx @@ -173,6 +173,7 @@ cdef class InputContainer(Container): ret = lib.av_read_frame(self.ptr, packet.ptr) self.err_check(ret) except EOFError: + self.eof = True break if include_stream[packet.ptr.stream_index]: @@ -276,7 +277,9 @@ cdef class InputContainer(Container): ret = lib.av_seek_frame(self.ptr, stream_index, c_offset, flags) err_check(ret) - self.flush_buffers() + # codec buffers must be cleared if file is at eof, + if self.eof or lib.avio_feof(self.ptr.pb): + self.flush_buffers() cdef flush_buffers(self): self._assert_open() diff --git a/include/libavformat/avformat.pxd b/include/libavformat/avformat.pxd index 6c23e99b4..5dc819974 100644 --- a/include/libavformat/avformat.pxd +++ b/include/libavformat/avformat.pxd @@ -275,6 +275,8 @@ cdef extern from "libavformat/avformat.h" nogil: cdef int avio_closep(AVIOContext **s) + cdef int avio_feof(AVIOContext *s) + cdef int avformat_find_stream_info( AVFormatContext *ctx, AVDictionary **options, # Can be NULL.