#ifndef _FFMPEG_FORMAT_CONTEXT_OUT_H_
|
#define _FFMPEG_FORMAT_CONTEXT_OUT_H_
|
|
#include <stdlib.h>
|
#include <memory>
|
#include <string>
|
|
struct AVFormatContext;
|
struct AVStream;
|
struct AVCodecContext;
|
struct AVFrame;
|
struct AVPacket;
|
struct AVDictionary;
|
struct AVBSFContext;
|
|
namespace ffwrapper{
|
class VideoProp;
|
|
class FormatOut
|
{
|
public:
|
FormatOut();
|
~FormatOut();
|
|
FormatOut(VideoProp &prop,
|
const char *filename, char *format_name = NULL);
|
|
FormatOut(const double fps, const char *format_name);
|
|
void clear();
|
public:
|
bool open(const char *filename, const char *format_name);
|
bool openCodec(VideoProp &prop);
|
|
int encode(AVPacket *pkt, AVFrame *frame);
|
|
public:
|
bool addStream(AVStream *s);
|
bool copyCodecFromIn(AVStream *v, AVStream *a);
|
bool openResource(const char *filename, const int flags);
|
bool closeResource();
|
|
bool JustWriter(AVStream *v, AVStream *a, const char *filename);
|
bool EncodeWriter(const char *filename);
|
bool writeFrame(AVPacket *pkt, const int64_t &frame_cnt, bool interleaved = true);
|
void adjustPTS(AVPacket *pkt, const int64_t &frame_cnt);
|
bool endWriter();
|
|
bool writeHeader(AVDictionary **options = NULL);
|
bool writeFrame2(AVPacket *pkt, bool interleaved);
|
bool writeTrailer();
|
public:
|
AVStream *getStream();
|
const AVCodecContext *getCodecContext() const;
|
|
const double getFPS()const{return fps_;}
|
const char* getFormatName() const{return format_name_.c_str();}
|
const char* getFileName() const;//{return ctx_->filename;}
|
|
const bool isRecord(){return record_;}
|
private:
|
void configEncoder(VideoProp &prop);
|
private:
|
AVFormatContext *ctx_;
|
int v_idx_;
|
int a_idx_;
|
AVCodecContext *enc_ctx_;
|
|
int64_t sync_opts_;
|
|
bool record_;
|
|
double fps_;
|
std::string format_name_;
|
|
AVBSFContext *bsf_h264, *bsf_hevc;
|
// rec
|
AVStream *in_v_stream_;
|
AVStream *in_a_stream_;
|
};
|
}
|
#endif
|