[Libav-user] av_read_frame returns -32

Bob Self bobslf at gmail.com
Tue Mar 6 15:31:51 CET 2012


I am trying to get a simple video play working for an xvid codec.
Below is the essential part of the
program. It stops decoding the movie at frame 2247. The video is about 1.5
hours and has a lot more frames that that.

The problem is that av_read_frame() is returning -32 I can't find any
documentation
about what this return value means.


VLC says that the movie codec is MPEG-4 (XVID) and the frame rate is 23.97...

I've tested this on windows 7 and Ubuntu 11.04 (both 64 bit) and it
behaves the same. The movie plays fine in other players. Can anyone
tell me what the problem is?

thanks,
Robert




// globals:
long packets=0L;
bool b;
long frame = 0L;


avcodec_init();
av_register_all();
m_pFrame = avcodec_alloc_frame();

av_open_input_file(&m_pFormatCtx, filename, NULL, 0, NULL);
av_find_stream_info(m_pFormatCtx);
OpenVideoStream();
OpenCodec();

while (1)  {
   b = GetNextFrame();
   if (b==false)  {
      printf("GetNextFrame failed or EOF\n");
      break;
   }
   frame++;
}

.....

/*****************************************************************************

 *****************************************************************************/

bool GetNextFrame() {
   int   got_picture;
   AVPacket packet;
   int status;
   int len;

   while (1)  {
      status = av_read_frame(m_pFormatCtx, &packet);
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS IS WHERE IT FAILS
      if (status<0)  {
         // status is -32
         av_free_packet(&packet);
         break;
      }
      packets++;

      if (packet.stream_index == m_videoStream) {
         len = avcodec_decode_video2(m_pCodecCtx, m_pFrame,
&got_picture, &packet);
         if (len < 0) {
            printf("avcodec_decode_video2() failed\n");
            break;
         }
         if (got_picture)  {
            av_free_packet(&packet);
            return true;
         }
      }
      av_free_packet(&packet);
   }
   return false;
}

/*****************************************************************************

 *****************************************************************************/

bool OpenVideoStream() {
   unsigned int      i;

   // find the first video stream
   m_videoStream = -1;

   for (i = 0; i < m_pFormatCtx->nb_streams; i++) {
      if (m_pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
         m_videoStream = i;
         break;
      }
   }

   if (m_videoStream == -1) {
      return false;
   }

   // Get a pointer to the codec context for the video stream
   m_pCodecCtx = m_pFormatCtx->streams[m_videoStream]->codec;
   frames = m_pFormatCtx->streams[m_videoStream]->nb_frames;         // 154959


   double d;

   d = frames / 23.97;               // d = 5170
   d /= 3600.0;                  // d = 1.79 hours

   return true;
}

/*****************************************************************************

 *****************************************************************************/

bool OpenCodec() {
   AVCodec            *pCodec;

   // find the decoder for the video stream
   pCodec = avcodec_find_decoder(m_pCodecCtx->codec_id);

   if (pCodec == NULL) {
      // could not find codec
      return false;
   }

   // inform the codec that we can handle truncated bitstreams -- i.e.,
   // bitstreams where frame boundaries can fall in the middle of packets
   if (pCodec->capabilities & CODEC_CAP_TRUNCATED) {
      m_pCodecCtx->flags |= CODEC_FLAG_TRUNCATED;
   }

   // open codec
   if (avcodec_open(m_pCodecCtx, pCodec) < 0) {
      // could not open codec
      return false;
   }
   return true;
}


More information about the Libav-user mailing list