On Tue, 4 Dec 2012 11:00:14 -0800, Shi Yan <[email protected]> wrote: > Hello everyone, > > May I ask you a question regarding h264 decoding with libavcodec? > > I’m working on a launch animation for my application. The animation is a > h264 mp4 file. Because I’m not very familiar with video decoding, I started > by following this tutorial: > > http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/ > > > > I verified the tutorial can work fine on other video formats, for example > mpeg, but can’t work on h264. > > The reason is that a call to this function: > > const auto processedLength = avcodec_decode_video2(avCodecContext, > avFrame, &isFrameAvailable, &packetToSend); > > Always returns -1. There is no error code telling me what’s wrong. > > > > This morning, I found > http://git.videolan.org/?p=ffmpeg.git;a=blob;f=doc/examples/decoding_encoding.c;hb=HEAD. > it says that h264 is frame based. To decode it, I need to provide the > correct width and height. > > I verified my avCodecContext->width and height are both zeros, so I guess > this could be an issue. So I enforced them to be the size of the video: > > avCodecContext->width = 1920; > > avCodecContext->height = 1080; > > //avCodecContext->flags2 |= CODEC_FLAG2_FAST; > > avCodecContext->pix_fmt = (enum PixelFormat)29; //I tried almost every > format here > >
What makes you think that setting random numbers there will work? Typically you get those values from the container. In your specific case, either copy the parameters from AVStream.codec, or use that codec context directly for decoding. > -- Anton Khirnov _______________________________________________ libav-api mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-api
