FFmpegAVMuxer

FFmpegAVDemuxer is a muxer dependent on FFmpeg lib, which can mux video stream and audio stream to media files. Currently, only mux MP4/FMP4 is supported(Currently, only Video Stream is supported.), and we will add support for more types of files in the future.

API Instructions

namespace com { namespace sunplus { namespace media { class FFmpegAVMuxer { public: FFmpegAVMuxer(bool isFMP4 = false); ~FFmpegAVMuxer(); public: int init(std::string filepath, AVCodecContext* videoCodecCtx); int init(std::string filepath, VideoStreamParam_t param, uint8_t* spspps, int spsppsSize); void uninit(); int putVideoFrame(AVPacket*& packet); int flush(); }; }}}

Constructors

FFmpegAVMuxer(bool isFMP4 = false)

init

Initialize muxer, set stream parameters, and write a header to the file.

/** * initialize demuxer. * * @param filepath the file to write. * * @param videoCodecCtx used to initialize stream. * * @return 0 if OK, < 0 on error. */ int init(std::string filepath, AVCodecContext* videoCodecCtx); /** * initialize demuxer. * * @param filepath the file to write. * * @param param used to initialize stream. * * @param spspps used to initialize stream. * * @return 0 if OK, < 0 on error. */ int init(std::string filepath, VideoStreamParam_t param, uint8_t* spspps, int spsppsSize);

uninit

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

putVideoFrame

Write the video packet to the muxer.

flush

Flush data buffered within the muxer and write the stream trailer to output media file.

It must be called after when there are no new frames to be written.

Sample Code

This is a sample of how to record MP4 dependent on FFmpegH264Provider and FFmpegAVMuxer.

the flow of record MP4:

create yuv source --> create h264 provider --> h264 provider prepare -> create MP4 muxer -> init muxer --> create the thread of get the frame from h264 provider to put to muxer --> uninit muxer

Test Result

FFmpegAVMuxerTestResult.png

Â