FFmpegH264Decoder

FFmpegH264Decoder is to use the FFmpeg library to decode video H264 data into YUV data. On C3V we will use the decoder named h264_v4l2m2m which is a hardware decoder.

API Instructions

namespace com { namespace sunplus { namespace media { using YUVDataCallback = std::function<void(AVFrame* yuvFrame, int index)>; class FFmpegH264Decoder { public: FFmpegH264Decoder(); ~FFmpegH264Decoder(); public: int init(VideoStreamParam_t param, YUVDataCallback dataCallback); void uninit(); AVCodecContext* getAVCodecContext(); int decode(AVPacket* h264Packet); int flush(); }; }}}

Constructors

FFmpegH264Decoder();

init

Set decode parameters, such as width, height, timebase etc, and initialize decode

/** * Set decode parameters and initialize decode. * * @param param set parameters of the decoder. * * @param dataCallback to get yuv frame. * */ int init(VideoStreamParam_t param, YUVDataCallback dataCallback);

Sample

uninit

Release all resources allocated by the init method and close the decoder.

getAVCodecContext

Get AVCodecContext to get the info of the encoder, such as width, height, etc.

decode

Send the h264 packet to the decoder. the h264Packet must be freed with av_packet_unref()+av_packet_free() when it is no longer needed.

flush

Send a NULL packet, in which case it is considered a flush packet.

If the decoder still has packets buffered, it will return them after this call.

Sample Code

This is a sample of H264 decode using FFmpegH264Decoder. FFmpegH264Provider provides the h264 source, then using the h264 provider gets the h264 packet and sends it to the decoder.

the flow of decode h264:

create h264 decoder --> init --> create h264 provider --> provider prepare --> create the thread of get h264 packet --> send to decoder --> get yuv data by YUVDataCallback.

Test Result

FFmpegH264DecoderTestResult.png

Â