[FFmpeg-cvslog] avformat/utils: return pending IO error on EOF in av_read_frame()

Marton Balint git at videolan.org
Sat Aug 31 19:15:02 EEST 2019

ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Sat Aug 24 22:00:12 2019 +0200| [ce1fcc8cede2971f6e36119e9dd41fb41b36c63a] | committer: Marton Balint

avformat/utils: return pending IO error on EOF in av_read_frame()

avio_feof() returns true both in case of actual EOF and in case of IO errors.
Some demuxers (matroska) have special handling to be able to return the proper
error for this exact reason, e.g.:

if (avio_feof(pb)) {
     if (pb->error) {
         return pb->error;
     } else {
         return AVERROR_EOF;

However, most of the demuxers do not, and they simply return AVERROR_EOF if
avio_feof() is true, so there is a real chance that IO errors are mistaken for

We might just say that the API user should always check the IO context error
attribute on EOF to make sure no IO errors happened, but not even ffmpeg.c does
this. It should be more intuitive to the API user if we simply return the IO
error as the return value of av_read_frame() instead of AVERROR_EOF.

Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ce1fcc8cede2971f6e36119e9dd41fb41b36c63a

 libavformat/utils.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index b57e680089..b83a740500 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
                pkt->size, pkt->duration, pkt->flags);
+    /* A demuxer might have returned EOF because of an IO error, let's
+     * propagate this back to the user. */
+    if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN))
+        ret = s->pb->error;
     return ret;

More information about the ffmpeg-cvslog mailing list