[FFmpeg-trac] #3519(undetermined:new): Decoding mpegts h264 i-frame into jpeg occasionally gives gray or green images

FFmpeg trac at avcodec.org
Tue Apr 1 23:04:55 CEST 2014

#3519: Decoding mpegts h264 i-frame into jpeg occasionally gives gray or green
             Reporter:  werner        |                     Type:  defect
               Status:  new           |                 Priority:  normal
            Component:  undetermined  |                  Version:  2.2
             Keywords:                |               Blocked By:
             Blocking:                |  Reproduced by developer:  0
Analyzed by developer:  0             |
 '''Summary of the bug''': decoding mpegts h264 i-frame into jpeg
 occasionally gives gray or green images.
 '''FFmpeg version''':
 ffmpeg version 2.2
 built on Apr  1 2014 15:14:10 with gcc 4.1.2 (GCC) 20080704 (Red Hat
 configuration: --shlibdir=/usr/lib64 --prefix=/usr --mandir=/usr/share/man
 --libdir=/usr/lib64 --enable-shared --disable-static --enable-debug
 --disable-stripping --extra-cflags='-O2 -g -pipe -Wall
 -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-
 size=4 -m64 -mtune=generic -fPIC -I/usr/include/gsm' --enable-gpl
 --enable-x11grab --enable-version3 --enable-pthreads --enable-libfaac
 --enable-nonfree --enable-avfilter --enable-libvpx --enable-libass
 --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264
 --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb
 --enable-postproc --enable-libdc1394 --enable-libfreetype --enable-
 avresample --enable-libtwolame --enable-librtmp
 libavutil      52. 66.100 / 52. 66.100
 libavcodec     55. 52.102 / 55. 52.102
 libavformat    55. 33.100 / 55. 33.100
 libavdevice    55. 10.100 / 55. 10.100
 libavfilter     4.  2.100 /  4.  2.100
 libavresample   1.  2.  0 /  1.  2.  0
 libswscale      2.  5.102 /  2.  5.102
 libswresample   0. 18.100 /  0. 18.100
 libpostproc    52.  3.100 / 52.  3.100
 '''How to reproduce''': I am using the c libraries to create my own
 functions, and unfortunately I can't post the entire code here (I can show
 how the decoder/encoder are set up, see below). I know the code works as
 >90% of my videos work entirely and the rest of the videos work for most
 of the frames. I understand this is most likely due to corrupt i-frames or
 something with data not being there (the videos can be bad quality), and I
 even try to help it out by passing more frames to it after the i-frame. I
 don't necessarily expect valid images back (although if there was a way to
 get the decoder to do that by passing more data or something, that would
 be awesome if someone could help me down that path), but I do expect
 FFmpeg to throw some sort of error my way that I can detect it had a bad
 frame. I have a video clip I can upload that exhibits the behavior with
 this code, but it's 118MB - I don't know if I can upload that here. I will
 try after opening the bug or I can upload it somewhere else if necessary.

 AVCodec* decoder = avcodec_find_decoder(CODEC_ID_H264);
 AVCodecContext* decoder_cc = avcodec_alloc_context3(decoder);
 avcodec_open2(decoder_cc, decoder, NULL);
 decoder_cc->flags2 |= CODEC_FLAG2_SHOW_ALL;
 decoder_cc->skip_frame = AVDISCARD_BIDIR | AVDISCARD_NONREF;
 //decoder_cc->err_recognition = AV_EF_CRCCHECK | AV_EF_BITSTREAM |
 AV_EF_BUFFER | AV_EF_CAREFUL; // these don't seem to help
 // Initialized packet variables, etc
 // At this point, we have parsed the mpegts stream to find the video pid
 and have found the sps header and it's slice data, which we then pass into
 ret = avcodec_decode_video2(decoder_cc, picture, &got_packet,
 // all is valid, got_packet is 1, ret > 0, and all the flags on picture
 look good (no error flags set, key frame is 1, etc)

 AVFormatContext* output_stream = NULL;
 avformat_alloc_output_context2(&output_stream, NULL, "image2", NULL);
 AVCodec* encoder = avcodec_find_encoder(CODEC_ID_MJPEG);
 AVStream* video_stream;
 video_stream = avformat_new_stream(output_stream, encoder);
 video_stream->codec->codec = encoder;
 video_stream->codec->qcompress = 0.8f;
 video_stream->codec->width = 200; // Note: scaling happens with SwsContext
 not shown here
 video_stream->codec->height = 150;
 video_stream->codec->time_base.num = 1;
 video_stream->codec->pix_fmt = AV_PIX_FMT_YUVJ420P;
 avcodec_open2(video_stream->codec, NULL, NULL);
 //output_stream->pb initialized using simplified ffio_fdopen
 // decoded picture is passed in
 ret = avcodec_encode_video2(output_stream->streams[0]->codec,
 &encoder_pkt, picture, &got_packet);
 // ret is 0 and got_packet is 1, but the image is all gray

Ticket URL: <https://trac.ffmpeg.org/ticket/3519>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list