Ernstjan Freriks
Ernstjan Freriks

Reputation: 671

FFmpeg.AutoGen decoding h264 MP4 to an image

I've been experimenting with the FFmpeg.AutoGen (https://github.com/Ruslan-B/FFmpeg.AutoGen) wrapper. I have successfully made it possible to decode an MPG file to a bitmap from a .NET stream. But decoding a MP4 (h264) file gives me a negative return value for FFmpegInvoke.avcodec_decode_video2.

I've tried setting flags (such as pCodecContext->flags2 |= FFmpegInvoke.CODEC_FLAG2_CHUNKS;) but I do not get a successfull image from the stream. So what I'm looking for is a working example of decoding h264 to an image using FFmpeg.AutoGen. I know somebody has got this working (see How to get a byte** from managed byte[] buffer) so it is possible!

Upvotes: 2

Views: 2042

Answers (1)

Ruslan Balanukhin
Ruslan Balanukhin

Reputation: 68

I've managed to decode video successfully using demo application from project and mp4 file provided by Ernstjan, the reason why it was broken - codec context which was initialized with all defaults just by using coded information, apparently that is not enough.

Fortunately the codecContext variable still contains coded context which was initially discovered by av_find_stream_info, thus we can reuse it and it works fine for me.

Thus quick and dirty solution will be replace this line:

AVCodecContext* pCodecContext = FFmpegInvoke.avcodec_alloc_context3(pCodec);

With:

AVCodecContext* pCodecContext = &codecContext;

I'll update demo application to show few different approaches how to obtain proper codec context.

Upvotes: 1

Related Questions