[FFmpeg-trac] #3090(undetermined:new): h264 decoder returns bad image

FFmpeg trac at avcodec.org
Tue Oct 29 02:27:40 CET 2013


#3090: h264 decoder returns bad image
-------------------------------------+-------------------------------------
             Reporter:  hxuanyu      |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:
  undetermined                       |  unspecified
             Keywords:               |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 it's reproducible on 2.0.1 but not reproducible on 1.1.3.

 I found it when our program upgrading from 1.1.3 to 2.0.1. On the attached
 file, video frames read out using 2.0.1 libs are not correct(1.1.3 is OK)

 So I wrote a piece of code, directly dumping AVframes returned from
 avcodec_decode_video2 to jpeg fomrat, and results are the same.

 below is the code I used:

 ===========================================================================================
 static int WriteJPG(AVCodecContext *pCodecCtx, AVFrame *pFrame, int
 FrameNo){
          AVCodecContext         *pOCodecCtx;
          AVCodec                *pOCodec;
          uint8_t                *Buffer;
          int                     BufSiz;
          int                     BufSizActual;
          enum AVPixelFormat      ImgFmt = AV_PIX_FMT_YUVJ420P;

          BufSiz =
 avpicture_get_size(ImgFmt,pCodecCtx->width,pCodecCtx->height);

          Buffer = (uint8_t *)av_malloc ( BufSiz );
          if ( Buffer == NULL ) return ( 0 );
          memset ( Buffer, 0, BufSiz );

          pOCodecCtx = avcodec_alloc_context3(NULL);
          if ( !pOCodecCtx ) {
             av_free ( Buffer );
             return ( 0 );
          }

          pOCodecCtx->bit_rate      = pCodecCtx->bit_rate;
          pOCodecCtx->width         = pCodecCtx->width;
          pOCodecCtx->height        = pCodecCtx->height;
          pOCodecCtx->pix_fmt       = ImgFmt;
          pOCodecCtx->codec_id      = AV_CODEC_ID_MJPEG;
          pOCodecCtx->codec_type    = AVMEDIA_TYPE_VIDEO;
          pOCodecCtx->time_base.num = pCodecCtx->time_base.num;
          pOCodecCtx->time_base.den = pCodecCtx->time_base.den;

          pOCodec = avcodec_find_encoder ( pOCodecCtx->codec_id );
          if ( !pOCodec ) {
             free ( Buffer );
             return ( 0 );
          }
          if ( avcodec_open2 ( pOCodecCtx, pOCodec, NULL ) < 0 ) {
             free ( Buffer );
             return ( 0 );
          }

          pOCodecCtx->mb_lmin        = pOCodecCtx->lmin =  pOCodecCtx->qmin
 * 118;
          pOCodecCtx->mb_lmax        = pOCodecCtx->lmax =  pOCodecCtx->qmax
 * 118;
          pOCodecCtx->flags          = CODEC_FLAG_QSCALE;
          pOCodecCtx->global_quality = pOCodecCtx->qmin * 118;

          pFrame->pts     = 1;
          pFrame->quality = pOCodecCtx->global_quality;
          BufSizActual =
 avcodec_encode_video(pOCodecCtx,Buffer,BufSiz,pFrame);

          char filename[260];
          sprintf(filename, "C:\\image\\%06d.jpg", FrameNo );

          FILE* JPEGFile = fopen (filename, "wb");
                  fwrite ( Buffer, 1, BufSizActual, JPEGFile );
          fclose ( JPEGFile );


          avcodec_close ( pOCodecCtx );
          av_free ( Buffer );
          return ( BufSizActual );
 }

 static int open_codec_context(int *stream_idx,
                               AVFormatContext *fmt_ctx, enum AVMediaType
 type)
 {
     int ret;
     AVStream *st;
     AVCodecContext *dec_ctx = NULL;
     AVCodec *dec = NULL;

     ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0);
     if (ret < 0) {
         //fprintf(stderr, "Could not find %s stream in input file '%s'\n",
         //        av_get_media_type_string(type), src_filename);
         return ret;
     } else {
         *stream_idx = ret;
         st = fmt_ctx->streams[*stream_idx];

         /* find decoder for the stream */
         dec_ctx = st->codec;
         dec = avcodec_find_decoder(dec_ctx->codec_id);
         if (!dec) {
             fprintf(stderr, "Failed to find %s codec\n",
                     av_get_media_type_string(type));
             return ret;
         }

         if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) {
             fprintf(stderr, "Failed to open %s codec\n",
                     av_get_media_type_string(type));
             return ret;
         }
     }

     return 0;
 }

 int main(int argc, char **argv)
 {
     int ret;

     if (argc == 1) {
         printf("no argument provided, exit ************** \n");
         return 0;
     }
     const char *src_filename = argv[1];

     avcodec_register_all();
     av_register_all();

     AVFormatContext *pFormatCtx = NULL;
     if (avformat_open_input(&pFormatCtx, src_filename, NULL, NULL) < 0) {
         fprintf(stderr, "Could not open source file %s\n", src_filename);
         exit(1);
     }

     if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
         fprintf(stderr, "Could not find stream information\n");
         exit(1);
     }

     int video_stream_idx = -1, audio_stream_idx = -1;
     AVStream *video_stream;
     AVCodecContext *pCodecCtx = NULL;
     if (open_codec_context(&video_stream_idx, pFormatCtx,
 AVMEDIA_TYPE_VIDEO) >= 0) {
         video_stream = pFormatCtx->streams[video_stream_idx];
         pCodecCtx = video_stream->codec;
         printf("video stream index = %d", video_stream_idx);
     }

     AVCodec* pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
     avcodec_open2(pCodecCtx, pCodec, NULL);

     AVFrame *frame = avcodec_alloc_frame();
     AVPacket pkt;

     av_init_packet(&pkt);
     pkt.data = NULL;
     pkt.size = 0;

     int frameFinished = 0;
     int count = 0;
     while (av_read_frame(pFormatCtx, &pkt) >= 0) {
         printf("frame %d\n", count++);
         AVFrame* pFrame = avcodec_alloc_frame();
         int ret = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished,
 &pkt);
         if (ret < 0) {
             avcodec_free_frame(&pFrame);
             continue;
         }
         if (frameFinished) {
             // dump to jpeg
             WriteJPG(pCodecCtx, pFrame, count++);
         }
         avcodec_free_frame(&pFrame);
     }

     return 1;
 }

 ===========================================================================================

 and when I ran this test program with 17, I saw these logs. But the
 strange thing is ffplay plays
 this file correctly and I didn't see similar errors.

 [avi @ 00794000] non-interleaved AVI
 [h264 @ 013a8280] error while decoding MB 31 16, bytestream (-6)
 [h264 @ 013a8280] concealing 423 DC, 423 AC, 423 MV errors in I frame
 [h264 @ 013a8280] error while decoding MB 38 24, bytestream (-37)
 [h264 @ 013a8280] Cannot use next picture in error concealment
 [h264 @ 013a8280] concealing 56 DC, 56 AC, 56 MV errors in P frame
 [h264 @ 013a8280] error while decoding MB 16 24, bytestream (-10)
 [h264 @ 013a8280] Cannot use next picture in error concealment
 [h264 @ 013a8280] concealing 78 DC, 78 AC, 78 MV errors in P frame
 [h264 @ 013a8280] error while decoding MB 38 24, bytestream (-8)
 [h264 @ 013a8280] Cannot use next picture in error concealment
 [h264 @ 013a8280] concealing 56 DC, 56 AC, 56 MV errors in P frame
 [h264 @ 013a8280] error while decoding MB 43 24, bytestream (-6)
 [h264 @ 013a8280] Cannot use next picture in error concealment
 [h264 @ 013a8280] concealing 51 DC, 51 AC, 51 MV errors in P frame
 [h264 @ 013a8280] error while decoding MB 38 24, bytestream (-9)
 [h264 @ 013a8280] Cannot use next picture in error concealment
 [h264 @ 013a8280] concealing 56 DC, 56 AC, 56 MV errors in P frame
 [h264 @ 01755ae0] error while decoding MB 31 16, bytestream (-6)
 [h264 @ 01755ae0] concealing 423 DC, 423 AC, 423 MV errors in I frame
 [h264 @ 015aa720] error while decoding MB 38 24, bytestream (-35)
 [h264 @ 015aa720] Cannot use next picture in error concealment
 [h264 @ 015aa720] concealing 56 DC, 56 AC, 56 MV errors in P frame
 [h264 @ 016a0060] error while decoding MB 16 24, bytestream (-10)
 [h264 @ 016a0060] Cannot use next picture in error concealment
 [h264 @ 016a0060] concealing 78 DC, 78 AC, 78 MV errors in P frame
 [h264 @ 01755ae0] error while decoding MB 38 24, bytestream (-8)
 [h264 @ 01755ae0] Cannot use next picture in error concealment
 [h264 @ 01755ae0] concealing 56 DC, 56 AC, 56 MV errors in P frame
 [h264 @ 015aa720] error while decoding MB 43 24, bytestream (-6)
 [h264 @ 015aa720] Cannot use next picture in error concealment
 [h264 @ 015aa720] concealing 51 DC, 51 AC, 51 MV errors in P frame
 [h264 @ 016a0060] error while decoding MB 38 24, bytestream (-9)
 [h264 @ 016a0060] Cannot use next picture in error concealment
 [h264 @ 016a0060] concealing 56 DC, 56 AC, 56 MV errors in P frame
 [h264 @ 01755ae0] error while decoding MB 39 24, bytestream (-10)
 [h264 @ 01755ae0] Cannot use next picture in error concealment
 [h264 @ 01755ae0] concealing 55 DC, 55 AC, 55 MV errors in P frame
 [h264 @ 015aa720] error while decoding MB 6 24, bytestream (-10)
 [h264 @ 015aa720] Cannot use next picture in error concealment
 [h264 @ 015aa720] concealing 88 DC, 88 AC, 88 MV errors in P frame
 [h264 @ 016a0060] error while decoding MB 39 24, bytestream (-8)
 [h264 @ 016a0060] concealing 55 DC, 55 AC, 55 MV errors in I frame
 [h264 @ 01755ae0] error while decoding MB 40 24, bytestream (-5)
 [h264 @ 01755ae0] Cannot use next picture in error concealment
 [h264 @ 01755ae0] concealing 54 DC, 54 AC, 54 MV errors in P frame
 [h264 @ 015aa720] error while decoding MB 40 24, bytestream (-5)
 [h264 @ 015aa720] concealing 54 DC, 54 AC, 54 MV errors in I frame
 [h264 @ 016a0060] error while decoding MB 44 19, bytestream (-26)
 [h264 @ 016a0060] Cannot use next picture in error concealment
 [h264 @ 016a0060] concealing 275 DC, 275 AC, 275 MV errors in P frame
 [h264 @ 01755ae0] error while decoding MB 36 20, bytestream (-5)
 [h264 @ 01755ae0] concealing 238 DC, 238 AC, 238 MV errors in I frame
 [h264 @ 015aa720] error while decoding MB 31 24, bytestream (-4)
 [h264 @ 015aa720] Cannot use next picture in error concealment
 [h264 @ 015aa720] concealing 63 DC, 63 AC, 63 MV errors in P frame
 [h264 @ 016a0060] error while decoding MB 40 24, bytestream (-6)
 [h264 @ 016a0060] Cannot use next picture in error concealment
 [h264 @ 016a0060] concealing 54 DC, 54 AC, 54 MV errors in P frame
 [h264 @ 01755ae0] error while decoding MB 43 24, bytestream (-6)
 [h264 @ 01755ae0] Cannot use next picture in error concealment
 [h264 @ 01755ae0] concealing 51 DC, 51 AC, 51 MV errors in P frame
 [h264 @ 015aa720] error while decoding MB 3 24, bytestream (-5)
 [h264 @ 015aa720] Cannot use next picture in error concealment
 [h264 @ 015aa720] concealing 91 DC, 91 AC, 91 MV errors in P frame
 [h264 @ 016a0060] error while decoding MB 31 24, bytestream (-5)
 [h264 @ 016a0060] concealing 63 DC, 63 AC, 63 MV errors in I frame
 [h264 @ 01755ae0] error while decoding MB 43 16, bytestream (-6)
 [h264 @ 01755ae0] concealing 411 DC, 411 AC, 411 MV errors in I frame
 [h264 @ 015aa720] error while decoding MB 39 24, bytestream (-5)
 [h264 @ 015aa720] concealing 55 DC, 55 AC, 55 MV errors in I frame
 [h264 @ 016a0060] error while decoding MB 38 24, bytestream (-5)
 [h264 @ 016a0060] concealing 56 DC, 56 AC, 56 MV errors in I frame
 [h264 @ 01755ae0] error while decoding MB 30 24, bytestream (-5)
 [h264 @ 01755ae0] Cannot use next picture in error concealment
 [h264 @ 01755ae0] concealing 64 DC, 64 AC, 64 MV errors in P frame
 [h264 @ 015aa720] error while decoding MB 40 23, bytestream (-9)
 [h264 @ 015aa720] concealing 99 DC, 99 AC, 99 MV errors in I frame
 [h264 @ 016a0060] error while decoding MB 43 24, bytestream (-5)
 [h264 @ 016a0060] concealing 51 DC, 51 AC, 51 MV errors in I frame
 [h264 @ 01755ae0] error while decoding MB 35 24, bytestream (-6)
 [h264 @ 01755ae0] [h264 @ 015aa720] Cannot use next picture in error
 concealment
 error while decoding MB 42 24, bytestream (-7)
 [h264 @ 01755ae0] [h264 @ 015aa720] concealing 59 DC, 59 AC, 59 MV errors
 in P frame
 Cannot use next picture in error concealment
 [h264 @ 015aa720] concealing 52 DC, 52 AC, 52 MV errors in P frame
 [h264 @ 016a0060] error while decoding MB 43 24, bytestream (-6)
 [h264 @ 016a0060] Cannot use next picture in error concealment
 [h264 @ 016a0060] concealing 51 DC, 51 AC, 51 MV errors in P frame
 [h264 @ 01755ae0] error while decoding MB 43 24, bytestream (-6)
 [h264 @ 01755ae0] [h264 @ 015aa720] concealing 51 DC, 51 AC, 51 MV errors
 in I frame
 error while decoding MB 30 24, bytestream (-8)
 [h264 @ 015aa720] concealing 64 DC, 64 AC, 64 MV errors in I frame
 [h264 @ 016a0060] error while decoding MB 32 24, bytestream (-5)

-- 
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/3090>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list