video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-09-20 be9c1d1f659b0ff31f656424c478e83a4f7c53b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef _FFMPEG_FORMAT_CONTEXT_OUT_H_
#define _FFMPEG_FORMAT_CONTEXT_OUT_H_
 
#include <stdlib.h>
#include <memory>
#include <string>
#include <vector>
 
struct AVFormatContext;
struct AVStream;
struct AVCodecContext;
struct AVFrame;
struct AVPacket;
struct AVDictionary;
 
namespace ffwrapper{
    class VideoProp;
    class CodedData;
    class FrameData;
 
    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);
        int encode(std::shared_ptr<CodedData> &data,
                    std::shared_ptr<FrameData> &frame_data);
        int encode(std::shared_ptr<CodedData> &data,AVFrame *frame);
 
    public:
        bool copyCodecFromIn(std::vector<AVStream*> in);
        bool openResource(const char *filename, const int flags);
        bool closeResource();
 
        bool JustWriter(std::vector<AVStream*> in, 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);
        void adjustVideoPTS(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(){return v_s_;}
        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_;    
        AVStream                 *v_s_;
        AVCodecContext             *enc_ctx_;
 
        int64_t                     sync_opts_;
 
        bool                     record_;
 
        double                     fps_;
        std::string             format_name_;
 
        // rec
        std::vector<AVStream*>    streams_;
    };
}
#endif