From a1a85c502ef8f8ed70ea1215ca7b49d675181c9a Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 9 Jan 2022 03:37:45 -0800 Subject: [PATCH] FFmpeg input: Check for seeking errors and stop decoding when they happen --- Plugins/FFMPEG/FFMPEGDecoder.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Plugins/FFMPEG/FFMPEGDecoder.m b/Plugins/FFMPEG/FFMPEGDecoder.m index 4d21ec5df..ba7285e03 100644 --- a/Plugins/FFMPEG/FFMPEGDecoder.m +++ b/Plugins/FFMPEG/FFMPEGDecoder.m @@ -540,8 +540,15 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op) } AVRational tb = {.num = 1, .den = codecCtx->sample_rate}; int64_t ts = av_rescale_q(frame, tb, formatCtx->streams[streamIndex]->time_base); - avformat_seek_file(formatCtx, streamIndex, ts - 1000, ts, ts, 0); + int ret = avformat_seek_file(formatCtx, streamIndex, ts - 1000, ts, ts, 0); avcodec_flush_buffers(codecCtx); + if (ret < 0) + { + framesRead = totalFrames; + endOfStream = YES; + endOfAudio = YES; + return -1; + } readNextPacket = YES; // so we immediately read next packet bytesConsumedFromDecodedFrame = INT_MAX; // so we immediately begin decoding next frame framesRead = frame;