In my program I’m trying to decode an MPEG4 stream from a certain url and the decoding fails. Strangely, MPEG4 streams from other urls are decoded fine, so it’s not a problem of the absence of the codec.
Here’s how I decode:
1) Find the decoder:
AVCodec* codec = avcodec_find_decoder(CODEC_ID_MPEG4);
2) Allocate a context
ACodecContext* ctx = avcodec_alloc_context3(0);
3) Open the codec
avcodec_open2(ctx, codec, 0) // it returns > 0, fine
4) Decoding a packet (which I have)
avcodec_decode_video2(ctx, frame, &decoded, &packet);
Now avcodec_decode_video2 fails returning -1 and FFMPEG log prints:
Picture size 0x0 is invalid
get_buffer() failed (-1 0 0x0)
If I manually set up ctx->width and ctx->height before decoding to the correct values (I know the dimensions of the picture) then it decodes fine.
But I can not be sure of the dimensions all the time, therefore I would like to know if I can overcome the -1 error.
By seeing the FFMPEG log output can anyone suggest something for me to do?
Does the file have a correct VOL header? You will face this problem if it does not. The VOL header has the height and width.