diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index ec1c04e0f921c5e42d0cafe13c4ae7c5785119ba..c0f331c27c58fbdf5269adb0d7b6af0a451d75fb 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -737,13 +737,12 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
         uint64_t tmp= nut->next_startcode;
         nut->next_startcode=0;
 
-        if (url_feof(bc))
-            return -1;
-
         if(tmp){
             pos-=8;
         }else{
             frame_code = get_byte(bc);
+            if(url_feof(bc))
+                return -1;
             if(frame_code == 'N'){
                 tmp= frame_code;
                 for(i=1; i<8; i++)