video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-10-22 7fe46306ac577db11ba8a8bbf20653861fcb1a1a
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
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef _cffmpeg_buz_recorder_hpp_
#define _cffmpeg_buz_recorder_hpp_
 
#include <stdint.h>
#include <string>
#include <list>
#include <memory>
 
#include <thread>
#include <atomic>
#include <mutex>
#include <condition_variable>
 
#include "../common/callback.hpp"
 
#include "../common.hpp"
 
struct AVPacket;
 
namespace ffwrapper{
    class FormatIn;
    class FormatOut;
}
 
namespace cffmpeg_wrap{
    namespace buz{
 
        class Recorder{
            public:
                Recorder(ffwrapper::FormatIn *in, const std::string &id);
                ~Recorder();
 
            public: 
                int Run(const char* output, const int mind, const int maxd, const bool audio);
                int PushPacket(std::list<CPacket> &lst);
                int StartWritePacket(std::list<CPacket> &lst, const int64_t &id, const int start, const int end);
                int FireRecorder(const int64_t &id);
 
                void SetCallback(FUNC_REC_INFO cb){
                    func_rec_info_ = cb;
                }
 
                const bool ErrorOcurred(){return error_occured_;}
                const std::string& RecID()const{return id_;}
            private:
                void run_thread();
 
                int init_writer(const bool audio);
                int write_correctly(const CPacket &pkt);
                void end_writer();
 
                void maybe_dump_gop();
 
                int init_write_h264(const bool audio);
                int write_h264(const CPacket &pkt);
                int end_write_h264();
 
                int init_write_hevc(const bool audio);
                int write_hevc(const CPacket &pkt);
                int end_write_hevc();
                int mux_hevc(FILE *fp, const char *outfile);
            private: 
                ffwrapper::FormatIn     *in_;
                ffwrapper::FormatOut    *out_;
 
                std::list<CPacket>      list_pkt_;
                std::atomic_bool        stop_recorder_;
                std::mutex              mutex_pkt_;
                 std::condition_variable cv_;
                std::string             dir_;
                std::string             id_;
                int64_t                 id_frame_;
                int                     id_frame_in_file_;
 
                std::string             file_path_;
                FUNC_REC_INFO           func_rec_info_;
                FILE                    *fp_;
                bool                    audio_;
 
                std::unique_ptr<std::thread> thrd_;
 
 
                int     end_frame_;
                int     v_cur_frame_;
                int     a_cur_frame_;
                
                int64_t last_rec_id_;
 
                int     maxduration;
                int     minduration;
 
                bool                    error_occured_;
        };
    }
}
 
#endif