[Libav-user] mpeg4 decoding only decodes 36395 out of 154959 frames

Bob Self bobslf at gmail.com
Fri May 11 14:24:31 CEST 2012


I modified the program (and fixed a mistake), and now this loop gets
the right count. Before, it was only counting video_frames if
'isFrameFinished' was non-zero, but this version counts all video
frames from av_read_frame(). It is amazing how little documentation
there is on this stuff and how the examples you find are full of
deprecated (incompatible?) functions.

What is the purpose of isFrameFinished in avcodec_decode_video2()?
Should a video frame be counted if it is not finished?



   while (1)  {
      status = av_read_frame(pFormatCtx, &packet);
      if (status<0)  {
         break;
      }


      if (packet.stream_index == videoStream)  {
         video_frames++;

         status = avcodec_decode_video2(pCodecCtx, pFrame,
&isFrameFinished, &packet);

         /*
         if (isFrameFinished) {

            if ( (video_frames%1000) == 0)  {
               printf("%d\n", video_frames);
            }

            // SCANNING GOES HERE
            pixelScanCount = 0;

            for (int y = 0; y < pCodecCtx->height; y++)  {
               uint8_t *p = pFrame->data[0] + y * pFrame->linesize[0];
        // this gets Y' in YUV

               for (int x = 0; x < pCodecCtx->width; x++)  {
                  pixelScanCount++;
                  //printf("Frame %d at %d, %d has Y'=%d\n",
frameLocation, x, y, p[x]);
               }
            }
         }
         */

      }
      else  {
         audio_frames++;
      }

      av_free_packet(&packet);
   }               // while(1)


More information about the Libav-user mailing list