From bacd46df33e0932fe861e159ec1b6e830e40138e Mon Sep 17 00:00:00 2001 From: SuslikV Date: Tue, 30 Jul 2019 21:30:09 +0300 Subject: [PATCH] Fix crash during seeking at the start of the file Due to seeking optimizations the file can be closed and reopened. The packet's pointer becomes NULL in this case. This change ensures that packet's pointer is valid after seeking performed (if any). --- src/FFmpegReader.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index d5d51d52..86ada05c 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -921,6 +921,11 @@ std::shared_ptr FFmpegReader::ReadStream(int64_t requested_frame) { continue; } + // Packet may become NULL on Close inside Seek if CheckSeek returns false + if (!packet) + // Jump to the next iteration of this loop + continue; + // Get the AVFrame from the current packet frame_finished = GetAVFrame(); @@ -957,6 +962,11 @@ std::shared_ptr FFmpegReader::ReadStream(int64_t requested_frame) { continue; } + // Packet may become NULL on Close inside Seek if CheckSeek returns false + if (!packet) + // Jump to the next iteration of this loop + continue; + // Update PTS / Frame Offset (if any) UpdatePTSOffset(false);