video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2023-12-26 18a05d269516a5e33d8460291c2f93e73d95adce
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
#ifndef _FFMPEG_FORMAT_CONTEXT_IN_H_
#define _FFMPEG_FORMAT_CONTEXT_IN_H_
 
#include <stdint.h>
#include <memory>
#include <deque>
#include "PsToEs.hpp"
 
struct AVFormatContext;
struct AVDictionary;
struct AVStream;
struct AVCodecContext;
struct AVPacket;
struct AVFrame;
struct AVCodec;
struct AVIOContext;
struct AVCodecParserContext;
 
typedef int(* read_packet)(void *opaque,uint8_t *buf, int buf_size);
 
namespace ffwrapper{
 
    class VideoProp;
 
    class FormatIn
    {
    public:
        explicit FormatIn(bool hw=true);
        explicit FormatIn(const VideoProp &prop, bool hw=true);
        virtual ~FormatIn();
        
    public:
 
        virtual int open(const char *filename, AVDictionary **options);
        virtual const bool IsHEVC()const;
        virtual const bool IsAVC1()const;
        virtual int readPacket(AVPacket *pkt_out);
        virtual bool isVideoPkt(AVPacket *pkt);
        virtual bool isAudioPkt(AVPacket *pkt);
        bool notVideoAudio(AVPacket *pkt);
 
        int openWithCustomIO(void *opaque, read_packet fn, AVDictionary **options=NULL);
        bool openCodec(AVDictionary **options);
        int decode(AVFrame* frame, AVPacket *pkt);
 
    protected:
        bool allocCodec(AVCodec *dec, AVStream *s, AVDictionary **options);
    public:
        AVStream *getStream(int type = -1);
        AVCodecContext *getCodecContext(int type = 0);
        AVFormatContext *getFromatContext(){return ctx_;}
        const double getFPS()const{return fps_;}
    protected:
         AVFormatContext     *ctx_;
         AVCodecContext         *dec_ctx_;
         int                 vs_idx_;
        int                 as_idx_;
 
        VideoProp             *prop_;
        int                 fps_;
    private:
        AVIOContext            *io_ctx_;
        uint8_t             *read_io_buff_;
        const int             read_io_buff_size_;
    };
 
    class FormatInGB : public FormatIn{
    public:
        FormatInGB();
        explicit FormatInGB(const VideoProp &prop);
        ~FormatInGB();
 
        virtual int open(const char *filename, AVDictionary **options) override;
        virtual const bool IsHEVC()const override;
        virtual const bool IsAVC1()const override;
        virtual int readPacket(AVPacket *pkt_out) override;
 
        virtual bool isVideoPkt(AVPacket *pkt) override;
        virtual bool isAudioPkt(AVPacket *pkt) override;
 
    private:
        GB28181API*             gb28181_;
        AVCodecParserContext*     parser_ctx_;
        unsigned char*          buffer_;
        int                     buffer_size_;
 
        std::deque<AVPacket*>   q_pkt_;
    };
}
 
#endif