#ifndef FFMPEGFUNC_H
#define FFMPEGFUNC_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "libavutil/avstring.h"
#include "libavutil/mathematics.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/dict.h"
#include "libavutil/parseutils.h"
#include "libavutil/samplefmt.h"
#include "libavutil/avassert.h"
#include "libavutil/time.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/opt.h"
#include "libavcodec/avfft.h"
#include "libswresample/swresample.h"
#include <libavutil/channel_layout.h>
#include <libavutil/timestamp.h>

#ifdef __cplusplus
}
#endif


typedef struct AVOutputStream {
    //所属的输出文件
    AVFormatContext *pFmtCtx;
    //流
    AVStream        *pStream;
    //流对应的编解码器
    AVCodec         *pCodec;
    //流对应的解码器上下文
    AVCodecContext  *pCodecContext;
}AVOutputStream;

void PrepareFFmpeg();

enum AVSampleFormat SelectSampleFormat(const AVCodec *codec);

int SelectSampleRate(const AVCodec *codec);

int SelectChannelLayout(const AVCodec *codec);

//---------------------------------------------------

int OpenOutput(AVFormatContext **pFmtCtx,const char *strOutFmtName,const char *strOutputName);

void CloseOutput(AVFormatContext **pFmtCtx);

int WriteHeader(AVFormatContext *pFmtCtx,AVDictionary *pDict);

int WritePacket(AVOutputStream *pOutStream,AVPacket *pPacket);

int WriteTrailer(AVFormatContext *pFmtCtx);

AVOutputStream *CreateOutputStreamByDefalutParam(enum AVCodecID iCodecID);

int OpenOutputStream(AVOutputStream *pAVOutputStream, AVDictionary *pOpt);

void FreeAVOutputStream(AVOutputStream **pOutStream);

int AddStreamToOutput(AVFormatContext *pFmtCtx,AVOutputStream *pOutStream);

#endif // FFMPEGFUNC_H
