FFmpegAVDemuxer

FFmpegAVDemuxer is a demuxer dependent on FFmpeg lib, which can demux media files into independent video and audio streams. Currently, only demux MP4/FMP4 is supported, and we will add support for more types of files in the future.

API Instructions

namespace com { namespace sunplus { namespace media { using VideoDataCallback = std::function<void(AVPacket* packet, int index)>; using AudioDataCallback = std::function<void(AVPacket* packet, int index)>; class FFmpegAVDemuxer { public: FFmpegAVDemuxer(); ~FFmpegAVDemuxer(); public: int init(std::string filepath, VideoDataCallback videoCb, AudioDataCallback audioCb); void uninit(); AVStream* getVideoStream(); AVStream* getAudioStream(); int getNextFrame(); }; }}}

Constructors

FFmpegAVDemuxer();

init

Open the file to demux, and retrieve stream information.

/** * initialize demuxer. * * @param filepath the file to demux. * * @param videoCb to get video packet. * * @param audioCb to get audio packet. * * @return 0 if OK, < 0 on error. */ int init(std::string filepath, VideoDataCallback videoCb, AudioDataCallback audioCb);

 

uninit

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

getVideoStream

You can get video stream information through it, but it must be after the demuxer is successfully init. Such as gop, fps, bitrate, duration, etc.

Sample

getAudioStream

You can get audio stream information through it, but it must be after the demuxer is successfully init. Such as sample_rate, channels, bitrate, duration, etc.

Sample

getNextFrame

Get the next frame of the file. The frame is returned through VideoDataCallback and AudioDataCallback.

 

Sample Code

This is a sample of demux the MP4 file.

the flow of demux:

create demuxer --> init demuxer --> create the thread of get frame --> end of file --> uninit demuxer

Test Result

FFmpegAVDemuxerTestResult.png

Â